l4_cxprofile.py : moved prints to logger

create_l4.py : moved prints to logger -needed for testing

Signed-off-by: Chuck SmileyRekiere <chuck.smileyrekiere@candelatech.com>
This commit is contained in:
Chuck SmileyRekiere
2022-01-29 10:09:11 -07:00
committed by shivam
parent f0fdc40cca
commit 0f1ffdd0ee

View File

@@ -7,12 +7,16 @@ import pandas as pd
import time
import datetime
import ast
from pprint import pformat
import logging
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../")))
lfcli_base = importlib.import_module("py-json.LANforge.lfcli_base")
LFCliBase = lfcli_base.LFCliBase
logger = logging.getLogger(__name__)
class L4CXProfile(LFCliBase):
def __init__(self, lfclient_host, lfclient_port, local_realm, debug_=False):
@@ -44,32 +48,34 @@ class L4CXProfile(LFCliBase):
passes -= 1
debug_info[name] = {field: info[field.replace("+", " ")]}
if debug:
print(debug_info)
logger.debug(debug_info)
if passes == expected_passes:
return True
else:
print(list(debug_info), " Endps in this list showed errors getting to %s " % self.url)
logger.info(list(debug_info), " Endps in this list showed errors getting to %s " % self.url)
return False
def start_cx(self):
print("Starting CXs...")
logger.info("Starting CXs...")
for cx_name in self.created_cx.keys():
self.json_post("/cli-json/set_cx_state", {
"test_mgr": "default_tm",
"cx_name": self.created_cx[cx_name],
"cx_state": "RUNNING"
}, debug_=self.debug)
# this is for a visual affect someone watching the screen, leave as print
print(".", end='')
print("")
def stop_cx(self):
print("Stopping CXs...")
logger.info("Stopping CXs...")
for cx_name in self.created_cx.keys():
self.json_post("/cli-json/set_cx_state", {
"test_mgr": "default_tm",
"cx_name": self.created_cx[cx_name],
"cx_state": "STOPPED"
}, debug_=self.debug)
# this is for a visual affect someone watching the screen, leave as print
print(".", end='')
print("")
@@ -92,7 +98,7 @@ class L4CXProfile(LFCliBase):
def get_bytes(self):
time.sleep(1)
cx_list = self.json_get("layer4/list?fields=name,%s" % self.test_type, debug_=self.debug)
# print("==============\n", cx_list, "\n==============")
# logger.info("==============\n", cx_list, "\n==============")
cx_map = {}
for cx_name in cx_list['endpoint']:
if cx_name != 'uri' and cx_name != 'handler':
@@ -116,13 +122,13 @@ class L4CXProfile(LFCliBase):
if name in self.created_cx.keys():
expected_passes += 1
if info['urls/s'] * self.requests_per_ten >= self.target_requests_per_ten * .9:
# print(name, info['urls/s'], info['urls/s'] * self.requests_per_ten, self.target_requests_per_ten * .9)
# logger.info(name, info['urls/s'], info['urls/s'] * self.requests_per_ten, self.target_requests_per_ten * .9)
passes += 1
return passes == expected_passes
def cleanup(self):
print("Cleaning up cxs and endpoints")
logger.info("Cleaning up cxs and endpoints")
if len(self.created_cx) != 0:
for cx_name in self.created_cx.keys():
req_url = "cli-json/rm_cx"
@@ -131,20 +137,20 @@ class L4CXProfile(LFCliBase):
"cx_name": self.created_cx[cx_name]
}
self.json_post(req_url, data)
# pprint(data)
# logger.debug(pformat(data))
req_url = "cli-json/rm_endp"
data = {
"endp_name": cx_name
}
self.json_post(req_url, data)
# pprint(data)
# logger.debug(pformat(data))
def create(self, ports=None, sleep_time=.5, debug_=False, suppress_related_commands_=None):
if ports is None:
ports = []
cx_post_data = []
for port_name in ports:
print("port_name: {} len: {} self.local_realm.name_to_eid(port_name): {}".format(port_name,
logger.info("port_name: {} len: {} self.local_realm.name_to_eid(port_name): {}".format(port_name,
len(self.local_realm.name_to_eid(
port_name)),
self.local_realm.name_to_eid(
@@ -199,17 +205,23 @@ class L4CXProfile(LFCliBase):
duration_sec = LFCliBase.parse_time(duration_sec).seconds
else:
if (duration_sec is None) or (duration_sec <= 1):
logger.critical("L4CXProfile::monitor wants duration_sec > 1 second")
raise ValueError("L4CXProfile::monitor wants duration_sec > 1 second")
if duration_sec <= monitor_interval:
logger.critical("L4CXProfile::monitor wants duration_sec > monitor_interval")
raise ValueError("L4CXProfile::monitor wants duration_sec > monitor_interval")
if report_file is None:
logger.critical("Monitor requires an output file to be defined")
raise ValueError("Monitor requires an output file to be defined")
if created_cx is None:
logger.critical("Monitor needs a list of Layer 4 connections")
raise ValueError("Monitor needs a list of Layer 4 connections")
if (monitor_interval is None) or (monitor_interval < 1):
logger.critical("L4CXProfile::monitor wants monitor_interval >= 1 second")
raise ValueError("L4CXProfile::monitor wants monitor_interval >= 1 second")
if output_format is not None:
if output_format.lower() != report_file.split('.')[-1]:
logger.critical('Filename %s does not match output format %s' % (report_file, output_format))
raise ValueError('Filename %s does not match output format %s' % (report_file, output_format))
else:
output_format = report_file.split('.')[-1]
@@ -221,16 +233,16 @@ class L4CXProfile(LFCliBase):
else:
header_row = list((list(self.json_get("/layer4/all")['endpoint'][0].values())[0].keys()))
if debug:
print(header_row)
logger.debug(header_row)
# Step 2 - Monitor columns
start_time = datetime.datetime.now()
end_time = start_time + datetime.timedelta(seconds=duration_sec)
sleep_interval = round(duration_sec // 5)
if debug:
print("Sleep_interval is %s ", sleep_interval)
print("Start time is %s ", start_time)
print("End time is %s ", end_time)
logger.debug("Sleep_interval is %s ", sleep_interval)
logger.debug("Start time is %s ", start_time)
logger.debug("End time is %s ", end_time)
value_map = dict()
passes = 0
expected_passes = 0
@@ -246,13 +258,13 @@ class L4CXProfile(LFCliBase):
fields = ",".join(col_names)
response = self.json_get("/layer4/%s?fields=%s" % (created_cx, fields))
if debug:
print(response)
logger.debug(response)
if response is None:
print(response)
logger.debug(response)
raise ValueError("Cannot find any endpoints")
if monitor:
if debug:
print(response)
logger.debug(response)
time.sleep(sleep_interval)
t = datetime.datetime.now()
@@ -280,7 +292,7 @@ class L4CXProfile(LFCliBase):
# self.exit_fail()
time.sleep(monitor_interval)
print(value_map)
logger.info(value_map)
# [further] post-processing data, after test completion
full_test_data_list = []
@@ -289,7 +301,7 @@ class L4CXProfile(LFCliBase):
for datum in data["endpoint"]:
for endpoint_data in datum.values():
if debug:
print(endpoint_data)
logger.debug(endpoint_data)
endpoint_data["Timestamp"] = test_timestamp
full_test_data_list.append(endpoint_data)