python: longevity gains pre-cleanup logic.

No more need for manual removal.

Put rm_cx, endp, and rm cxe by prefix in realm
class.
This commit is contained in:
Ben Greear
2020-08-06 10:42:17 -07:00
parent e76ad3341c
commit 7252d686bd
3 changed files with 63 additions and 30 deletions

View File

@@ -168,6 +168,43 @@ class Realm(LFCliBase):
request = LFUtils.port_down_request(resource_id=resource, port_name=port) request = LFUtils.port_down_request(resource_id=resource, port_name=port)
self.json_post("/cli-json/set_port", request) self.json_post("/cli-json/set_port", request)
def rm_cx(self, cx_name):
req_url = "cli-json/rm_cx"
data = {
"test_mgr": "ALL",
"cx_name": cx_name
}
self.json_post(req_url, data)
def rm_endp(self, ename, debug_=False, suppress_related_commands_=True):
req_url = "cli-json/rm_endp"
data = {
"endp_name": ename
}
self.json_post(req_url, data, debug_=debug_, suppress_related_commands_=suppress_related_commands_)
def stop_cx(self, cx_name):
self.json_post("/cli-json/set_cx_state", {
"test_mgr": "ALL",
"cx_name": cx_name,
"cx_state": "STOPPED"
}, debug_=self.debug)
def cleanup_cxe_prefix(self, prefix):
cx_list = self.cx_list()
if cx_list is not None:
for cx_name in cx_list:
if cx_name.startswith(prefix):
self.rm_cx(cx_name)
endp_list = self.json_get("/endp")
if endp_list is not None:
endp_list = list(endp_list['endpoint'])
for idx in range(len(endp_list)):
endp_name = list(endp_list[idx])[0]
if endp_name.startswith(prefix):
self.rm_endp(endp_name)
def channel_freq(self, channel_=0): def channel_freq(self, channel_=0):
return self.chan_to_freq[channel_] return self.chan_to_freq[channel_]
@@ -225,8 +262,8 @@ class Realm(LFCliBase):
found_endps = {} found_endps = {}
if endp_list is not None: if endp_list is not None:
endp_list = list(endp_list['endpoint']) endp_list = list(endp_list['endpoint'])
for endp_name in range(len(endp_list)): for idx in range(len(endp_list)):
name = list(endp_list[endp_name])[0] name = list(endp_list[idx])[0]
found_endps[name] = name found_endps[name] = name
for req in these_endp: for req in these_endp:
@@ -623,16 +660,15 @@ class MULTICASTProfile(LFCliBase):
pass pass
def cleanup_prefix(self):
self.local_realm.cleanup_cxe_prefix(self.name_prefix)
def cleanup(self, suppress_related_commands=None, debug_ = False): def cleanup(self, suppress_related_commands=None, debug_ = False):
if self.debug: if self.debug:
debug_=True debug_=True
for endp_name in self.get_mc_names(): for endp_name in self.get_mc_names():
json_data = { self.local_realm.rm_endp(endp_name, debug_=debug_, suppress_related_commands_=suppress_related_commands)
"endp_name":endp_name
}
url = "cli-json/rm_endp"
self.local_realm.json_post(url, json_data, debug_=debug_, suppress_related_commands_=suppress_related_commands)
def create_mc_tx(self, endp_type, side_tx, suppress_related_commands=None, debug_ = False ): def create_mc_tx(self, endp_type, side_tx, suppress_related_commands=None, debug_ = False ):
if self.debug: if self.debug:
@@ -642,7 +678,7 @@ class MULTICASTProfile(LFCliBase):
side_tx_shelf = side_tx_info[0] side_tx_shelf = side_tx_info[0]
side_tx_resource = side_tx_info[1] side_tx_resource = side_tx_info[1]
side_tx_port = side_tx_info[2] side_tx_port = side_tx_info[2]
side_tx_name = "mtx-%s-%i"%(side_tx_port, len(self.created_mc)) side_tx_name = "%smtx-%s-%i"%(self.name_prefix, side_tx_port, len(self.created_mc))
json_data = [] json_data = []
@@ -699,7 +735,7 @@ class MULTICASTProfile(LFCliBase):
side_rx_shelf = side_rx_info[0] side_rx_shelf = side_rx_info[0]
side_rx_resource = side_rx_info[1] side_rx_resource = side_rx_info[1]
side_rx_port = side_rx_info[2] side_rx_port = side_rx_info[2]
side_rx_name = "mrx-%s-%i"%(side_rx_port, len(self.created_mc)) side_rx_name = "%smrx-%s-%i"%(self.name_prefix, side_rx_port, len(self.created_mc))
# add_endp mcast-rcv-sta-001 1 1 sta0002 mc_udp 9999 NO 0 0 NO 1472 0 INCREASING NO 32 0 0 # add_endp mcast-rcv-sta-001 1 1 sta0002 mc_udp 9999 NO 0 0 NO 1472 0 INCREASING NO 32 0 0
json_data = { json_data = {
'alias':side_rx_name, 'alias':side_rx_name,
@@ -812,34 +848,23 @@ class L3CXProfile(LFCliBase):
def stop_cx(self): def stop_cx(self):
print("Stopping CXs...") print("Stopping CXs...")
for cx_name in self.created_cx.keys(): for cx_name in self.created_cx.keys():
self.json_post("/cli-json/set_cx_state", { self.local_realm.stop_cx(cx_name)
"test_mgr": "default_tm",
"cx_name": cx_name,
"cx_state": "STOPPED"
}, debug_=self.debug)
print(".", end='') print(".", end='')
print("") print("")
def cleanup_prefix(self):
self.local_realm.cleanup_cxe_prefix(self.name_prefix)
def cleanup(self): def cleanup(self):
print("Cleaning up cxs and endpoints") print("Cleaning up cxs and endpoints")
if len(self.created_cx) != 0: if len(self.created_cx) != 0:
for cx_name in self.created_cx.keys(): for cx_name in self.created_cx.keys():
print("Cleaning cx: %s"%(cx_name)) print("Cleaning cx: %s"%(cx_name))
req_url = "cli-json/rm_cx" self.local_realm.rm_cx(cx_name)
data = {
"test_mgr": "default_tm",
"cx_name": cx_name
}
self.json_post(req_url, data)
for side in range(len(self.created_cx[cx_name])): for side in range(len(self.created_cx[cx_name])):
ename = self.created_cx[cx_name][side]
print("Cleaning endpoint: %s"%(ename)) print("Cleaning endpoint: %s"%(ename))
req_url = "cli-json/rm_endp" self.local_realm.rm_endp(self.created_cx[cx_name][side])
data = {
"endp_name": ename
}
self.json_post(req_url, data)
def create(self, endp_type, side_a, side_b, sleep_time=0.03, suppress_related_commands=None, debug_=False): def create(self, endp_type, side_a, side_b, sleep_time=0.03, suppress_related_commands=None, debug_=False):
if self.debug: if self.debug:

View File

@@ -135,6 +135,7 @@ class IPV4VariableTime(LFCliBase):
self.station_profile.admin_down() self.station_profile.admin_down()
def pre_cleanup(self): def pre_cleanup(self):
self.cx_profile.cleanup_prefix()
for sta in self.sta_list: for sta in self.sta_list:
self.local_realm.rm_port(sta, check_exists=True) self.local_realm.rm_port(sta, check_exists=True)

View File

@@ -43,6 +43,7 @@ class L3VariableTimeLongevity(LFCliBase):
self.local_realm = realm.Realm(lfclient_host=self.host, lfclient_port=self.port, debug_=debug_on) self.local_realm = realm.Realm(lfclient_host=self.host, lfclient_port=self.port, debug_=debug_on)
self.cx_profile = self.local_realm.new_l3_cx_profile() self.cx_profile = self.local_realm.new_l3_cx_profile()
self.multicast_profile = self.local_realm.new_multicast_profile() self.multicast_profile = self.local_realm.new_multicast_profile()
self.multicast_profile.name_prefix = "MLT-";
self.station_profiles = [] self.station_profiles = []
index = 0 index = 0
@@ -170,6 +171,13 @@ class L3VariableTimeLongevity(LFCliBase):
for station_name in station_list: for station_name in station_list:
self.local_realm.admin_down(station_name) self.local_realm.admin_down(station_name)
def pre_cleanup(self):
self.cx_profile.cleanup_prefix()
self.multicast_profile.cleanup_prefix()
for station_list in self.station_lists:
for sta in station_list:
self.local_realm.rm_port(sta, check_exists=True)
def cleanup(self): def cleanup(self):
self.cx_profile.cleanup() self.cx_profile.cleanup()
self.multicast_profile.cleanup() self.multicast_profile.cleanup()
@@ -345,7 +353,8 @@ Note: multiple --radio switches may be entered up to the number of radios avai
if number_of_stations > MAX_NUMBER_OF_STATIONS: if number_of_stations > MAX_NUMBER_OF_STATIONS:
print("number of stations per radio exceeded max of : {}".format(MAX_NUMBER_OF_STATIONS)) print("number of stations per radio exceeded max of : {}".format(MAX_NUMBER_OF_STATIONS))
quit(1) quit(1)
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_= 1 + index*1000, end_id_= number_of_stations + index*1000, padding_number_=10000) station_list = LFUtils.portNameSeries(prefix_="sta", start_id_= 1 + index*1000, end_id_= number_of_stations + index*1000,
padding_number_=10000, radio=radio_name[index])
station_lists.append(station_list) station_lists.append(station_list)
index += 1 index += 1
@@ -366,9 +375,7 @@ Note: multiple --radio switches may be entered up to the number of radios avai
ssid_security_list=ssid_security_list, test_duration=test_duration, ssid_security_list=ssid_security_list, test_duration=test_duration,
side_a_min_rate=256000, side_b_min_rate=256000, debug_on=debug_on) side_a_min_rate=256000, side_b_min_rate=256000, debug_on=debug_on)
# This cleanup does not work because objects in the profiles are not yet created. ip_var_test.pre_cleanup()
# Not sure the best way to resolve this currently. --Ben
ip_var_test.cleanup()
ip_var_test.build() ip_var_test.build()
if not ip_var_test.passes(): if not ip_var_test.passes():