From 7252d686bd63ee74ee0a1686ce0f9d9687cdfcab Mon Sep 17 00:00:00 2001 From: Ben Greear Date: Thu, 6 Aug 2020 10:42:17 -0700 Subject: [PATCH] python: longevity gains pre-cleanup logic. No more need for manual removal. Put rm_cx, endp, and rm cxe by prefix in realm class. --- py-json/realm.py | 77 ++++++++++++++++++--------- py-scripts/test_ipv4_variable_time.py | 1 + py-scripts/test_l3_longevity.py | 15 ++++-- 3 files changed, 63 insertions(+), 30 deletions(-) diff --git a/py-json/realm.py b/py-json/realm.py index a66b4475..e31e2d5e 100755 --- a/py-json/realm.py +++ b/py-json/realm.py @@ -168,6 +168,43 @@ class Realm(LFCliBase): request = LFUtils.port_down_request(resource_id=resource, port_name=port) 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): return self.chan_to_freq[channel_] @@ -225,8 +262,8 @@ class Realm(LFCliBase): found_endps = {} if endp_list is not None: endp_list = list(endp_list['endpoint']) - for endp_name in range(len(endp_list)): - name = list(endp_list[endp_name])[0] + for idx in range(len(endp_list)): + name = list(endp_list[idx])[0] found_endps[name] = name for req in these_endp: @@ -623,16 +660,15 @@ 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 for endp_name in self.get_mc_names(): - json_data = { - "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) + self.local_realm.rm_endp(endp_name, debug_=debug_, suppress_related_commands_=suppress_related_commands) def create_mc_tx(self, endp_type, side_tx, suppress_related_commands=None, debug_ = False ): if self.debug: @@ -642,7 +678,7 @@ class MULTICASTProfile(LFCliBase): side_tx_shelf = side_tx_info[0] side_tx_resource = side_tx_info[1] 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 = [] @@ -699,7 +735,7 @@ class MULTICASTProfile(LFCliBase): side_rx_shelf = side_rx_info[0] side_rx_resource = side_rx_info[1] 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 json_data = { 'alias':side_rx_name, @@ -812,34 +848,23 @@ class L3CXProfile(LFCliBase): def stop_cx(self): print("Stopping CXs...") for cx_name in self.created_cx.keys(): - self.json_post("/cli-json/set_cx_state", { - "test_mgr": "default_tm", - "cx_name": cx_name, - "cx_state": "STOPPED" - }, debug_=self.debug) + self.local_realm.stop_cx(cx_name) print(".", end='') print("") + def cleanup_prefix(self): + self.local_realm.cleanup_cxe_prefix(self.name_prefix) + def cleanup(self): print("Cleaning up cxs and endpoints") if len(self.created_cx) != 0: for cx_name in self.created_cx.keys(): print("Cleaning cx: %s"%(cx_name)) - req_url = "cli-json/rm_cx" - data = { - "test_mgr": "default_tm", - "cx_name": cx_name - } - self.json_post(req_url, data) + self.local_realm.rm_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)) - req_url = "cli-json/rm_endp" - data = { - "endp_name": ename - } - self.json_post(req_url, data) + self.local_realm.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): if self.debug: diff --git a/py-scripts/test_ipv4_variable_time.py b/py-scripts/test_ipv4_variable_time.py index d926da28..114eb1bf 100755 --- a/py-scripts/test_ipv4_variable_time.py +++ b/py-scripts/test_ipv4_variable_time.py @@ -135,6 +135,7 @@ class IPV4VariableTime(LFCliBase): self.station_profile.admin_down() def pre_cleanup(self): + self.cx_profile.cleanup_prefix() for sta in self.sta_list: self.local_realm.rm_port(sta, check_exists=True) diff --git a/py-scripts/test_l3_longevity.py b/py-scripts/test_l3_longevity.py index d001bf72..25eb4222 100755 --- a/py-scripts/test_l3_longevity.py +++ b/py-scripts/test_l3_longevity.py @@ -43,6 +43,7 @@ class L3VariableTimeLongevity(LFCliBase): 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.multicast_profile = self.local_realm.new_multicast_profile() + self.multicast_profile.name_prefix = "MLT-"; self.station_profiles = [] index = 0 @@ -170,6 +171,13 @@ class L3VariableTimeLongevity(LFCliBase): for station_name in station_list: 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): self.cx_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: print("number of stations per radio exceeded max of : {}".format(MAX_NUMBER_OF_STATIONS)) 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) 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, 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. - # Not sure the best way to resolve this currently. --Ben - ip_var_test.cleanup() + ip_var_test.pre_cleanup() ip_var_test.build() if not ip_var_test.passes():