mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-10-31 18:58:01 +00:00 
			
		
		
		
	LFRequest.py: uses wpa2 flag; uses waitX methods
This commit is contained in:
		| @@ -16,6 +16,7 @@ from LANforge import LFUtils | |||||||
| # from LANforge import LFCliBase | # from LANforge import LFCliBase | ||||||
| from LANforge.lfcli_base import LFCliBase | from LANforge.lfcli_base import LFCliBase | ||||||
| from LANforge.LFUtils import * | from LANforge.LFUtils import * | ||||||
|  | from pprint import pprint | ||||||
|  |  | ||||||
| if sys.version_info[0] != 3: | if sys.version_info[0] != 3: | ||||||
|     print("This script requires Python 3") |     print("This script requires Python 3") | ||||||
| @@ -67,8 +68,9 @@ class StaConnect(LFCliBase): | |||||||
|  |  | ||||||
|     def run(self): |     def run(self): | ||||||
|         self.checkConnect() |         self.checkConnect() | ||||||
|         # Create stations and turn dhcp on |         eth1IP = self.jsonGet(self.getUpstreamUrl()) | ||||||
|         print("Creating station and turning on dhcp") |         if eth1IP['interface']['ip'] == "0.0.0.0": | ||||||
|  |             print(f"Warning: {self.getUpstreamUrl()} lacks ip address") | ||||||
|  |  | ||||||
|         url = self.getStaUrl() |         url = self.getStaUrl() | ||||||
|         response = super().jsonGet(url) |         response = super().jsonGet(url) | ||||||
| @@ -76,10 +78,14 @@ class StaConnect(LFCliBase): | |||||||
|             if response["interface"] is not None: |             if response["interface"] is not None: | ||||||
|                 print("removing old station") |                 print("removing old station") | ||||||
|                 LFUtils.removePort(self.resource, self.sta_name, self.mgr_url) |                 LFUtils.removePort(self.resource, self.sta_name, self.mgr_url) | ||||||
|                 time.sleep(5) |                 LFUtils.waitUntilPortsDisappear(self.resource, self.mgr_url, [self.sta_name]) | ||||||
|  |  | ||||||
|         # See add_sta in LANforge CLI user guide |         # Create stations and turn dhcp on | ||||||
|  |         print("Creating station %s and turning on dhcp..." % self.sta_name) | ||||||
|         url = "cli-json/add_sta" |         url = "cli-json/add_sta" | ||||||
|  |         flags = 0x10000 | ||||||
|  |         if "" != self.dut_passwd: | ||||||
|  |             flags += 0x400 | ||||||
|         data = { |         data = { | ||||||
|             "shelf": 1, |             "shelf": 1, | ||||||
|             "resource": self.resource, |             "resource": self.resource, | ||||||
| @@ -89,9 +95,9 @@ class StaConnect(LFCliBase): | |||||||
|             "key": self.dut_passwd, |             "key": self.dut_passwd, | ||||||
|             "mode": self.sta_mode, |             "mode": self.sta_mode, | ||||||
|             "mac": "xx:xx:xx:xx:*:xx", |             "mac": "xx:xx:xx:xx:*:xx", | ||||||
|             "flags": 0x10000  # verbose, open |             "flags": flags  # verbose, wpa2 | ||||||
|         } |         } | ||||||
|         print("adding new station") |         print("Adding new station %s " % self.sta_name) | ||||||
|         super().jsonPost(url, data) |         super().jsonPost(url, data) | ||||||
|  |  | ||||||
|         reqURL = "cli-json/set_port" |         reqURL = "cli-json/set_port" | ||||||
| @@ -102,21 +108,16 @@ class StaConnect(LFCliBase): | |||||||
|             "current_flags": 0x80000000,  # use DHCP, not down |             "current_flags": 0x80000000,  # use DHCP, not down | ||||||
|             "interest": 0x4002  # set dhcp, current flags |             "interest": 0x4002  # set dhcp, current flags | ||||||
|         } |         } | ||||||
|         print("configuring port") |         print("Configuring %s..." % self.sta_name) | ||||||
|         super().jsonPost(reqURL, data) |         super().jsonPost(reqURL, data) | ||||||
|  |  | ||||||
|         time.sleep(5) |  | ||||||
|  |  | ||||||
|         eth1IP = self.jsonGet(self.getUpstreamUrl()) |  | ||||||
|         if eth1IP['interface']['ip'] == "0.0.0.0": |  | ||||||
|             print(f"Warning: {self.getUpstreamUrl()} lacks ip address") |  | ||||||
|  |  | ||||||
|         reqURL = "cli-json/nc_show_ports" |         reqURL = "cli-json/nc_show_ports" | ||||||
|         data = {"shelf": 1, |         data = {"shelf": 1, | ||||||
|                 "resource": self.resource, |                 "resource": self.resource, | ||||||
|                 "port": self.sta_name, |                 "port": self.sta_name, | ||||||
|                 "probe_flags": 1} |                 "probe_flags": 1} | ||||||
|         super().jsonPost(reqURL, data) |         super().jsonPost(reqURL, data) | ||||||
|  |         LFUtils.waitUntilPortsAdminUp(self.resource, self.mgr_url, [self.sta_name]) | ||||||
|  |  | ||||||
|         # station_info = self.jsonGet(self.mgr_url, "%s?fields=port,ip,ap" % (self.getStaUrl())) |         # station_info = self.jsonGet(self.mgr_url, "%s?fields=port,ip,ap" % (self.getStaUrl())) | ||||||
|         duration = 0 |         duration = 0 | ||||||
| @@ -124,10 +125,8 @@ class StaConnect(LFCliBase): | |||||||
|         ip = "0.0.0.0" |         ip = "0.0.0.0" | ||||||
|         ap = "" |         ap = "" | ||||||
|         while (ip == "0.0.0.0") and (duration < maxTime): |         while (ip == "0.0.0.0") and (duration < maxTime): | ||||||
|  |  | ||||||
|             duration += 2 |             duration += 2 | ||||||
|             time.sleep(2) |             time.sleep(2) | ||||||
|  |  | ||||||
|             station_info = super().jsonGet(f"{self.getStaUrl()}?fields=port,ip,ap") |             station_info = super().jsonGet(f"{self.getStaUrl()}?fields=port,ip,ap") | ||||||
|  |  | ||||||
|             # LFUtils.debug_printer.pprint(station_info) |             # LFUtils.debug_printer.pprint(station_info) | ||||||
| @@ -138,10 +137,10 @@ class StaConnect(LFCliBase): | |||||||
|                     ap = station_info["interface"]["ap"] |                     ap = station_info["interface"]["ap"] | ||||||
|  |  | ||||||
|             if (ap == "Not-Associated") or (ap == ""): |             if (ap == "Not-Associated") or (ap == ""): | ||||||
|                 print("Station waiting to associate...") |                 print("Waiting for %s associate to AP [%s]..." % (self.sta_name, ap)) | ||||||
|             else: |             else: | ||||||
|                 if ip == "0.0.0.0": |                 if ip == "0.0.0.0": | ||||||
|                     print("Station waiting for IP ...") |                     print("Waiting for %s to gain IP ..." % self.sta_name) | ||||||
|  |  | ||||||
|         if (ap != "") and (ap != "Not-Associated"): |         if (ap != "") and (ap != "Not-Associated"): | ||||||
|             print(f"Connected to AP: {ap}") |             print(f"Connected to AP: {ap}") | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jed Reynolds
					Jed Reynolds