From d697963ceccca11579bcc1359cf00e7633b9464a Mon Sep 17 00:00:00 2001 From: Ben Greear Date: Wed, 26 Jan 2022 16:47:05 -0800 Subject: [PATCH] create-cx: Add return code checking for cx and endp creation. Check for false value in create_l3_stations and return error code upon failure. Add configurable timeout to waiting for cx/endp logic. Signed-off-by: Ben Greear --- py-json/l3_cxprofile.py | 20 +++++++++++++++---- py-json/realm.py | 33 ++++++++++++++++++-------------- py-scripts/create_l3_stations.py | 15 +++++++++++---- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/py-json/l3_cxprofile.py b/py-json/l3_cxprofile.py index b1359feb..9be2aef0 100644 --- a/py-json/l3_cxprofile.py +++ b/py-json/l3_cxprofile.py @@ -415,7 +415,10 @@ class L3CXProfile(LFCliBase): self.created_endp.clear() def create(self, endp_type, side_a, side_b, sleep_time=0.03, suppress_related_commands=None, debug_=False, - tos=None): + tos=None, timeout=300): + # Returns a 2-member array, list of cx, list of endp on success. + # If endpoints creation fails, returns False, False + # if Endpoints creation is OK, but CX creation fails, returns False, list of endp if self.debug: debug_ = True print('Start L3CXProfile.create') @@ -628,15 +631,24 @@ class L3CXProfile(LFCliBase): 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))) - print("wait_until_endps_appear these_endp: {} debug_ {}".format(these_endp, debug_)) - self.local_realm.wait_until_endps_appear(these_endp, debug=debug_) + if debug_: + print("wait_until_endps_appear these_endp: {} debug_ {}".format(these_endp, debug_)) + rv = self.local_realm.wait_until_endps_appear(these_endp, debug=debug_, timeout=timeout) + if not rv: + if debug_: + print("ERROR: L3CXProfile::create, Could not create/find endpoints") + return False, False 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_) + rv = self.local_realm.wait_until_cxs_appear(these_cx, debug=debug_, timeout=timeout) + if not rv: + if debug_: + print("ERROR: L3CXProfile::create, Could not create/find connections.") + return False, these_endp return these_cx, these_endp diff --git a/py-json/realm.py b/py-json/realm.py index b25ae153..4f41b65d 100755 --- a/py-json/realm.py +++ b/py-json/realm.py @@ -384,14 +384,13 @@ class Realm(LFCliBase): response = self.json_get("/cx/list") return response - def waitUntilEndpsAppear(self, these_endp, debug=False): - return self.wait_until_endps_appear(these_endp, debug=debug) + def waitUntilEndpsAppear(self, these_endp, debug=False, timeout=300): + return self.wait_until_endps_appear(these_endp, debug=debug, timeout=timeout) - def wait_until_endps_appear(self, these_endp, debug=False): + def wait_until_endps_appear(self, these_endp, debug=False, timeout=100): wait_more = True count = 0 while wait_more: - time.sleep(1) wait_more = False endp_list = self.json_get("/endp/list") found_endps = {} @@ -413,19 +412,21 @@ class Realm(LFCliBase): print("Waiting on endpoint: %s" % req) wait_more = True count += 1 - if count > 100: - break + if count > timeout: + print("ERROR: Could not find all endpoints: %s" % these_endp) + return False + if wait_more: + time.sleep(1) - return not wait_more + return True - def waitUntilCxsAppear(self, these_cx, debug=False): - return self.wait_until_cxs_appear(these_cx, debug=debug) + def waitUntilCxsAppear(self, these_cx, debug=False, timeout=100): + return self.wait_until_cxs_appear(these_cx, debug=debug, timeout=timeout) - def wait_until_cxs_appear(self, these_cx, debug=False): + def wait_until_cxs_appear(self, these_cx, debug=False, timeout=100): wait_more = True count = 0 while wait_more: - time.sleep(1) wait_more = False found_cxs = {} cx_list = self.cx_list() @@ -442,10 +443,14 @@ class Realm(LFCliBase): print("Waiting on CX: %s" % req) wait_more = True count += 1 - if count > 100: - break + if count > timeout: + if debug: + print("ERROR: Failed to find all cxs: %s" % these_cx) + return False + if wait_more: + time.sleep(1) - return not wait_more + return True # def wait_until_database_loaded(self): diff --git a/py-scripts/create_l3_stations.py b/py-scripts/create_l3_stations.py index 85b15ae0..60acc56d 100755 --- a/py-scripts/create_l3_stations.py +++ b/py-scripts/create_l3_stations.py @@ -118,10 +118,17 @@ class CreateL3(Realm): print("ERROR: create_l3_stations: could not create all ports, exiting with error."); exit(1); - self.cx_profile.create(endp_type="lf_udp", - side_a=self.station_profile.station_names, - side_b=self.upstream, - sleep_time=0) + cx_timeout=300 + #cx_timeout=0 # expect this to fail + rv = self.cx_profile.create(endp_type="lf_udp", + side_a=self.station_profile.station_names, + side_b=self.upstream, + sleep_time=0, + timeout=cx_timeout) + if not rv: + print("ERROR: create_l3_stations: could not create all cx/endpoints, exiting with error."); + exit(1); + self._pass("PASS: Station build finished")