Wireless Daemon for Linux
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH 2/4] auto-t: update utilities to use namespaces
Date: Tue, 17 Nov 2020 12:53:02 -0800	[thread overview]
Message-ID: <20201117205304.3542997-2-prestwoj@gmail.com> (raw)
In-Reply-To: <20201117205304.3542997-1-prestwoj@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 9247 bytes --]

---
 autotests/util/ead.py   |  2 +-
 autotests/util/hwsim.py | 10 ++++-----
 autotests/util/iwd.py   | 49 +++++++++++++++++++++++------------------
 autotests/util/ofono.py |  5 +++--
 4 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/autotests/util/ead.py b/autotests/util/ead.py
index 356b0b9b..3a613bbe 100644
--- a/autotests/util/ead.py
+++ b/autotests/util/ead.py
@@ -75,7 +75,7 @@ class AdapterList(collections.Mapping):
             del self._dict[path]
 
 class EAD(iwd.AsyncOpAbstract):
-    _bus = dbus.SystemBus()
+    _bus = ctx.get_bus()
 
     _object_manager_if = None
     _adapters = None
diff --git a/autotests/util/hwsim.py b/autotests/util/hwsim.py
index 4f41952f..415bfc90 100755
--- a/autotests/util/hwsim.py
+++ b/autotests/util/hwsim.py
@@ -7,6 +7,7 @@ from abc import ABCMeta, abstractmethod
 from enum import Enum
 
 import iwd
+from config import ctx
 
 HWSIM_SERVICE =                 'net.connman.hwsim'
 HWSIM_RULE_MANAGER_INTERFACE =  'net.connman.hwsim.RuleManager'
@@ -20,9 +21,8 @@ HWSIM_AGENT_MANAGER_PATH =      '/'
 class HwsimDBusAbstract(iwd.AsyncOpAbstract):
     __metaclass__ = ABCMeta
 
-    _bus = dbus.SystemBus()
-
-    def __init__(self, object_path, properties = None):
+    def __init__(self, object_path, properties = None, namespace=ctx):
+        self._bus = namespace.get_bus()
         self._object_path = object_path
         proxy = self._bus.get_object(HWSIM_SERVICE, self._object_path)
         self._iface = dbus.Interface(proxy, self._iface_name)
@@ -256,9 +256,9 @@ class RadioList(collections.Mapping):
         return obj
 
 class Hwsim(iwd.AsyncOpAbstract):
-    _bus = dbus.SystemBus()
+    def __init__(self, namespace=ctx):
+        self._bus = namespace.get_bus()
 
-    def __init__(self):
         self._rule_manager_if = dbus.Interface(
                 self._bus.get_object(HWSIM_SERVICE, '/'),
                 HWSIM_RULE_MANAGER_INTERFACE)
diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py
index af3ecd05..bb4ecefa 100755
--- a/autotests/util/iwd.py
+++ b/autotests/util/iwd.py
@@ -122,9 +122,9 @@ class AsyncOpAbstract(object):
 class IWDDBusAbstract(AsyncOpAbstract):
     __metaclass__ = ABCMeta
 
-    _bus = dbus.SystemBus()
+    def __init__(self, object_path = None, properties = None, service=IWD_SERVICE, namespace=ctx):
+        self._bus = namespace.get_bus()
 
-    def __init__(self, object_path = None, properties = None, service=IWD_SERVICE):
         self._object_path = object_path
         proxy = self._bus.get_object(service, self._object_path)
         self._iface = dbus.Interface(proxy, self._iface_name)
@@ -190,7 +190,7 @@ class SignalAgent(dbus.service.Object):
     def __init__(self, passphrase = None):
         self._path = '/test/agent/' + str(int(round(time.time() * 1000)))
 
-        dbus.service.Object.__init__(self, dbus.SystemBus(), self._path)
+        dbus.service.Object.__init__(self, ctx.get_bus(), self._path)
 
     @property
     def path(self):
