mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-29 13:59:24 +01:00
b600440ea2
In certain cases the autoconnect portion of each subtest was connecting to the network so fast that the check for obj.scanning was never successful since IWD was already connected (and in turn not scanning). Since the autoconnect path will wait for the device to be connected there really isn't a reason to wait for any scanning conditions. The normal connect path does need to wait for scanning though, and for this we can now use the new scan_if_needed parameter to get_ordered_networks.
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
#!/usr/bin/python3
|
|
|
|
import unittest
|
|
import sys
|
|
|
|
sys.path.append('../util')
|
|
import iwd
|
|
from iwd import IWD
|
|
from iwd import PSKAgent
|
|
from iwd import NetworkType
|
|
|
|
class TestConnectAutoConnect(unittest.TestCase):
|
|
|
|
def check_connect(self, wd, device, ssid, throws):
|
|
ordered_network = device.get_ordered_network(ssid, scan_if_needed=True)
|
|
|
|
condition = 'not obj.connected'
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
if not throws is None:
|
|
with self.assertRaises(throws):
|
|
ordered_network.network_object.connect()
|
|
return
|
|
else:
|
|
ordered_network.network_object.connect()
|
|
|
|
condition = 'obj.connected'
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
def check_autoconnect(self, wd, device, ssid, throws):
|
|
if throws is None:
|
|
condition = 'obj.state == DeviceState.connected'
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
condition = 'obj.connected_network is not None'
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
ordered_network = device.get_ordered_network(ssid)
|
|
|
|
self.assertTrue(ordered_network.network_object.connected)
|
|
|
|
device.disconnect()
|
|
|
|
condition = 'obj.state == DeviceState.disconnected'
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
def validate_connection(self, wd, ssid, autoconnect, throws = None,
|
|
use_agent = False):
|
|
if use_agent:
|
|
psk_agent = PSKAgent("secret123")
|
|
wd.register_psk_agent(psk_agent)
|
|
|
|
devices = wd.list_devices(1)
|
|
self.assertIsNotNone(devices)
|
|
device = devices[0]
|
|
|
|
if autoconnect:
|
|
self.check_autoconnect(wd, device, ssid, throws)
|
|
else:
|
|
self.check_connect(wd, device, ssid, throws)
|
|
|
|
if use_agent:
|
|
wd.unregister_psk_agent(psk_agent)
|
|
|
|
def validate(self, ssid, autoconnect, throws = None, use_agent = False):
|
|
wd = IWD(True)
|
|
|
|
self.validate_connection(wd, ssid, autoconnect, throws, use_agent)
|