mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-10-31 02:38:03 +00:00 
			
		
		
		
	LFUtils: Cleanup whitespace
Signed-off-by: Matthew Stidham <stidmatt@gmail.com>
This commit is contained in:
		| @@ -21,7 +21,7 @@ if sys.version_info[0] != 3: | |||||||
| sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../../"))) | sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../../"))) | ||||||
|  |  | ||||||
| LFRequest = importlib.import_module("py-json.LANforge.LFRequest") | LFRequest = importlib.import_module("py-json.LANforge.LFRequest") | ||||||
| Logg = importlib.import_module("lanforge_client.logg") # .Logg | Logg = importlib.import_module("lanforge_client.logg")  # .Logg | ||||||
|  |  | ||||||
| debug_printer = pprint.PrettyPrinter(indent=2) | debug_printer = pprint.PrettyPrinter(indent=2) | ||||||
|  |  | ||||||
| @@ -31,7 +31,8 @@ ADD_STA_FLAGS_DOWN_WPA2 = 68719477760 | |||||||
| REPORT_TIMER_MS_FAST = 1500 | REPORT_TIMER_MS_FAST = 1500 | ||||||
| REPORT_TIMER_MS_SLOW = 3000 | REPORT_TIMER_MS_SLOW = 3000 | ||||||
|  |  | ||||||
| #Used for Speed |  | ||||||
|  | # Used for Speed | ||||||
| def parse_size_bps(size_val): | def parse_size_bps(size_val): | ||||||
|     if isinstance(size_val, str): |     if isinstance(size_val, str): | ||||||
|         size_val.upper() |         size_val.upper() | ||||||
| @@ -53,7 +54,8 @@ def parse_size_bps(size_val): | |||||||
|     else: |     else: | ||||||
|         return size_val |         return size_val | ||||||
|  |  | ||||||
| #Used for Size of file |  | ||||||
|  | # Used for Size of file | ||||||
| def parse_size(size_val): | def parse_size(size_val): | ||||||
|     if isinstance(size_val, str): |     if isinstance(size_val, str): | ||||||
|         size_val.upper() |         size_val.upper() | ||||||
| @@ -104,6 +106,7 @@ class PortEID: | |||||||
| def staNewDownStaRequest(sta_name, resource_id=1, radio="wiphy0", ssid="", passphrase="", debug_on=False): | def staNewDownStaRequest(sta_name, resource_id=1, radio="wiphy0", ssid="", passphrase="", debug_on=False): | ||||||
|     return sta_new_down_sta_request(sta_name, resource_id, radio, ssid, passphrase, debug_on) |     return sta_new_down_sta_request(sta_name, resource_id, radio, ssid, passphrase, debug_on) | ||||||
|  |  | ||||||
|  |  | ||||||
| def sta_new_down_sta_request(sta_name, resource_id=1, radio="wiphy0", ssid="", passphrase="", debug_on=False): | def sta_new_down_sta_request(sta_name, resource_id=1, radio="wiphy0", ssid="", passphrase="", debug_on=False): | ||||||
|     """ |     """ | ||||||
|     For use with add_sta. If you don't want to generate mac addresses via patterns (xx:xx:xx:xx:81:*) |     For use with add_sta. If you don't want to generate mac addresses via patterns (xx:xx:xx:xx:81:*) | ||||||
| @@ -133,6 +136,7 @@ def sta_new_down_sta_request(sta_name, resource_id=1, radio="wiphy0", ssid="", p | |||||||
| def portSetDhcpDownRequest(resource_id, port_name, debug_on=False): | def portSetDhcpDownRequest(resource_id, port_name, debug_on=False): | ||||||
|     return port_set_dhcp_down_request(resource_id, port_name, debug_on) |     return port_set_dhcp_down_request(resource_id, port_name, debug_on) | ||||||
|  |  | ||||||
|  |  | ||||||
| def port_set_dhcp_down_request(resource_id, port_name, debug_on=False): | def port_set_dhcp_down_request(resource_id, port_name, debug_on=False): | ||||||
|     """ |     """ | ||||||
|     See http://localhost:8080/help/set_port |     See http://localhost:8080/help/set_port | ||||||
| @@ -157,6 +161,7 @@ def port_set_dhcp_down_request(resource_id, port_name, debug_on=False): | |||||||
| def portDhcpUpRequest(resource_id, port_name, debug_on=False): | def portDhcpUpRequest(resource_id, port_name, debug_on=False): | ||||||
|     return port_dhcp_up_request(resource_id, port_name, debug_on) |     return port_dhcp_up_request(resource_id, port_name, debug_on) | ||||||
|  |  | ||||||
|  |  | ||||||
| def port_dhcp_up_request(resource_id, port_name, debug_on=False): | def port_dhcp_up_request(resource_id, port_name, debug_on=False): | ||||||
|     """ |     """ | ||||||
|     See http://localhost:8080/help/set_port |     See http://localhost:8080/help/set_port | ||||||
| @@ -182,6 +187,7 @@ def port_dhcp_up_request(resource_id, port_name, debug_on=False): | |||||||
| def portUpRequest(resource_id, port_name, debug_on=False): | def portUpRequest(resource_id, port_name, debug_on=False): | ||||||
|     return port_up_request(resource_id, port_name, debug_on) |     return port_up_request(resource_id, port_name, debug_on) | ||||||
|  |  | ||||||
|  |  | ||||||
| def port_up_request(resource_id, port_name, debug_on=False): | def port_up_request(resource_id, port_name, debug_on=False): | ||||||
|     """ |     """ | ||||||
|     See http://localhost:8080/help/set_port |     See http://localhost:8080/help/set_port | ||||||
| @@ -202,9 +208,11 @@ def port_up_request(resource_id, port_name, debug_on=False): | |||||||
|         debug_printer.pprint(data) |         debug_printer.pprint(data) | ||||||
|     return data |     return data | ||||||
|  |  | ||||||
|  |  | ||||||
| def portDownRequest(resource_id, port_name, debug_on=False): | def portDownRequest(resource_id, port_name, debug_on=False): | ||||||
|     return port_down_request(resource_id, port_name, debug_on) |     return port_down_request(resource_id, port_name, debug_on) | ||||||
|  |  | ||||||
|  |  | ||||||
| def port_down_request(resource_id, port_name, debug_on=False): | def port_down_request(resource_id, port_name, debug_on=False): | ||||||
|     """ |     """ | ||||||
|     Does not change the use_dhcp flag |     Does not change the use_dhcp flag | ||||||
| @@ -227,6 +235,7 @@ def port_down_request(resource_id, port_name, debug_on=False): | |||||||
|         debug_printer.pprint(data) |         debug_printer.pprint(data) | ||||||
|     return data |     return data | ||||||
|  |  | ||||||
|  |  | ||||||
| def port_reset_request(resource_id, port_name, debug_on=False): | def port_reset_request(resource_id, port_name, debug_on=False): | ||||||
|     """ |     """ | ||||||
|     Does not change the use_dhcp flag |     Does not change the use_dhcp flag | ||||||
| @@ -250,6 +259,7 @@ def port_reset_request(resource_id, port_name, debug_on=False): | |||||||
| def generateMac(parent_mac, random_octet, debug=False): | def generateMac(parent_mac, random_octet, debug=False): | ||||||
|     return generate_mac(parent_mac=parent_mac, random_octet=random_octet, debug=debug) |     return generate_mac(parent_mac=parent_mac, random_octet=random_octet, debug=debug) | ||||||
|  |  | ||||||
|  |  | ||||||
| def generate_mac(parent_mac, random_octet, debug=False): | def generate_mac(parent_mac, random_octet, debug=False): | ||||||
|     if debug: |     if debug: | ||||||
|         print("************ random_octet: %s **************" % (random_octet)) |         print("************ random_octet: %s **************" % (random_octet)) | ||||||
| @@ -273,7 +283,8 @@ def portNameSeries(prefix_="sta", start_id_=0, end_id_=1, padding_number_=10000, | |||||||
|     :param padding_number_: |     :param padding_number_: | ||||||
|     :return: |     :return: | ||||||
|     """ |     """ | ||||||
|     return port_name_series(prefix=prefix_, start_id=start_id_, end_id=end_id_, padding_number=padding_number_, radio=radio) |     return port_name_series(prefix=prefix_, start_id=start_id_, end_id=end_id_, padding_number=padding_number_, | ||||||
|  |                             radio=radio) | ||||||
|  |  | ||||||
|  |  | ||||||
| def port_name_series(prefix="sta", start_id=0, end_id=1, padding_number=10000, radio=None): | def port_name_series(prefix="sta", start_id=0, end_id=1, padding_number=10000, radio=None): | ||||||
| @@ -313,9 +324,11 @@ def gen_ip_series(ip_addr, netmask, num_ips=None): | |||||||
|             chosen_ips.append(ip_list[i]) |             chosen_ips.append(ip_list[i]) | ||||||
|         return chosen_ips |         return chosen_ips | ||||||
|  |  | ||||||
|  |  | ||||||
| def generateRandomHex(): | def generateRandomHex(): | ||||||
|     return generate_random_hex() |     return generate_random_hex() | ||||||
|  |  | ||||||
|  |  | ||||||
| # generate random hex if you need it for mac addresses | # generate random hex if you need it for mac addresses | ||||||
| def generate_random_hex(): | def generate_random_hex(): | ||||||
|     # generate a few random numbers and convert them into hex: |     # generate a few random numbers and convert them into hex: | ||||||
| @@ -371,6 +384,7 @@ def port_list_to_alias_map(json_list, debug_=False): | |||||||
|  |  | ||||||
|     return reverse_map |     return reverse_map | ||||||
|  |  | ||||||
|  |  | ||||||
| def list_to_alias_map(json_list=None, from_element=None, debug_=False): | def list_to_alias_map(json_list=None, from_element=None, debug_=False): | ||||||
|     reverse_map = {} |     reverse_map = {} | ||||||
|     if (json_list is None) or (len(json_list) < 1): |     if (json_list is None) or (len(json_list) < 1): | ||||||
| @@ -461,6 +475,7 @@ def wait_until_ports_admin_down(resource_id=1, base_url="http://localhost:8080", | |||||||
| def waitUntilPortsAdminUp(resource_id=1, base_url="http://localhost:8080", port_list=()): | def waitUntilPortsAdminUp(resource_id=1, base_url="http://localhost:8080", port_list=()): | ||||||
|     return wait_until_ports_admin_up(resource_id=resource_id, base_url=base_url, port_list=port_list) |     return wait_until_ports_admin_up(resource_id=resource_id, base_url=base_url, port_list=port_list) | ||||||
|  |  | ||||||
|  |  | ||||||
| def wait_until_ports_admin_up(resource_id=1, base_url="http://localhost:8080", port_list=(), debug_=False): | def wait_until_ports_admin_up(resource_id=1, base_url="http://localhost:8080", port_list=(), debug_=False): | ||||||
|     print("Waiting until  ports appear admin-up...") |     print("Waiting until  ports appear admin-up...") | ||||||
|     down_stations = port_list.copy() |     down_stations = port_list.copy() | ||||||
| @@ -484,9 +499,11 @@ def wait_until_ports_admin_up(resource_id=1, base_url="http://localhost:8080", p | |||||||
|         sleep(1) |         sleep(1) | ||||||
|     return None |     return None | ||||||
|  |  | ||||||
|  |  | ||||||
| def waitUntilPortsDisappear(base_url="http://localhost:8080", port_list=(), debug=False): | def waitUntilPortsDisappear(base_url="http://localhost:8080", port_list=(), debug=False): | ||||||
|     wait_until_ports_disappear(base_url, port_list, debug) |     wait_until_ports_disappear(base_url, port_list, debug) | ||||||
|  |  | ||||||
|  |  | ||||||
| def wait_until_ports_disappear(base_url="http://localhost:8080", port_list=(), debug=False): | def wait_until_ports_disappear(base_url="http://localhost:8080", port_list=(), debug=False): | ||||||
|     if (port_list is None) or (len(port_list) < 1): |     if (port_list is None) or (len(port_list) < 1): | ||||||
|         if debug: |         if debug: | ||||||
| @@ -500,8 +517,8 @@ def wait_until_ports_disappear(base_url="http://localhost:8080", port_list=(), d | |||||||
|     else: |     else: | ||||||
|         found_stations = [port_list] |         found_stations = [port_list] | ||||||
|  |  | ||||||
|     temp_names_by_resource = {1:[]} |     temp_names_by_resource = {1: []} | ||||||
|     temp_query_by_resource = {1:""} |     temp_query_by_resource = {1: ""} | ||||||
|     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] | ||||||
| @@ -512,7 +529,8 @@ def wait_until_ports_disappear(base_url="http://localhost:8080", port_list=(), d | |||||||
|             temp_names_by_resource[resource_id] = [] |             temp_names_by_resource[resource_id] = [] | ||||||
|         port_name = eid[2] |         port_name = eid[2] | ||||||
|         temp_names_by_resource[resource_id].append(port_name) |         temp_names_by_resource[resource_id].append(port_name) | ||||||
|         temp_query_by_resource[resource_id] = "%s/%s/%s?fields=alias" % (url, resource_id, ",".join(temp_names_by_resource[resource_id])) |         temp_query_by_resource[resource_id] = "%s/%s/%s?fields=alias" % ( | ||||||
|  |         url, resource_id, ",".join(temp_names_by_resource[resource_id])) | ||||||
|     if debug: |     if debug: | ||||||
|         pprint.pprint(("temp_query_by_resource", temp_query_by_resource)) |         pprint.pprint(("temp_query_by_resource", temp_query_by_resource)) | ||||||
|     while len(found_stations) > 0: |     while len(found_stations) > 0: | ||||||
| @@ -541,7 +559,7 @@ def wait_until_ports_disappear(base_url="http://localhost:8080", port_list=(), d | |||||||
|         if len(found_stations) > 0: |         if len(found_stations) > 0: | ||||||
|             if debug: |             if debug: | ||||||
|                 pprint.pprint(("wait_until_ports_disappear found_stations:", found_stations)) |                 pprint.pprint(("wait_until_ports_disappear found_stations:", found_stations)) | ||||||
|     sleep(1) # safety |     sleep(1)  # safety | ||||||
|     return |     return | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -562,31 +580,32 @@ def name_to_eid(eid_input, non_port=False): | |||||||
|     if (eid_input is None) or (eid_input == ""): |     if (eid_input is None) or (eid_input == ""): | ||||||
|         raise ValueError("name_to_eid wants eid like 1.1.sta0 but given[%s]" % eid_input) |         raise ValueError("name_to_eid wants eid like 1.1.sta0 but given[%s]" % eid_input) | ||||||
|     if type(eid_input) is not str: |     if type(eid_input) is not str: | ||||||
|         raise ValueError("name_to_eid wants string formatted like '1.2.name', not a tuple or list or [%s]" % type(eid_input)) |         raise ValueError( | ||||||
|  |             "name_to_eid wants string formatted like '1.2.name', not a tuple or list or [%s]" % type(eid_input)) | ||||||
|  |  | ||||||
|     info = eid_input.split('.') |     info = eid_input.split('.') | ||||||
|     if len(info) == 1: |     if len(info) == 1: | ||||||
|         rv[2] = info[0] # just port name |         rv[2] = info[0]  # just port name | ||||||
|         return rv |         return rv | ||||||
|  |  | ||||||
|     if (len(info) == 2) and info[0].isnumeric() and not info[1].isnumeric(): # resource.port-name |     if (len(info) == 2) and info[0].isnumeric() and not info[1].isnumeric():  # resource.port-name | ||||||
|         rv[1] = int(info[0]) |         rv[1] = int(info[0]) | ||||||
|         rv[2] = info[1] |         rv[2] = info[1] | ||||||
|         return rv |         return rv | ||||||
|  |  | ||||||
|     elif (len(info) == 2) and not info[0].isnumeric(): # port-name.qvlan |     elif (len(info) == 2) and not info[0].isnumeric():  # port-name.qvlan | ||||||
|         rv[2] = info[0]+"."+info[1] |         rv[2] = info[0] + "." + info[1] | ||||||
|         return rv |         return rv | ||||||
|  |  | ||||||
|     if (len(info) == 3) and info[0].isnumeric() and info[1].isnumeric(): # shelf.resource.port-name |     if (len(info) == 3) and info[0].isnumeric() and info[1].isnumeric():  # shelf.resource.port-name | ||||||
|         rv[0] = int(info[0]) |         rv[0] = int(info[0]) | ||||||
|         rv[1] = int(info[1]) |         rv[1] = int(info[1]) | ||||||
|         rv[2] = info[2] |         rv[2] = info[2] | ||||||
|         return rv |         return rv | ||||||
|  |  | ||||||
|     elif (len(info) == 3) and info[0].isnumeric() and not info[1].isnumeric(): # resource.port-name.qvlan |     elif (len(info) == 3) and info[0].isnumeric() and not info[1].isnumeric():  # resource.port-name.qvlan | ||||||
|         rv[1] = int(info[0]) |         rv[1] = int(info[0]) | ||||||
|         rv[2] = info[1]+"."+info[2] |         rv[2] = info[1] + "." + info[2] | ||||||
|         return rv |         return rv | ||||||
|  |  | ||||||
|     if non_port: |     if non_port: | ||||||
| @@ -598,13 +617,14 @@ def name_to_eid(eid_input, non_port=False): | |||||||
|             rv[3] = int(info[3]) |             rv[3] = int(info[3]) | ||||||
|         return rv |         return rv | ||||||
|  |  | ||||||
|     if len(info) == 4: # shelf.resource.port-name.qvlan |     if len(info) == 4:  # shelf.resource.port-name.qvlan | ||||||
|         rv[0] = int(info[0]) |         rv[0] = int(info[0]) | ||||||
|         rv[1] = int(info[1]) |         rv[1] = int(info[1]) | ||||||
|         rv[2] = info[2]+"."+info[3] |         rv[2] = info[2] + "." + info[3] | ||||||
|  |  | ||||||
|     return rv |     return rv | ||||||
|  |  | ||||||
|  |  | ||||||
| def wait_until_ports_appear(base_url="http://localhost:8080", port_list=(), debug=False): | def wait_until_ports_appear(base_url="http://localhost:8080", port_list=(), debug=False): | ||||||
|     """ |     """ | ||||||
|     Use this method to pause until the LANforge system has caught up and implemented the |     Use this method to pause until the LANforge system has caught up and implemented the | ||||||
| @@ -650,6 +670,7 @@ def wait_until_ports_appear(base_url="http://localhost:8080", port_list=(), debu | |||||||
|         print("These stations appeared: " + ", ".join(found_stations)) |         print("These stations appeared: " + ", ".join(found_stations)) | ||||||
|     return |     return | ||||||
|  |  | ||||||
|  |  | ||||||
| def wait_until_endps(base_url="http://localhost:8080", endp_list=(), debug=False): | def wait_until_endps(base_url="http://localhost:8080", endp_list=(), debug=False): | ||||||
|     """ |     """ | ||||||
|  |  | ||||||
| @@ -793,11 +814,11 @@ def expand_endp_histogram(distribution_payload=None): | |||||||
|         raise ValueError("Unexpected histogram format.") |         raise ValueError("Unexpected histogram format.") | ||||||
|     multiplier = int(distribution_payload["histo_category_width"]) |     multiplier = int(distribution_payload["histo_category_width"]) | ||||||
|     formatted_dict = { |     formatted_dict = { | ||||||
|         #"00000 <= x <= 00001" : "0" |         # "00000 <= x <= 00001" : "0" | ||||||
|     } |     } | ||||||
|     for bucket_index in range(len(distribution_payload["histogram"]) - 1): |     for bucket_index in range(len(distribution_payload["histogram"]) - 1): | ||||||
|         pow1 = (2**bucket_index) * multiplier |         pow1 = (2 ** bucket_index) * multiplier | ||||||
|         pow2 = (2**(bucket_index+1)) * multiplier |         pow2 = (2 ** (bucket_index + 1)) * multiplier | ||||||
|         if bucket_index == 0: |         if bucket_index == 0: | ||||||
|             category_name = "00000 <= x <= {:-05.0f}".format(pow2) |             category_name = "00000 <= x <= {:-05.0f}".format(pow2) | ||||||
|         else: |         else: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Matthew Stidham
					Matthew Stidham