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 <greearb@candelatech.com>
This commit is contained in:
Ben Greear
2022-01-26 16:47:05 -08:00
committed by shivam
parent 4bb9cb4b82
commit d697963cec
3 changed files with 46 additions and 22 deletions

View File

@@ -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)))
if debug_:
print("wait_until_endps_appear these_endp: {} debug_ {}".format(these_endp, debug_))
self.local_realm.wait_until_endps_appear(these_endp, debug=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

View File

@@ -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):

View File

@@ -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",
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)
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")