mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-10-31 02:38:03 +00:00 
			
		
		
		
	sta_scan_test: Fix regression, create csv_output option
Signed-off-by: Matthew Stidham <stidmatt@gmail.com>
This commit is contained in:
		| @@ -15,6 +15,7 @@ License: Free to distribute and modify. LANforge systems must be licensed. | |||||||
| import sys | import sys | ||||||
| import os | import os | ||||||
| import importlib | import importlib | ||||||
|  | import pandas as pd | ||||||
|  |  | ||||||
| if sys.version_info[0] != 3: | if sys.version_info[0] != 3: | ||||||
|     print("This script requires Python 3") |     print("This script requires Python 3") | ||||||
| @@ -25,8 +26,6 @@ import time | |||||||
|  |  | ||||||
| sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../"))) | sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../"))) | ||||||
|  |  | ||||||
| lfcli_base = importlib.import_module("py-json.LANforge.lfcli_base") |  | ||||||
| LFCliBase = lfcli_base.LFCliBase |  | ||||||
| realm = importlib.import_module("py-json.realm") | realm = importlib.import_module("py-json.realm") | ||||||
| Realm = realm.Realm | Realm = realm.Realm | ||||||
| LFUtils = importlib.import_module("py-json.LANforge.LFUtils") | LFUtils = importlib.import_module("py-json.LANforge.LFUtils") | ||||||
| @@ -37,17 +36,20 @@ class StaScan(Realm): | |||||||
|                  ssid=None, |                  ssid=None, | ||||||
|                  security=None, |                  security=None, | ||||||
|                  password=None, |                  password=None, | ||||||
|                  sta_list=[], |                  sta_list=None, | ||||||
|                  upstream=None, |                  upstream=None, | ||||||
|                  radio=None, |                  radio=None, | ||||||
|                  host="localhost", |                  host="localhost", | ||||||
|                  port=8080, |                  port=8080, | ||||||
|                  mode=0, |                  mode=0, | ||||||
|                  number_template="00000", |                  number_template="00000", | ||||||
|  |                  csv_output=False, | ||||||
|                  use_ht160=False, |                  use_ht160=False, | ||||||
|                  _debug_on=False, |                  _debug_on=False, | ||||||
|                  _exit_on_error=False, |                  _exit_on_error=False, | ||||||
|                  _exit_on_fail=False): |                  _exit_on_fail=False): | ||||||
|  |         if sta_list is None: | ||||||
|  |             sta_list = [] | ||||||
|         super().__init__(lfclient_host=host, |         super().__init__(lfclient_host=host, | ||||||
|                          lfclient_port=port), |                          lfclient_port=port), | ||||||
|         self.upstream = upstream |         self.upstream = upstream | ||||||
| @@ -60,6 +62,7 @@ class StaScan(Realm): | |||||||
|         self.radio = radio |         self.radio = radio | ||||||
|         self.mode = mode |         self.mode = mode | ||||||
|         self.number_template = number_template |         self.number_template = number_template | ||||||
|  |         self.csv_output = csv_output | ||||||
|         self.debug = _debug_on |         self.debug = _debug_on | ||||||
|         self.station_profile = self.new_station_profile() |         self.station_profile = self.new_station_profile() | ||||||
|         self.station_profile.lfclient_url = self.lfclient_url |         self.station_profile.lfclient_url = self.lfclient_url | ||||||
| @@ -77,22 +80,50 @@ class StaScan(Realm): | |||||||
|     def start(self): |     def start(self): | ||||||
|         self.station_profile.admin_up() |         self.station_profile.admin_up() | ||||||
|         print(self.sta_list) |         print(self.sta_list) | ||||||
|         print("Sleeping 15s while waiting for scan") |         LFUtils.wait_until_ports_admin_up(base_url=self.lfclient_url, port_list=self.station_profile.station_names, | ||||||
|         data = { |                                           debug_=self.debug) | ||||||
|             "shelf": 1, |         stations = [LFUtils.name_to_eid(x) for x in self.sta_list] | ||||||
|             "resource": 1, |         stations = pd.DataFrame(stations) | ||||||
|             "port": self.sta_list |         resources = stations[1].unique() | ||||||
|         } |         interfaces = list() | ||||||
|         self.json_post("/cli-json/scan_wifi", data) |         for resource in resources: | ||||||
|         time.sleep(15) |             shelf = stations[0][0] | ||||||
|         scan_results = self.json_get("scanresults/1/1/%s" % ','.join(self.sta_list)) |             resource_station = list(stations[stations[1] == resource][2]) | ||||||
|  |             url = '/port/%s/%s/%s' % (shelf, resource, ','.join(resource_station)) | ||||||
|         print("{0:<23}".format("BSS"), "{0:<7}".format("Signal"), "{0:<5}".format("SSID")) |             response = self.json_get(url) | ||||||
|         for result in scan_results['scan-results']: |             if 'interface' in response.keys(): | ||||||
|             for name, info in result.items(): |                 interface = response['interface'] | ||||||
|                 print("%s\t%s\t%s" % (info['bss'], info['signal'], info['ssid'])) |                 interfaces.append(interface) | ||||||
|  |             elif 'interfaces' in response.keys(): | ||||||
|  |                 response_interfaces = response['interfaces'] | ||||||
|  |                 for interface in response_interfaces: | ||||||
|  |                     for item in interface.values(): | ||||||
|  |                         interfaces.append(item) | ||||||
|  |         df = pd.DataFrame(interfaces) | ||||||
|  |         stations = df[df['port type'] == 'WIFI-STA'] | ||||||
|  |         stations = list(stations.drop_duplicates('parent dev')['alias']) | ||||||
|  |         stations = [station for station in stations if station in self.sta_list] | ||||||
|  |  | ||||||
|  |         for port in stations: | ||||||
|  |             port = LFUtils.name_to_eid(port) | ||||||
|  |             data = { | ||||||
|  |                 "shelf": port[0], | ||||||
|  |                 "resource": port[1], | ||||||
|  |                 "port": port[2] | ||||||
|  |             } | ||||||
|  |             self.json_post("/cli-json/scan_wifi", data) | ||||||
|  |             time.sleep(15) | ||||||
|  |             scan_results = self.json_get("scanresults/%s/%s/%s" % (port[0], port[1], port[2])) | ||||||
|  |             if self.csv_output: | ||||||
|  |                 results = scan_results['scan-results'] | ||||||
|  |                 df = pd.DataFrame([list(result.values())[0] for result in results]) | ||||||
|  |                 df.to_csv(self.csv_output) | ||||||
|  |                 print('CSV output saved at %s' % self.csv_output) | ||||||
|  |             else: | ||||||
|  |                 print("{0:<23}".format("BSS"), "{0:<7}".format("Signal"), "{0:<5}".format("SSID")) | ||||||
|  |                 for result in scan_results['scan-results']: | ||||||
|  |                     for name, info in result.items(): | ||||||
|  |                         print("%s\t%s\t%s" % (info['bss'], info['signal'], info['ssid'])) | ||||||
|  |  | ||||||
|     def pre_cleanup(self): |     def pre_cleanup(self): | ||||||
|         for sta in self.sta_list: |         for sta in self.sta_list: | ||||||
| @@ -133,6 +164,7 @@ def main(): | |||||||
|     parser.add_argument('--mode', help='Used to force mode of stations') |     parser.add_argument('--mode', help='Used to force mode of stations') | ||||||
|     parser.add_argument('--sta_name', help='Optional: User defined station names, can be a comma or space separated list', nargs='+', |     parser.add_argument('--sta_name', help='Optional: User defined station names, can be a comma or space separated list', nargs='+', | ||||||
|                         default=["sta0000"]) |                         default=["sta0000"]) | ||||||
|  |     parser.add_argument('--csv_output', help='create CSV from scan results, otherwise print it in the terminal', default=None) | ||||||
|  |  | ||||||
|     args = parser.parse_args() |     args = parser.parse_args() | ||||||
|  |  | ||||||
| @@ -147,6 +179,7 @@ def main(): | |||||||
|                             radio=args.radio, |                             radio=args.radio, | ||||||
|                             security=args.security, |                             security=args.security, | ||||||
|                             use_ht160=False, |                             use_ht160=False, | ||||||
|  |                             csv_output=args.csv_output, | ||||||
|                             mode=args.mode, |                             mode=args.mode, | ||||||
|                             _debug_on=args.debug) |                             _debug_on=args.debug) | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Matthew Stidham
					Matthew Stidham