test-network: add tests for --any option of wait-online
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 1 Apr 2019 01:28:32 +0000 (10:28 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 1 Apr 2019 18:38:22 +0000 (03:38 +0900)
test/test-network/conf/11-dummy.network [new file with mode: 0644]
test/test-network/conf/25-bridge.network [new file with mode: 0644]
test/test-network/systemd-networkd-tests.py

diff --git a/test/test-network/conf/11-dummy.network b/test/test-network/conf/11-dummy.network
new file mode 100644 (file)
index 0000000..b117028
--- /dev/null
@@ -0,0 +1,5 @@
+[Match]
+Name=test1
+
+[Network]
+IPv6AcceptRA=no
diff --git a/test/test-network/conf/25-bridge.network b/test/test-network/conf/25-bridge.network
new file mode 100644 (file)
index 0000000..d2f3463
--- /dev/null
@@ -0,0 +1,5 @@
+[Match]
+Name=bridge99
+
+[Network]
+IPv6AcceptRA=no
index 34cf388..bd79ff7 100755 (executable)
@@ -185,8 +185,10 @@ class Utilities():
         if sleep_sec > 0:
             time.sleep(sleep_sec)
 
-    def wait_online(self, links_with_operstate, timeout='20s'):
+    def wait_online(self, links_with_operstate, timeout='20s', bool_any=False):
         args = [wait_online_bin, f'--timeout={timeout}'] + [f'--interface={link}' for link in links_with_operstate]
+        if bool_any:
+            args += ['--any']
         subprocess.check_call(args)
 
 class NetworkdNetDevTests(unittest.TestCase, Utilities):
@@ -243,6 +245,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
     units = [
         '10-dropin-test.netdev',
         '11-dummy.netdev',
+        '11-dummy.network',
         '12-dummy.netdev',
         '21-macvlan.netdev',
         '21-macvtap.netdev',
@@ -253,6 +256,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
         '25-bond.netdev',
         '25-bond-balanced-tlb.netdev',
         '25-bridge.netdev',
+        '25-bridge.network',
         '25-erspan-tunnel-local-any.netdev',
         '25-erspan-tunnel.netdev',
         '25-geneve.netdev',
@@ -352,6 +356,22 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
         else:
             print('ethtool does not support driver field at least for dummy interfaces, skipping test for Driver field of networkctl.')
 
+    def test_wait_online_any(self):
+        self.copy_unit_to_networkd_unit_path('25-bridge.netdev', '25-bridge.network', '11-dummy.netdev', '11-dummy.network')
+        self.start_networkd(0)
+
+        self.wait_online(['bridge99', 'test1:degraded'], bool_any=True)
+        self.assertTrue(self.link_exits('bridge99'))
+        self.assertTrue(self.link_exits('test1'))
+
+        output = subprocess.check_output(['networkctl', 'status', 'bridge99']).rstrip().decode('utf-8')
+        print(output)
+        self.assertRegex(output, 'State: (?:off|no-carrier) \(configuring\)')
+
+        output = subprocess.check_output(['networkctl', 'status', 'test1']).rstrip().decode('utf-8')
+        print(output)
+        self.assertRegex(output, 'State: degraded \(configured\)')
+
     def test_bridge(self):
         self.copy_unit_to_networkd_unit_path('25-bridge.netdev')
         self.start_networkd()