All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] auto-t: allow multiple PSKAgent's to be registered
@ 2022-06-29 17:31 James Prestwood
  2022-06-29 17:31 ` [PATCH 2/2] auto-t: fix unpredictability/pointless test from testAgent James Prestwood
  2022-06-29 18:25 ` [PATCH 1/2] auto-t: allow multiple PSKAgent's to be registered Denis Kenzior
  0 siblings, 2 replies; 3+ messages in thread
From: James Prestwood @ 2022-06-29 17:31 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

By creating a new bus connection for each agent we can register multiple
with IWD. This did mean the agent interface needs to be unique for each
agent (removing _agent_manager_if) as well as tracking multiple agents
in a list.
---
 autotests/util/iwd.py | 51 ++++++++++++++++++++-----------------------
 1 file changed, 24 insertions(+), 27 deletions(-)

diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py
index b74ba440..5591d7e1 100755
--- a/autotests/util/iwd.py
+++ b/autotests/util/iwd.py
@@ -865,10 +865,11 @@ class PSKAgent(dbus.service.Object):
             users = [users]
         self.users = users
         self._path = '/test/agent/%s' % agent_count
+        self._bus = dbus.bus.BusConnection(address_or_type=namespace.dbus_address)
 
         agent_count += 1
 
-        dbus.service.Object.__init__(self, namespace.get_bus(), self._path)
+        dbus.service.Object.__init__(self, self._bus, self._path)
 
     @property
     def path(self):
