From 4ea2935b1a267d43c2bba203dec364914cc3ac43 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Fri, 26 Jun 2020 18:16:20 +1000 Subject: [PATCH] ci provisioning: Add some experiments to check the runner's STA state Not clear why sometimes it associates without negotiating a new DHCP lease. --- .../softap_prov/softap_prov_test.py | 79 ++++++++++--------- tools/ci/python_packages/wifi_tools.py | 7 +- 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/examples/provisioning/softap_prov/softap_prov_test.py b/examples/provisioning/softap_prov/softap_prov_test.py index a382fba11..8d74d9ad6 100644 --- a/examples/provisioning/softap_prov/softap_prov_test.py +++ b/examples/provisioning/softap_prov/softap_prov_test.py @@ -51,52 +51,55 @@ def test_examples_provisioning_softap(env, extra_data): print("SoftAP SSID : " + ssid) print("SoftAP Password : " + password) - ctrl = wifi_tools.wpa_cli(iface, reset_on_exit=True) - print("Connecting to DUT SoftAP...") - ip = ctrl.connect(ssid, password) - got_ip = dut1.expect(re.compile(r"DHCP server assigned IP to a station, IP is: (\d+.\d+.\d+.\d+)"), timeout=60)[0] - if ip != got_ip: - raise RuntimeError("SoftAP connected to another host! " + ip + "!=" + got_ip) - print("Connected to DUT SoftAP") + try: + ctrl = wifi_tools.wpa_cli(iface, reset_on_exit=True) + print("Connecting to DUT SoftAP...") + ip = ctrl.connect(ssid, password) + got_ip = dut1.expect(re.compile(r"DHCP server assigned IP to a station, IP is: (\d+.\d+.\d+.\d+)"), timeout=60)[0] + if ip != got_ip: + raise RuntimeError("SoftAP connected to another host! " + ip + "!=" + got_ip) + print("Connected to DUT SoftAP") - print("Starting Provisioning") - verbose = False - protover = "V0.1" - secver = 1 - pop = "abcd1234" - provmode = "softap" - ap_ssid = "myssid" - ap_password = "mypassword" - softap_endpoint = ip.split('.')[0] + "." + ip.split('.')[1] + "." + ip.split('.')[2] + ".1:80" + print("Starting Provisioning") + verbose = False + protover = "V0.1" + secver = 1 + pop = "abcd1234" + provmode = "softap" + ap_ssid = "myssid" + ap_password = "mypassword" + softap_endpoint = ip.split('.')[0] + "." + ip.split('.')[1] + "." + ip.split('.')[2] + ".1:80" - print("Getting security") - security = esp_prov.get_security(secver, pop, verbose) - if security is None: - raise RuntimeError("Failed to get security") + print("Getting security") + security = esp_prov.get_security(secver, pop, verbose) + if security is None: + raise RuntimeError("Failed to get security") - print("Getting transport") - transport = esp_prov.get_transport(provmode, softap_endpoint) - if transport is None: - raise RuntimeError("Failed to get transport") + print("Getting transport") + transport = esp_prov.get_transport(provmode, softap_endpoint) + if transport is None: + raise RuntimeError("Failed to get transport") - print("Verifying protocol version") - if not esp_prov.version_match(transport, protover): - raise RuntimeError("Mismatch in protocol version") + print("Verifying protocol version") + if not esp_prov.version_match(transport, protover): + raise RuntimeError("Mismatch in protocol version") - print("Starting Session") - if not esp_prov.establish_session(transport, security): - raise RuntimeError("Failed to start session") + print("Starting Session") + if not esp_prov.establish_session(transport, security): + raise RuntimeError("Failed to start session") - print("Sending Wifi credential to DUT") - if not esp_prov.send_wifi_config(transport, security, ap_ssid, ap_password): - raise RuntimeError("Failed to send Wi-Fi config") + print("Sending Wifi credential to DUT") + if not esp_prov.send_wifi_config(transport, security, ap_ssid, ap_password): + raise RuntimeError("Failed to send Wi-Fi config") - print("Applying config") - if not esp_prov.apply_wifi_config(transport, security): - raise RuntimeError("Failed to send apply config") + print("Applying config") + if not esp_prov.apply_wifi_config(transport, security): + raise RuntimeError("Failed to send apply config") - if not esp_prov.wait_wifi_connected(transport, security): - raise RuntimeError("Provisioning failed") + if not esp_prov.wait_wifi_connected(transport, security): + raise RuntimeError("Provisioning failed") + finally: + ctrl.reset() if __name__ == '__main__': diff --git a/tools/ci/python_packages/wifi_tools.py b/tools/ci/python_packages/wifi_tools.py index bc3a7aab8..b926efb55 100644 --- a/tools/ci/python_packages/wifi_tools.py +++ b/tools/ci/python_packages/wifi_tools.py @@ -55,8 +55,9 @@ class wpa_cli: if self.iface_ifc is None: raise RuntimeError('supplicant : Failed to fetch interface') - self.old_network = self.iface_obj.Get("fi.w1.wpa_supplicant1.Interface", "CurrentNetwork", - dbus_interface='org.freedesktop.DBus.Properties') + self.old_network = self._get_iface_property("CurrentNetwork") + print("Old network is %s" % self.old_network) + if self.old_network == '/': self.old_network = None else: @@ -78,6 +79,8 @@ class wpa_cli: if self.new_network is not None: self.iface_ifc.RemoveNetwork(self.new_network) + print("Pre-connect state is %s, IP is %s" % (self._get_iface_property("State"), get_wiface_IPv4(self.iface_name))) + self.new_network = self.iface_ifc.AddNetwork({"ssid": ssid, "psk": password}) self.iface_ifc.SelectNetwork(self.new_network)