Skip to contentSkip to conversation

auto-t: modify copy_to_storage to take optional dir

PATCH In review James Prestwood 2 participants 7 messages Sep 17, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 auto-t: modify copy_to_storage to take optional dir

This is to prepare for testing EAD, and in this case we need to copy the 8021x config to /var/lib/ead instead of IWD's config dir.

---
 autotests/util/iwd.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
autotests/util/iwd.py +2 -2
index 67bb6e41..e812a4e4 100755
@@ -921,12 +921,12 @@ class IWD(AsyncOpAbstract):
         fo.close()
 
     @staticmethod
-    def copy_to_storage(source):
+    def copy_to_storage(source, storage_dir=IWD_STORAGE_DIR):
         import shutil
 
         assert not os.path.isabs(source)
 
-        shutil.copy(source, IWD_STORAGE_DIR)
+        shutil.copy(source, storage_dir)
 
     @staticmethod
     def copy_to_hotspot(source):
Signature · 1 line
2.26.2
#1 lore raw

Hi James,

Quoted 7 lines · James Prestwood

This is to prepare for testing EAD, and in this case we need to copy the 8021x config to /var/lib/ead instead of IWD's config dir.

---
  autotests/util/iwd.py | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

All applied, thanks.

Regards,
-Denis

#2 lore raw

PATCH 2/6 doc: update hostapd.conf with DRIVER_WIRED

In reply to James Prestwood
---
 doc/hostapd.config | 1 +
 1 file changed, 1 insertion(+)
doc/hostapd.config +1 -0
index 2ad99b8a..91d1b4cf 100644
@@ -1,6 +1,7 @@
 CONFIG_DRIVER_HOSTAP=y
 CONFIG_DRIVER_NL80211=y
 CONFIG_DRIVER_NONE=y
+CONFIG_DRIVER_WIRED=y
 CONFIG_LIBNL32=y
 CONFIG_IAPP=y
 CONFIG_RSN_PREAUTH=y
Signature · 1 line
2.26.2
#3 lore raw

PATCH 3/6 auto-t: allow IWDDBusAbstract to work with any service

In reply to James Prestwood

This is somewhat of a hack, but the IWDDBusAbstract is a very convenient abstraction to DBus objects. The only piece that restricts it to IWD is the hardcoded IWD_SERVICE. Instead we can pass in a keyword argument which defaults to IWD_SERVICE. That way other modules (like EAD) can utilize this abstraction with their own service simply by changing that service argument.

---
 autotests/util/iwd.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
autotests/util/iwd.py +2 -2
index e812a4e4..ef843a95 100755
@@ -120,9 +120,9 @@ class IWDDBusAbstract(AsyncOpAbstract):
 
     _bus = dbus.SystemBus()
 
-    def __init__(self, object_path = None, properties = None):
+    def __init__(self, object_path = None, properties = None, service=IWD_SERVICE):
         self._object_path = object_path
-        proxy = self._bus.get_object(IWD_SERVICE, self._object_path)
+        proxy = self._bus.get_object(service, self._object_path)
         self._iface = dbus.Interface(proxy, self._iface_name)
         self._prop_proxy = dbus.Interface(proxy, DBUS_PROPERTIES)
 
Signature · 1 line
2.26.2
#4 lore raw

PATCH 4/6 auto-t: add ead.py module

In reply to James Prestwood

This module is essentially a heavily stripped down version of iwd.py to work with EAD. Class names were changed to match EAD but basically the EAD, Adapter, and AdapterList classes map 1:1 to IWD, Device, and DeviceList.

---
 autotests/util/ead.py | 141 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 141 insertions(+)
 create mode 100644 autotests/util/ead.py
autotests/util/ead.py new file +141 -0
new file mode 100644
index 00000000..356b0b9b
@@ -0,0 +1,141 @@
+#!/usr/bin/python3
+
+from gi.repository import GLib
+import dbus
+import time
+import collections
+
+import iwd
+from config import ctx
+
+EAD_SERVICE =                   'net.connman.ead'
+EAD_ADAPTER_INTERFACE =         'net.connman.ead.Adapter'
+DBUS_OBJECT_MANAGER =           'org.freedesktop.DBus.ObjectManager'
+DBUS_PROPERTIES =               'org.freedesktop.DBus.Properties'
+EAD_TOP_LEVEL_PATH =            '/'
+
+class Adapter(iwd.IWDDBusAbstract):
+    _iface_name = "net.connman.ead.Adapter"
+
+    @property
+    def name(self):
+        return self._properties['Name']
+
+    @property
+    def address(self):
+        return self._properties['Address']
+
+    @property
+    def active(self):
+        return self._properties['Active']
+
+    @property
+    def connected(self):
+        return self._properties['Connected']
+
+    @property
+    def authenticated(self):
+        return self._properties['Authenticated']
+
+
+class AdapterList(collections.Mapping):
+    def __init__(self, ead):
+        self._dict = {}
+
+        ead._object_manager.connect_to_signal("InterfacesAdded",
+                                               self._interfaces_added_handler)
+        ead._object_manager.connect_to_signal("InterfacesRemoved",
+                                               self._interfaces_removed_handler)
+
+        objects = ead._object_manager.GetManagedObjects()
+
+        for path in objects:
+            for interface in objects[path]:
+                if interface == EAD_ADAPTER_INTERFACE:
+                    self._dict[path] = Adapter(path, objects[path][interface], service=EAD_SERVICE)
+
+    def __getitem__(self, key):
+        return self._dict.__getitem__(key)
+
+    def __iter__(self):
+        return self._dict.__iter__()
+
+    def __len__(self):
+        return self._dict.__len__()
+
+    def __delitem__(self, key):
+        self._dict.pop(key).remove()
+
+    def _interfaces_added_handler(self, path, interfaces):
+        if EAD_ADAPTER_INTERFACE in interfaces:
+            self._dict[path] = Adapter(path, interfaces[EAD_ADAPTER_INTERFACE], service=EAD_SERVICE)
+
+    def _interfaces_removed_handler(self, path, interfaces):
+        if EAD_ADAPTER_INTERFACE in interfaces:
+            del self._dict[path]
+
+class EAD(iwd.AsyncOpAbstract):
+    _bus = dbus.SystemBus()
+
+    _object_manager_if = None
+    _adapters = None
+
+    def __init__(self):
+        tries = 0
+        while not self._bus.name_has_owner(EAD_SERVICE):
+            if tries > 200:
+                raise TimeoutError('IWD has failed to start')
+            tries += 1
+            time.sleep(0.1)
+
+        self._adapters = AdapterList(self)
+
+    @property
+    def _object_manager(self):
+        if self._object_manager_if is None:
+            self._object_manager_if = \
+                       dbus.Interface(self._bus.get_object(EAD_SERVICE,
+                                                           EAD_TOP_LEVEL_PATH),
+                                      DBUS_OBJECT_MANAGER)
+        return self._object_manager_if
+
+    def list_adapters(self, wait_to_appear = 0, max_wait = 50):
+        if not wait_to_appear:
+            return list(self._adapters.values())
+
+        self._wait_timed_out = False
+        def wait_timeout_cb():
+            self._wait_timed_out = True
+            return False
+
+        try:
+            timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb)
+            context = ctx.mainloop.get_context()
+            while len(self._adapters) < wait_to_appear:
+                context.iteration(may_block=True)
+                if self._wait_timed_out:
+                    raise TimeoutError('IWD has no associated devices')
+        finally:
+            if not self._wait_timed_out:
+                GLib.source_remove(timeout)
+
+        return list(self._adapters.values())
+
+    def wait_for_object_condition(self, obj, condition_str, max_wait = 50):
+        self._wait_timed_out = False
+        def wait_timeout_cb():
+            self._wait_timed_out = True
+            return False
+
+        try:
+            timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb)
+            context = ctx.mainloop.get_context()
+            while not eval(condition_str):
+                context.iteration(may_block=True)
+                if self._wait_timed_out and ctx.args.gdb == None:
+                    raise TimeoutError('[' + condition_str + ']'\
+                                       ' condition was not met in '\
+                                       + str(max_wait) + ' sec')
+        finally:
+            if not self._wait_timed_out:
+                GLib.source_remove(timeout)
Signature · 1 line
2.26.2
#5 lore raw

PATCH 5/6 test-runner: allow EAD-based autotests

In reply to James Prestwood

The virtual environment changed slightly adding two network adatpers which are connected to the same backend so they can communicate with each other (basically connected to a switch). The hostapd command line was modified to allow no interfaces to be passed in which lets us create zero radios but still specify a radius_config file.

---
 tools/test-runner | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
tools/test-runner +17 -2
index a320a3f0..6443af15 100755
@@ -113,6 +113,7 @@ mount_table = [
 	MountInfo('tmpfs', '/dev/shm', 'mode=1777', MS_NOSUID|MS_NODEV|MS_STRICTATIME),
 	MountInfo('tmpfs', '/run', 'mode=0755', MS_NOSUID|MS_NODEV|MS_STRICTATIME),
 	MountInfo('tmpfs', '/var/lib/iwd', 'mode=0755', 0),
+	MountInfo('tmpfs', '/var/lib/ead', 'mode=0755', 0),
 	MountInfo('tmpfs', '/tmp', '', 0),
 	MountInfo('tmpfs', '/usr/share/dbus-1', 'mode=0755', MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME),
 	MountInfo('debugfs', '/sys/kernel/debug', '', 0)
@@ -377,6 +378,9 @@ class Hostapd:
 
 		print("Initializing hostapd instances")
 
+		ctx.start_process(['ip', 'link', 'set', 'eth0', 'up'], wait=True)
+		ctx.start_process(['ip', 'link', 'set', 'eth1', 'up'], wait=True)
+
 		self.global_ctrl_iface = '/var/run/hostapd/ctrl'
 
 		self.instances = [HostapdInstance(c, r) for c, r in zip(configs, radios)]
@@ -384,7 +388,10 @@ class Hostapd:
 		ifaces = [rad.interface.name for rad in radios]
 		ifaces = ','.join(ifaces)
 
-		args = ['hostapd', '-i', ifaces, '-g', self.global_ctrl_iface]
+		args = ['hostapd', '-g', self.global_ctrl_iface]
+
+		if ifaces:
+			args.extend(['-i', ifaces])
 
 		#
 		# Config files should already be present in /tmp. This appends
@@ -1034,6 +1041,7 @@ def run_tests():
 	os.environ['PATH'] = '%s/src' % args.testhome
 	os.environ['PATH'] += ':%s/tools' % args.testhome
 	os.environ['PATH'] += ':%s/client' % args.testhome
+	os.environ['PATH'] += ':%s/wired' % args.testhome
 	os.environ['PATH'] += ':' + args.path
 
 	sys.path.append(args.testhome + '/autotests/util')
@@ -1219,7 +1227,7 @@ class Main:
 			'-machine', 'type=q35,accel=kvm:tcg',
 			'-nodefaults', '-no-user-config', '-monitor', 'none',
 			'-display', 'none', '-m', '192M', '-nographic', '-vga',
-			'none', '-net', 'none', '-no-acpi', '-no-hpet',
+			'none', '-no-acpi', '-no-hpet',
 			'-no-reboot', '-fsdev',
 			'local,id=fsdev-root,path=/,readonly,security_model=none,multidevs=remap',
 			'-device',
@@ -1238,6 +1246,13 @@ class Main:
 			'-cpu', 'host'
 		]
 
+		# Add two ethernet devices for testing EAD
+		qemu_cmdline.extend([
+				'-net', 'nic,model=virtio',
+				'-net', 'nic,model=virtio',
+				'-net', 'user'
+		])
+
 		if usb_adapters:
 			for bus, addr in [s.split(',') for s in usb_adapters]:
 				qemu_cmdline.extend(['-usb',
Signature · 1 line
2.26.2
#6 lore raw

PATCH 6/6 auto-t: add EAD autotest

In reply to James Prestwood
---
 autotests/testEAD/connection_test.py | 35 ++++++++++++++++++++++++++++
 autotests/testEAD/default.8021x      |  7 ++++++
 autotests/testEAD/hw.conf            |  6 +++++
 autotests/testEAD/wired.conf         | 17 ++++++++++++++
 4 files changed, 65 insertions(+)
 create mode 100644 autotests/testEAD/connection_test.py
 create mode 100644 autotests/testEAD/default.8021x
 create mode 100644 autotests/testEAD/hw.conf
 create mode 100644 autotests/testEAD/wired.conf
autotests/testEAD/connection_test.py new file +35 -0
new file mode 100644
index 00000000..c51d7237
@@ -0,0 +1,35 @@
+#!/usr/bin/python3
+
+import unittest
+import sys
+
+sys.path.append('../util')
+from iwd import IWD
+from config import ctx
+
+from ead import EAD
+
+class Test(unittest.TestCase):
+    def test_connection_success(self):
+        ctx.start_process(['ead', '-i', 'eth1', '-d'])
+
+        ead = EAD()
+
+        adapter = ead.list_adapters(1)[0]
+
+        condition = 'obj.connected == True'
+        ead.wait_for_object_condition(adapter, condition)
+
+        condition = 'obj.authenticated == True'
+        ead.wait_for_object_condition(adapter, condition)
+
+    @classmethod
+    def setUpClass(cls):
+        IWD.copy_to_storage('default.8021x', storage_dir='/var/lib/ead')
+
+    @classmethod
+    def tearDownClass(cls):
+        IWD.clear_storage()
+
+if __name__ == '__main__':
+    unittest.main(exit=True)
autotests/testEAD/default.8021x new file +7 -0
new file mode 100644
index 00000000..55eb431d
@@ -0,0 +1,7 @@
+[Security]
+EAP-Method=MSCHAPV2
+EAP-Identity=domain\\User
+EAP-Password=Password
+
+[Settings]
+AutoConnect=false
autotests/testEAD/hw.conf new file +6 -0
new file mode 100644
index 00000000..dee31f9e
@@ -0,0 +1,6 @@
+[SETUP]
+num_radios=0
+start_iwd=0
+
+[HOSTAPD]
+radius_server=wired.conf
autotests/testEAD/wired.conf new file +17 -0
new file mode 100644
index 00000000..9e6ef638
@@ -0,0 +1,17 @@
+interface=eth0
+driver=wired
+logger_stdout=-1
+logger_stdout_level=1
+
+ieee8021x=1
+eap_reauth_period=3600
+
+use_pae_group_addr=1
+
+nas_identifier=ap.example.com
+
+radius_server_clients=/tmp/certs/radius-clients.text
+radius_server_auth_port=1812
+
+eap_user_file=/tmp/secrets/eap-user-mschapv2.text
+eap_server=1
Signature · 1 line
2.26.2