@@ -1086,11 +1087,10 @@ class IWD(AsyncOpAbstract):
         start_iwd_daemon=True)
     '''
     _object_manager_if = None
-    _agent_manager_if = None
     _iwd_proc = None
     _devices = None
     _default_instance = None
-    psk_agent = None
+    psk_agents = []
 
     def __init__(self, start_iwd_daemon = False, iwd_config_dir = '/tmp',
                             iwd_storage_dir = IWD_STORAGE_DIR, namespace=ctx):
@@ -1114,11 +1114,12 @@ class IWD(AsyncOpAbstract):
             IWD._default_instance = weakref.ref(self)
 
     def __del__(self):
-        if self.psk_agent:
-            self.unregister_psk_agent(self.psk_agent)
+        for agent in self.psk_agents:
+            self.unregister_psk_agent(agent)
+
+        self.psk_agents = []
 
         self._object_manager_if = None
-        self._agent_manager_if = None
         self._known_networks = None
         self._devices = None
 
@@ -1137,15 +1138,6 @@ class IWD(AsyncOpAbstract):
                                       DBUS_OBJECT_MANAGER)
         return self._object_manager_if
 
-    @property
-    def _agent_manager(self):
-        if self._agent_manager_if is None:
-            self._agent_manager_if =\
-                dbus.Interface(self._bus.get_object(IWD_SERVICE,
-                                                    IWD_AGENT_MANAGER_PATH),
-                               IWD_AGENT_MANAGER_INTERFACE)
-        return self._agent_manager_if
-
     @staticmethod
     def _wait_for_object_condition(obj, condition_str, max_wait = 50):
         def _eval_wrap(obj, condition_str):
@@ -1271,22 +1263,27 @@ class IWD(AsyncOpAbstract):
         return known_network_list
 
     def register_psk_agent(self, psk_agent):
-        self._agent_manager.RegisterAgent(
-                                     psk_agent.path,
-                                     dbus_interface=IWD_AGENT_MANAGER_INTERFACE,
-                                     reply_handler=self._success,
-                                     error_handler=self._failure)
+        iface = dbus.Interface(psk_agent._bus.get_object(IWD_SERVICE,
+                                                IWD_AGENT_MANAGER_PATH),
+                                                IWD_AGENT_MANAGER_INTERFACE)
+        iface.RegisterAgent(psk_agent.path,
+                            dbus_interface=IWD_AGENT_MANAGER_INTERFACE,
+                            reply_handler=self._success,
+                            error_handler=self._failure)
+
         self._wait_for_async_op()
-        self.psk_agent = psk_agent
+        self.psk_agents.append(psk_agent)
 
     def unregister_psk_agent(self, psk_agent):
-        self._agent_manager.UnregisterAgent(
-                                     psk_agent.path,
-                                     dbus_interface=IWD_AGENT_MANAGER_INTERFACE,
-                                     reply_handler=self._success,
-                                     error_handler=self._failure)
+        iface = dbus.Interface(psk_agent._bus.get_object(IWD_SERVICE,
+                                                IWD_AGENT_MANAGER_PATH),
+                                                IWD_AGENT_MANAGER_INTERFACE)
+        iface.UnregisterAgent(psk_agent.path,
+                                dbus_interface=IWD_AGENT_MANAGER_INTERFACE,
+                                reply_handler=self._success,
+                                error_handler=self._failure)
         self._wait_for_async_op()
-        self.psk_agent = None
+        self.psk_agents.remove(psk_agent)
 
     @staticmethod
     def get_instance():
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] auto-t: fix unpredictability/pointless test from testAgent
  2022-06-29 17:31 [PATCH 1/2] auto-t: allow multiple PSKAgent's to be registered James Prestwood
@ 2022-06-29 17:31 ` James Prestwood
  2022-06-29 18:25 ` [PATCH 1/2] auto-t: allow multiple PSKAgent's to be registered Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: James Prestwood @ 2022-06-29 17:31 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

testAgent had a few tests which weren't reliable, and one was not actually
testing anything, or at least not what the name implied it should be testing.

The first issue was using iwctl in the first place. There is not a reliable
way to know when iwctl has registered its agent so relying on that with a sleep,
or waiting for the service to become available isn't 100% fool proof. To fix
this use the updated PSKAgent which allows multiple to be registered. This ensures
the agent is ready for requests. This test was also renamed to be consistent with
what its actually testing: that IWD uses the first agent registered.

This removes test_connection_with_other_agent as well because this test case is
covered by the client test itself. There is no need to re-test iwctl's agent
functionality here.
---
 autotests/testAgent/agent_test.py | 40 ++++---------------------------
 1 file changed, 4 insertions(+), 36 deletions(-)

diff --git a/autotests/testAgent/agent_test.py b/autotests/testAgent/agent_test.py
index c1dc8c7c..fc988f21 100644
--- a/autotests/testAgent/agent_test.py
+++ b/autotests/testAgent/agent_test.py
@@ -56,51 +56,19 @@ class Test(unittest.TestCase):
 
         IWD.clear_storage()
 
-    def test_connection_with_other_agent(self):
-        def wait_for_service_pid(pid):
-            dbus_object = ctx._bus.get_object('org.freedesktop.DBus',
-                                 '/org/freedesktop/DBus')
-            dbus_iface = dbus.Interface(dbus_object, 'org.freedesktop.DBus')
-
-            services = dbus_iface.ListNames()
-
-            for service in services:
-                bus_iface = dbus.Interface(dbus_object, "org.freedesktop.DBus")
-                if pid == int(bus_iface.GetConnectionUnixProcessID(service)):
-                    return True
-
-            return False
-
+    def test_connection_use_first_from_multiple_registered(self):
         wd = IWD()
 
-        iwctl = ctx.start_process(['iwctl', '-P', 'secret_ssid2'])
-
-        # Let iwctl to start and register its agent.
-        ctx.non_block_wait(wait_for_service_pid, 10, iwctl.pid)
-
-        self.check_connection(wd, 'ssid2')
-
-        iwctl.kill()
-
-        IWD.clear_storage()
-
-    def test_connection_use_own_agent_from_multiple_registered(self):
-
-        wd = IWD()
-
-        iwctl = ctx.start_process(['iwctl', '-P', 'secret_ssid2'])
-        # Let iwctl to start and register its agent.
-        wd.wait(2)
-
         psk_agent = PSKAgent("secret_ssid1")
         wd.register_psk_agent(psk_agent)
 
+        psk_agent = PSKAgent("secret_ssid2")
+        wd.register_psk_agent(psk_agent)
+
         self.check_connection(wd, 'ssid1')
 
         wd.unregister_psk_agent(psk_agent)
 
-        iwctl.kill()
-
         IWD.clear_storage()
 
     @classmethod
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] auto-t: allow multiple PSKAgent's to be registered
  2022-06-29 17:31 [PATCH 1/2] auto-t: allow multiple PSKAgent's to be registered James Prestwood
  2022-06-29 17:31 ` [PATCH 2/2] auto-t: fix unpredictability/pointless test from testAgent James Prestwood
@ 2022-06-29 18:25 ` Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: Denis Kenzior @ 2022-06-29 18:25 UTC (permalink / raw)
  To: James Prestwood, iwd

Hi James,

On 6/29/22 12:31, James Prestwood wrote:
> By creating a new bus connection for each agent we can register multiple
> with IWD. This did mean the agent interface needs to be unique for each
> agent (removing _agent_manager_if) as well as tracking multiple agents
> in a list.
> ---
>   autotests/util/iwd.py | 51 ++++++++++++++++++++-----------------------
>   1 file changed, 24 insertions(+), 27 deletions(-)
> 

Both applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-29 18:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-29 17:31 [PATCH 1/2] auto-t: allow multiple PSKAgent's to be registered James Prestwood
2022-06-29 17:31 ` [PATCH 2/2] auto-t: fix unpredictability/pointless test from testAgent James Prestwood
2022-06-29 18:25 ` [PATCH 1/2] auto-t: allow multiple PSKAgent's to be registered Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.