@@ -391,7 +391,7 @@ class Device(IWDDBusAbstract):
         '''
         ordered_networks = []
         for bus_obj in self._station.GetOrderedNetworks():
-            ordered_network = OrderedNetwork(bus_obj)
+            ordered_network = OrderedNetwork(bus_obj, self._bus)
             ordered_networks.append(ordered_network)
 
         if len(ordered_networks) > 0:
@@ -407,7 +407,7 @@ class Device(IWDDBusAbstract):
         IWD._wait_for_object_condition(self, condition)
 
         for bus_obj in self._station.GetOrderedNetworks():
-            ordered_network = OrderedNetwork(bus_obj)
+            ordered_network = OrderedNetwork(bus_obj, self._bus)
             ordered_networks.append(ordered_network)
 
         if len(ordered_networks) > 0:
@@ -643,9 +643,8 @@ class KnownNetwork(IWDDBusAbstract):
 class OrderedNetwork(object):
     '''Represents a network found in the scan'''
 
-    _bus = dbus.SystemBus()
-
-    def __init__(self, o_n_tuple):
+    def __init__(self, o_n_tuple, bus):
+        self._bus = bus
         self._network_object = Network(o_n_tuple[0])
         self._network_proxy = dbus.Interface(self._bus.get_object(IWD_SERVICE,
                                         o_n_tuple[0]),
@@ -707,7 +706,7 @@ agent_count = 0
 
 class PSKAgent(dbus.service.Object):
 
-    def __init__(self, passphrases=[], users=[]):
+    def __init__(self, passphrases=[], users=[], namespace=ctx):
         global agent_count
 
         if type(passphrases) != list:
@@ -720,7 +719,7 @@ class PSKAgent(dbus.service.Object):
 
         agent_count += 1
 
-        dbus.service.Object.__init__(self, dbus.SystemBus(), self._path)
+        dbus.service.Object.__init__(self, namespace.get_bus(), self._path)
 
     @property
     def path(self):
@@ -882,6 +881,7 @@ class DeviceList(collections.Mapping):
     def __init__(self, iwd):
         self._dict = {}
         self._p2p_dict = {}
+        self._namespace = iwd.namespace
 
         iwd._object_manager.connect_to_signal("InterfacesAdded",
                                                self._interfaces_added_handler)
@@ -893,9 +893,11 @@ class DeviceList(collections.Mapping):
         for path in objects:
             for interface in objects[path]:
                 if interface == IWD_DEVICE_INTERFACE:
-                    self._dict[path] = Device(path, objects[path][interface])
+                    self._dict[path] = Device(path, objects[path][interface],
+                                                namespace=self._namespace)
                 elif interface == IWD_P2P_INTERFACE:
-                    self._p2p_dict[path] = P2PDevice(path, objects[path][interface])
+                    self._p2p_dict[path] = P2PDevice(path, objects[path][interface],
+                                                namespace=self._namespace)
 
     def __getitem__(self, key):
         return self._dict.__getitem__(key)
@@ -911,9 +913,11 @@ class DeviceList(collections.Mapping):
 
     def _interfaces_added_handler(self, path, interfaces):
         if IWD_DEVICE_INTERFACE in interfaces:
-            self._dict[path] = Device(path, interfaces[IWD_DEVICE_INTERFACE])
+            self._dict[path] = Device(path, interfaces[IWD_DEVICE_INTERFACE],
+                                            namespace=self._namespace)
         elif IWD_P2P_INTERFACE in interfaces:
-            self._p2p_dict[path] = P2PDevice(path, interfaces[IWD_P2P_INTERFACE])
+            self._p2p_dict[path] = P2PDevice(path, interfaces[IWD_P2P_INTERFACE],
+                                            namespace=self._namespace)
 
     def _interfaces_removed_handler(self, path, interfaces):
         if IWD_DEVICE_INTERFACE in interfaces:
@@ -932,8 +936,6 @@ class IWD(AsyncOpAbstract):
         some tests do require starting IWD using this constructor (by passing
         start_iwd_daemon=True)
     '''
-    _bus = dbus.SystemBus()
-
     _object_manager_if = None
     _agent_manager_if = None
     _iwd_proc = None
@@ -941,19 +943,22 @@ class IWD(AsyncOpAbstract):
     _default_instance = None
     psk_agent = None
 
-    def __init__(self, start_iwd_daemon = False, iwd_config_dir = '/tmp'):
-        if start_iwd_daemon and ctx.is_process_running('iwd'):
-            raise Exception("IWD requested to start but is already running")
+    def __init__(self, start_iwd_daemon = False, iwd_config_dir = '/tmp', namespace=ctx):
+        self.namespace = namespace
+        self._bus = namespace.get_bus()
 
         if start_iwd_daemon:
-            self._iwd_proc = ctx.start_iwd(iwd_config_dir)
+            if self.namespace.is_process_running('iwd'):
+                raise Exception("IWD requested to start but is already running")
+
+            self._iwd_proc = self.namespace.start_iwd(iwd_config_dir)
 
         tries = 0
         while not self._bus.name_has_owner(IWD_SERVICE):
             if not ctx.args.gdb:
                 if tries > 200:
                     if start_iwd_daemon:
-                        ctx.stop_process(self._iwd_proc)
+                        self.namespace.stop_process(self._iwd_proc)
                         self._iwd_proc = None
                     raise TimeoutError('IWD has failed to start')
                 tries += 1
@@ -978,7 +983,7 @@ class IWD(AsyncOpAbstract):
         self._devices = None
 
         if self._iwd_proc is not None:
-            ctx.stop_process(self._iwd_proc)
+            self.namespace.stop_process(self._iwd_proc)
             self._iwd_proc = None
 
     @property
diff --git a/autotests/util/ofono.py b/autotests/util/ofono.py
index f1ed14ee..584a656a 100644
--- a/autotests/util/ofono.py
+++ b/autotests/util/ofono.py
@@ -1,12 +1,13 @@
 import dbus
 import time
 from gi.repository import GLib
+from config import ctx
 
 SIM_AUTH_IFACE = 'org.ofono.SimAuthentication'
 
 class Ofono(dbus.service.Object):
-    def __init__(self):
-        self._bus = dbus.SystemBus()
+    def __init__(self, namespace=ctx):
+        self._bus = namespace.get_bus()
 
         tries = 0
 
-- 
2.26.2

  reply	other threads:[~2020-11-17 20:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-17 20:53 [PATCH 1/4] test-runner: introduce network namespaces James Prestwood
2020-11-17 20:53 ` James Prestwood [this message]
2020-11-17 20:53 ` [PATCH 3/4] auto-t: add test_ip_connected to testutil James Prestwood
2020-11-17 20:53 ` [PATCH 4/4] auto-t: add namespaces to testAP James Prestwood
2020-11-18 17:01 ` [PATCH 1/4] test-runner: introduce network namespaces Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201117205304.3542997-2-prestwoj@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=iwd@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox