All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 1/6] auto-t: modify copy_to_storage to take optional dir
  2020-09-17 21:32 [PATCH 1/6] auto-t: modify copy_to_storage to take optional dir James Prestwood
@ 2020-09-17 21:20 ` Denis Kenzior
  2020-09-17 21:32 ` [PATCH 2/6] doc: update hostapd.conf with DRIVER_WIRED James Prestwood
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2020-09-17 21:20 UTC (permalink / raw)
  To: iwd

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

Hi James,

On 9/17/20 4:32 PM, James Prestwood wrote:
> 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

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

* [PATCH 1/6] auto-t: modify copy_to_storage to take optional dir
@ 2020-09-17 21:32 James Prestwood
  2020-09-17 21:20 ` Denis Kenzior
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: James Prestwood @ 2020-09-17 21:32 UTC (permalink / raw)
  To: iwd

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

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(-)

diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py
index 67bb6e41..e812a4e4 100755
--- a/autotests/util/iwd.py
+++ b/autotests/util/iwd.py
@@ -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):
-- 
2.26.2

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

* [PATCH 2/6] doc: update hostapd.conf with DRIVER_WIRED
  2020-09-17 21:32 [PATCH 1/6] auto-t: modify copy_to_storage to take optional dir James Prestwood
  2020-09-17 21:20 ` Denis Kenzior
@ 2020-09-17 21:32 ` James Prestwood
  2020-09-17 21:32 ` [PATCH 3/6] auto-t: allow IWDDBusAbstract to work with any service James Prestwood
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2020-09-17 21:32 UTC (permalink / raw)
  To: iwd

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

---
 doc/hostapd.config | 1 +
 1 file changed, 1 insertion(+)

diff --git a/doc/hostapd.config b/doc/hostapd.config
index 2ad99b8a..91d1b4cf 100644
--- a/doc/hostapd.config
+++ b/doc/hostapd.config
@@ -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
-- 
2.26.2

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

* [PATCH 3/6] auto-t: allow IWDDBusAbstract to work with any service
  2020-09-17 21:32 [PATCH 1/6] auto-t: modify copy_to_storage to take optional dir James Prestwood
  2020-09-17 21:20 ` Denis Kenzior
  2020-09-17 21:32 ` [PATCH 2/6] doc: update hostapd.conf with DRIVER_WIRED James Prestwood
@ 2020-09-17 21:32 ` James Prestwood
  2020-09-17 21:32 ` [PATCH 4/6] auto-t: add ead.py module James Prestwood
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2020-09-17 21:32 UTC (permalink / raw)
  To: iwd

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

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(-)

diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py
index e812a4e4..ef843a95 100755
--- a/autotests/util/iwd.py
+++ b/autotests/util/iwd.py
@@ -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)
 
-- 
2.26.2

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

* [PATCH 4/6] auto-t: add ead.py module
  2020-09-17 21:32 [PATCH 1/6] auto-t: modify copy_to_storage to take optional dir James Prestwood
                   ` (2 preceding siblings ...)
  2020-09-17 21:32 ` [PATCH 3/6] auto-t: allow IWDDBusAbstract to work with any service James Prestwood
@ 2020-09-17 21:32 ` James Prestwood
  2020-09-17 21:32 ` [PATCH 5/6] test-runner: allow EAD-based autotests James Prestwood
  2020-09-17 21:32 ` [PATCH 6/6] auto-t: add EAD autotest James Prestwood
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2020-09-17 21:32 UTC (permalink / raw)
  To: iwd

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

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

diff --git a/autotests/util/ead.py b/autotests/util/ead.py
new file mode 100644
index 00000000..356b0b9b
--- /dev/null
+++ b/autotests/util/ead.py
@@ -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)
-- 
2.26.2

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

* [PATCH 5/6] test-runner: allow EAD-based autotests
  2020-09-17 21:32 [PATCH 1/6] auto-t: modify copy_to_storage to take optional dir James Prestwood
                   ` (3 preceding siblings ...)
  2020-09-17 21:32 ` [PATCH 4/6] auto-t: add ead.py module James Prestwood
@ 2020-09-17 21:32 ` James Prestwood
  2020-09-17 21:32 ` [PATCH 6/6] auto-t: add EAD autotest James Prestwood
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2020-09-17 21:32 UTC (permalink / raw)
  To: iwd

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

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(-)

diff --git a/tools/test-runner b/tools/test-runner
index a320a3f0..6443af15 100755
--- a/tools/test-runner
+++ b/tools/test-runner
@@ -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',
-- 
2.26.2

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

* [PATCH 6/6] auto-t: add EAD autotest
  2020-09-17 21:32 [PATCH 1/6] auto-t: modify copy_to_storage to take optional dir James Prestwood
                   ` (4 preceding siblings ...)
  2020-09-17 21:32 ` [PATCH 5/6] test-runner: allow EAD-based autotests James Prestwood
@ 2020-09-17 21:32 ` James Prestwood
  5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2020-09-17 21:32 UTC (permalink / raw)
  To: iwd

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

---
 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

diff --git a/autotests/testEAD/connection_test.py b/autotests/testEAD/connection_test.py
new file mode 100644
index 00000000..c51d7237
--- /dev/null
+++ b/autotests/testEAD/connection_test.py
@@ -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)
diff --git a/autotests/testEAD/default.8021x b/autotests/testEAD/default.8021x
new file mode 100644
index 00000000..55eb431d
--- /dev/null
+++ b/autotests/testEAD/default.8021x
@@ -0,0 +1,7 @@
+[Security]
+EAP-Method=MSCHAPV2
+EAP-Identity=domain\\User
+EAP-Password=Password
+
+[Settings]
+AutoConnect=false
diff --git a/autotests/testEAD/hw.conf b/autotests/testEAD/hw.conf
new file mode 100644
index 00000000..dee31f9e
--- /dev/null
+++ b/autotests/testEAD/hw.conf
@@ -0,0 +1,6 @@
+[SETUP]
+num_radios=0
+start_iwd=0
+
+[HOSTAPD]
+radius_server=wired.conf
diff --git a/autotests/testEAD/wired.conf b/autotests/testEAD/wired.conf
new file mode 100644
index 00000000..9e6ef638
--- /dev/null
+++ b/autotests/testEAD/wired.conf
@@ -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
-- 
2.26.2

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

end of thread, other threads:[~2020-09-17 21:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 21:32 [PATCH 1/6] auto-t: modify copy_to_storage to take optional dir James Prestwood
2020-09-17 21:20 ` Denis Kenzior
2020-09-17 21:32 ` [PATCH 2/6] doc: update hostapd.conf with DRIVER_WIRED James Prestwood
2020-09-17 21:32 ` [PATCH 3/6] auto-t: allow IWDDBusAbstract to work with any service James Prestwood
2020-09-17 21:32 ` [PATCH 4/6] auto-t: add ead.py module James Prestwood
2020-09-17 21:32 ` [PATCH 5/6] test-runner: allow EAD-based autotests James Prestwood
2020-09-17 21:32 ` [PATCH 6/6] auto-t: add EAD autotest James Prestwood

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.