mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-19 03:25:05 +00:00
LFUtils.wait_until_ports_appear: alert the user if a port is phantom
Use a for loop for increased stability remove deprecated variables Signed-off-by: Matthew Stidham <stidmatt@gmail.com>
This commit is contained in:
@@ -687,39 +687,40 @@ def wait_until_ports_appear(base_url="http://localhost:8080", port_list=(), debu
|
|||||||
existing_stations = LFRequest.LFRequest(base_url, '/ports', debug_=debug)
|
existing_stations = LFRequest.LFRequest(base_url, '/ports', debug_=debug)
|
||||||
print('existing stations')
|
print('existing stations')
|
||||||
pprint.pprint(existing_stations)
|
pprint.pprint(existing_stations)
|
||||||
found_stations = []
|
|
||||||
port_url = "/port/1"
|
port_url = "/port/1"
|
||||||
show_url = "/cli-json/show_ports"
|
show_url = "/cli-json/show_ports"
|
||||||
if base_url.endswith('/'):
|
if base_url.endswith('/'):
|
||||||
port_url = port_url[1:]
|
port_url = port_url[1:]
|
||||||
show_url = show_url[1:]
|
show_url = show_url[1:]
|
||||||
sec_elapsed = 0
|
|
||||||
attempts = 0
|
|
||||||
if type(port_list) is not list:
|
if type(port_list) is not list:
|
||||||
port_list = [port_list]
|
port_list = [port_list]
|
||||||
while len(found_stations) < len(port_list) and sec_elapsed < timeout:
|
if debug:
|
||||||
found_stations = []
|
current_ports = LFRequest.LFRequest(base_url, '/ports', debug_=debug).getAsJson()
|
||||||
|
print("LFUtils:wait_until_ports_appear, full port listing: %s" % current_ports)
|
||||||
|
for port in current_ports['interfaces']:
|
||||||
|
if list(port.values())[0]['phantom']:
|
||||||
|
print("LFUtils:waittimeout_until_ports_appear: %s is phantom" % list(port.values())[0]['alias'])
|
||||||
|
for attempt in range(0, int(timeout / 2)):
|
||||||
|
found_stations = set()
|
||||||
for port_eid in port_list:
|
for port_eid in port_list:
|
||||||
eid = name_to_eid(port_eid)
|
eid = name_to_eid(port_eid)
|
||||||
shelf = eid[0]
|
shelf = eid[0]
|
||||||
resource_id = eid[1]
|
resource_id = eid[1]
|
||||||
port_name = eid[2]
|
port_name = eid[2]
|
||||||
# print("waiting for sta sta "+port_eid)
|
|
||||||
uri = "%s/%s/%s" % (port_url, resource_id, port_name)
|
uri = "%s/%s/%s" % (port_url, resource_id, port_name)
|
||||||
lf_r = LFRequest.LFRequest(base_url, uri, debug_=debug)
|
lf_r = LFRequest.LFRequest(base_url, uri, debug_=debug)
|
||||||
json_response = lf_r.getAsJson()
|
json_response = lf_r.getAsJson()
|
||||||
if json_response is not None:
|
if json_response is not None:
|
||||||
found_stations.append(port_name)
|
if not json_response['interface']['phantom']:
|
||||||
|
found_stations.add("%s.%s.%s" % (shelf, resource_id, port_name))
|
||||||
else:
|
else:
|
||||||
lf_r = LFRequest.LFRequest(base_url, show_url, debug_=debug)
|
lf_r = LFRequest.LFRequest(base_url, show_url, debug_=debug)
|
||||||
lf_r.addPostData({"shelf": shelf, "resource": resource_id, "port": port_name, "probe_flags": 5})
|
lf_r.addPostData({"shelf": shelf, "resource": resource_id, "port": port_name, "probe_flags": 5})
|
||||||
lf_r.jsonPost()
|
lf_r.jsonPost()
|
||||||
if len(found_stations) < len(port_list):
|
if len(found_stations) < len(port_list):
|
||||||
sleep(2)
|
sleep(2)
|
||||||
sec_elapsed += 2
|
|
||||||
attempts += 1
|
|
||||||
if debug:
|
if debug:
|
||||||
print('Found %s out of %s stations in %s out of %s tries in wait_until_ports_appear' % (len(found_stations), len(port_list), attempts, timeout/2))
|
print('Found %s out of %s stations in %s out of %s tries in wait_until_ports_appear' % (len(found_stations), len(port_list), attempt, timeout/2))
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user