mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-21 11:52:34 +01:00
auto-t: refactor get_instance from iwd.py
When network namespaces are introduced there may be multiple IWD class instances. This makes IWD.get_instance ambiguous when namespaces are involved. iwd.py has been refactored to not use IWD.get_instance, but testutil still needs it since its purely based off interface names. Rather than remove it and modify every test to pass the IWD object we can just maintain the existing behavior for only the root namespace.
This commit is contained in:
parent
4bf8bf2396
commit
eb92c0a6e5
@ -399,14 +399,12 @@ class Device(IWDDBusAbstract):
|
|||||||
elif not scan_if_needed:
|
elif not scan_if_needed:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
iwd = IWD.get_instance()
|
|
||||||
|
|
||||||
self.scan()
|
self.scan()
|
||||||
|
|
||||||
condition = 'obj.scanning'
|
condition = 'obj.scanning'
|
||||||
iwd.wait_for_object_condition(self, condition)
|
IWD._wait_for_object_condition(self, condition)
|
||||||
condition = 'not obj.scanning'
|
condition = 'not obj.scanning'
|
||||||
iwd.wait_for_object_condition(self, condition)
|
IWD._wait_for_object_condition(self, condition)
|
||||||
|
|
||||||
for bus_obj in self._station.GetOrderedNetworks():
|
for bus_obj in self._station.GetOrderedNetworks():
|
||||||
ordered_network = OrderedNetwork(bus_obj)
|
ordered_network = OrderedNetwork(bus_obj)
|
||||||
@ -940,7 +938,7 @@ class IWD(AsyncOpAbstract):
|
|||||||
_agent_manager_if = None
|
_agent_manager_if = None
|
||||||
_iwd_proc = None
|
_iwd_proc = None
|
||||||
_devices = None
|
_devices = None
|
||||||
_instance = None
|
_default_instance = None
|
||||||
psk_agent = None
|
psk_agent = None
|
||||||
|
|
||||||
def __init__(self, start_iwd_daemon = False, iwd_config_dir = '/tmp'):
|
def __init__(self, start_iwd_daemon = False, iwd_config_dir = '/tmp'):
|
||||||
@ -964,8 +962,11 @@ class IWD(AsyncOpAbstract):
|
|||||||
self._devices = DeviceList(self)
|
self._devices = DeviceList(self)
|
||||||
|
|
||||||
# Weak to make sure the test's reference to @self is the only counted
|
# Weak to make sure the test's reference to @self is the only counted
|
||||||
# reference so that __del__ gets called when it's released
|
# reference so that __del__ gets called when it's released. This is only
|
||||||
IWD._instance = weakref.ref(self)
|
# done for the root namespace in order to allow testutil to function
|
||||||
|
# correctly in non-namespace tests.
|
||||||
|
if self.namespace.name == "root":
|
||||||
|
IWD._default_instance = weakref.ref(self)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self.psk_agent:
|
if self.psk_agent:
|
||||||
@ -998,10 +999,11 @@ class IWD(AsyncOpAbstract):
|
|||||||
IWD_AGENT_MANAGER_INTERFACE)
|
IWD_AGENT_MANAGER_INTERFACE)
|
||||||
return self._agent_manager_if
|
return self._agent_manager_if
|
||||||
|
|
||||||
def wait_for_object_condition(self, obj, condition_str, max_wait = 50):
|
@staticmethod
|
||||||
self._wait_timed_out = False
|
def _wait_for_object_condition(obj, condition_str, max_wait = 50):
|
||||||
|
_wait_timed_out = False
|
||||||
def wait_timeout_cb():
|
def wait_timeout_cb():
|
||||||
self._wait_timed_out = True
|
_wait_timed_out = True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -1009,14 +1011,17 @@ class IWD(AsyncOpAbstract):
|
|||||||
context = ctx.mainloop.get_context()
|
context = ctx.mainloop.get_context()
|
||||||
while not eval(condition_str):
|
while not eval(condition_str):
|
||||||
context.iteration(may_block=True)
|
context.iteration(may_block=True)
|
||||||
if self._wait_timed_out and ctx.args.gdb == None:
|
if _wait_timed_out and ctx.args.gdb == None:
|
||||||
raise TimeoutError('[' + condition_str + ']'\
|
raise TimeoutError('[' + condition_str + ']'\
|
||||||
' condition was not met in '\
|
' condition was not met in '\
|
||||||
+ str(max_wait) + ' sec')
|
+ str(max_wait) + ' sec')
|
||||||
finally:
|
finally:
|
||||||
if not self._wait_timed_out:
|
if not _wait_timed_out:
|
||||||
GLib.source_remove(timeout)
|
GLib.source_remove(timeout)
|
||||||
|
|
||||||
|
def wait_for_object_condition(self, *args, **kwargs):
|
||||||
|
self._wait_for_object_condition(*args, **kwargs)
|
||||||
|
|
||||||
def wait(self, time):
|
def wait(self, time):
|
||||||
self._wait_timed_out = False
|
self._wait_timed_out = False
|
||||||
def wait_timeout_cb():
|
def wait_timeout_cb():
|
||||||
@ -1129,4 +1134,4 @@ class IWD(AsyncOpAbstract):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_instance():
|
def get_instance():
|
||||||
return IWD._instance()
|
return IWD._default_instance()
|
||||||
|
Loading…
Reference in New Issue
Block a user