]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-network: add wait_online() helper function
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 21 Mar 2019 20:06:09 +0000 (05:06 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 29 Mar 2019 17:27:16 +0000 (02:27 +0900)
test/test-network/systemd-networkd-tests.py

index 1621d400b14d39250ed1b160f4ff87ad382d8605..610f08847753e339b7e58e5e6abb5aed79c78131 100755 (executable)
@@ -22,6 +22,8 @@ network_sysctl_ipv4_path='/proc/sys/net/ipv4/conf'
 dnsmasq_pid_file='/run/networkd-ci/test-test-dnsmasq.pid'
 dnsmasq_log_file='/run/networkd-ci/test-dnsmasq-log-file'
 
+wait_online_bin='/usr/lib/systemd/systemd-networkd-wait-online'
+
 def is_module_available(module_name):
     lsmod_output = subprocess.check_output('lsmod', universal_newlines=True)
     module_re = re.compile(r'^{0}\b'.format(re.escape(module_name)), re.MULTILINE)
@@ -173,7 +175,7 @@ class Utilities():
         if os.path.exists(dnsmasq_log_file):
             os.remove(dnsmasq_log_file)
 
-    def start_networkd(self, remove_state_files=True):
+    def start_networkd(self, sleep_sec=5, remove_state_files=True):
         if (remove_state_files and
             os.path.exists(os.path.join(networkd_runtime_directory, 'state'))):
             subprocess.check_call('systemctl stop systemd-networkd', shell=True)
@@ -181,7 +183,12 @@ class Utilities():
             subprocess.check_call('systemctl start systemd-networkd', shell=True)
         else:
             subprocess.check_call('systemctl restart systemd-networkd', shell=True)
-        time.sleep(5)
+        if sleep_sec > 0:
+            time.sleep(sleep_sec)
+
+    def wait_online(self, links_with_operstate, timeout='20s'):
+        args = [wait_online_bin, f' --timeout={timeout}'] + [f'--interface={link}' for link in links_with_operstate]
+        subprocess.check_call(args)
 
 class NetworkdNetDevTests(unittest.TestCase, Utilities):
 
@@ -972,7 +979,7 @@ class NetworkdNetWorkTests(unittest.TestCase, Utilities):
 
         for trial in range(3):
             # Remove state files only first time
-            self.start_networkd(trial == 0)
+            self.start_networkd(remove_state_files=(trial == 0))
 
             self.assertTrue(self.link_exits('test1'))
             self.assertTrue(self.link_exits('dummy98'))