setting up base profile

This commit is contained in:
Matthew Stidham
2021-01-17 22:20:59 -08:00
committed by Jed Reynolds
parent 114ec7c2ab
commit 1a52b10664

View File

@@ -831,8 +831,37 @@ class BaseProfile(LFCliBase):
self.exit_on_error = False
def json_get(self, target):
self.debug_ = False
return self.parent_realm.json_get(self,target)
return self.json_get(target)
def json_post(self, url,data,debug_,suppress_related_commands_=None):
return self.json_post(url,data,debug_=False,suppress_related_commands_=suppress_related_commands_)
def parse_time(self,target):
return self.parent_realm.parse_time(target)
def stop_cx(self, target):
return self.parent_realm.stop_cx(target)
def cleanup_cxe_prefix(self,prefix):
return self.parent_realm.cleanup_cxe_prefix(prefix)
def rm_cx(self,target):
return self.parent_realm.rm_cx(target)
def created_cx(self,target):
return self.parent_realm.created_cx(target)
def name_to_eid(self,target):
return self.parent_realm.name_to_eid(target)
def set_endp_tos(self,target):
return self.parent_realm.set_endp_tos(target)
def wait_until_endps_appear(self,target,debug=False):
return self.parent_realm.wait_until_endps_appear(target,debug=False)
def wait_until_cxs_appear(self,target,debug=False):
return self.parent_realm.wait_until_cxs_appear(target,debug=False)
class MULTICASTProfile(LFCliBase):
def __init__(self, lfclient_host, lfclient_port, local_realm,
@@ -891,9 +920,6 @@ class MULTICASTProfile(LFCliBase):
pass
def cleanup_prefix(self):
self.local_realm.cleanup_cxe_prefix(self.name_prefix)
def cleanup(self, suppress_related_commands=None, debug_ = False):
if self.debug:
debug_=True
@@ -1011,7 +1037,7 @@ class MULTICASTProfile(LFCliBase):
class L3CXProfile(BaseProfile):
class L3CXProfile(LFCliBase):
def __init__(self, lfclient_host, lfclient_port, local_realm,
side_a_min_bps=None, side_b_min_bps=None,
side_a_max_bps=0, side_b_max_bps=0,
@@ -1034,7 +1060,7 @@ class L3CXProfile(BaseProfile):
:param number_template_: how many zeros wide we padd, possibly a starting integer with left padding
:param debug_:
"""
super().__init__(local_realm)
super().__init__(lfclient_host, lfclient_port, debug_, _halt_on_error=True)
self.lfclient_url = "http://%s:%s" % (lfclient_host, lfclient_port)
self.debug = debug_
self.local_realm = local_realm
@@ -1062,7 +1088,7 @@ class L3CXProfile(BaseProfile):
return self.data
def __get_rx_values(self):
cx_list = self.json_get("endp?fields=name,rx+bytes")
cx_list = self.json_get("endp?fields=name,rx+bytes", debug_=self.debug)
if self.debug:
print(self.created_cx.values())
print("==============\n", cx_list, "\n==============")
@@ -1096,13 +1122,13 @@ class L3CXProfile(BaseProfile):
monitor_interval=1,
col_names=None,
created_cx=None,
show=True,
show=False,
report_file=None,
output_format=None,
script_name=None,
arguments=None):
try:
duration_sec=self.local_realm.parse_time(duration_sec).seconds
duration_sec=local_realm.parse_time(duration_sec).seconds
except:
if (duration_sec is None) or (duration_sec <= 1):
raise ValueError("L3CXProfile::monitor wants duration_sec > 1 second")
@@ -1125,11 +1151,9 @@ class L3CXProfile(BaseProfile):
#Step 1, column names
fields=",".join(col_names)
print(fields)
#Step 2, monitor columns
start_time = datetime.datetime.now()
end_time = start_time + datetime.timedelta(seconds=duration_sec)
print(end_time)
value_map = dict()
passes = 0
@@ -1161,10 +1185,10 @@ class L3CXProfile(BaseProfile):
self.exit_fail()
old_cx_rx_values = new_cx_rx_values
time.sleep(monitor_interval)
print(value_map)
#print(value_map)
#if passes == expected_passes:
#self._pass("PASS: All tests passed")
if passes == expected_passes:
self._pass("PASS: All tests passed")
#step 3 organize data
endpoints=list()
for endpoint in value_map.values():
@@ -1179,7 +1203,6 @@ class L3CXProfile(BaseProfile):
endpoints2[point].insert(0, timestamps2[point])
#step 4 save and close
header_row=col_names
print(header_row)
header_row.insert(0,'Timestamp')
if output_format.lower() in ['excel','xlsx'] or report_file.split('.')[-1] == 'xlsx':
report_fh = open(report_file, "w+")
@@ -1232,9 +1255,10 @@ class L3CXProfile(BaseProfile):
else:
pass
def refresh_cx(self):
for cx_name in self.created_cx.keys():
self.local_realm.json_post("/cli-json/show_cxe", {
self.json_post("/cli-json/show_cxe", {
"test_mgr": "ALL",
"cross_connect": cx_name
}, debug_=self.debug)
@@ -1245,7 +1269,7 @@ class L3CXProfile(BaseProfile):
for cx_name in self.created_cx.keys():
if self.debug:
print("cx-name: %s"%(cx_name))
self.local_realm.json_post("/cli-json/set_cx_state", {
self.json_post("/cli-json/set_cx_state", {
"test_mgr": "default_tm",
"cx_name": cx_name,
"cx_state": "RUNNING"
@@ -1256,7 +1280,7 @@ class L3CXProfile(BaseProfile):
def stop_cx(self):
print("Stopping CXs...")
for cx_name in self.created_cx.keys():
self.local_realm.stop_cx(cx_name)
self.stop_cx(cx_name)
print(".", end='')
print("")
@@ -1269,13 +1293,13 @@ class L3CXProfile(BaseProfile):
for cx_name in self.created_cx.keys():
if self.debug:
print("Cleaning cx: %s"%(cx_name))
self.local_realm.rm_cx(cx_name)
self.rm_cx(cx_name)
for side in range(len(self.created_cx[cx_name])):
ename = self.created_cx[cx_name][side]
if self.debug:
print("Cleaning endpoint: %s"%(ename))
self.local_realm.rm_endp(self.created_cx[cx_name][side])
self.rm_endp(self.created_cx[cx_name][side])
def create(self, endp_type, side_a, side_b, sleep_time=0.03, suppress_related_commands=None, debug_=False, tos=None):
if self.debug:
@@ -1295,12 +1319,12 @@ class L3CXProfile(BaseProfile):
raise ValueError("side_a_min_bps, side_a_max_bps, side_b_min_bps, and side_b_max_bps must all be set to a value")
if type(side_a) == list and type(side_b) != list:
side_b_info = self.local_realm.name_to_eid(side_b)
side_b_info = self.name_to_eid(side_b)
side_b_shelf = side_b_info[0]
side_b_resource = side_b_info[1]
for port_name in side_a:
side_a_info = self.local_realm.name_to_eid(port_name)
side_a_info = self.name_to_eid(port_name)
side_a_shelf = side_a_info[0]
side_a_resource = side_a_info[1]
if port_name.find('.') < 0:
@@ -1365,8 +1389,8 @@ class L3CXProfile(BaseProfile):
self.local_realm.json_post(url, data, debug_=debug_, suppress_related_commands_=suppress_related_commands)
if tos != None:
self.local_realm.set_endp_tos(endp_a_name, tos)
self.local_realm.set_endp_tos(endp_b_name, tos)
self.set_endp_tos(endp_a_name, tos)
self.set_endp_tos(endp_b_name, tos)
data = {
"alias": cx_name,
@@ -1383,14 +1407,14 @@ class L3CXProfile(BaseProfile):
})
elif type(side_b) == list and type(side_a) != list:
side_a_info = self.local_realm.name_to_eid(side_a)
side_a_info = self.name_to_eid(side_a)
side_a_shelf = side_a_info[0]
side_a_resource = side_a_info[1]
#side_a_name = side_a_info[2]
for port_name in side_b:
print(side_b)
side_b_info = self.local_realm.name_to_eid(port_name)
side_b_info = self.name_to_eid(port_name)
side_b_shelf = side_b_info[0]
side_b_resource = side_b_info[1]
side_b_name = side_b_info[2]
@@ -1441,7 +1465,7 @@ class L3CXProfile(BaseProfile):
"flag": "autohelper",
"val": 1
}
self.local_realm.json_post(url, data, debug_=debug_, suppress_related_commands_=suppress_related_commands)
self.json_post(url, data, debug_=debug_, suppress_related_commands_=suppress_related_commands)
url = "cli-json/set_endp_flag"
data = {
@@ -1449,7 +1473,7 @@ class L3CXProfile(BaseProfile):
"flag": "autohelper",
"val": 1
}
self.local_realm.json_post(url, data, debug_=debug_, suppress_related_commands_=suppress_related_commands)
self.json_post(url, data, debug_=debug_, suppress_related_commands_=suppress_related_commands)
#print("CXNAME451: %s" % cx_name)
data = {
"alias": cx_name,
@@ -1466,14 +1490,14 @@ class L3CXProfile(BaseProfile):
else:
raise ValueError("side_a or side_b must be of type list but not both: side_a is type %s side_b is type %s" % (type(side_a), type(side_b)))
self.local_realm.wait_until_endps_appear(these_endp, debug=debug_)
self.wait_until_endps_appear(these_endp, debug=debug_)
for data in cx_post_data:
url = "/cli-json/add_cx"
self.local_realm.json_post(url, data, debug_=debug_, suppress_related_commands_=suppress_related_commands)
time.sleep(0.01)
self.local_realm.wait_until_cxs_appear(these_cx, debug=debug_)
self.wait_until_cxs_appear(these_cx, debug=debug_)
def to_string(self):
pprint.pprint(self)
@@ -2327,8 +2351,6 @@ class VRProfile(LFCliBase):
suppress_related_commands_=True):
# Create vr
if self.debug:
debug = True
if self.vr_name is not None:
self.add_vr_data["alias"] = self.vr_name
self.local_realm.json_post("add_vr", self.add_vr_data, debug_=debug)