networkd-test.py: fix interface state checker
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 22 Nov 2024 18:32:34 +0000 (03:32 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 23 Nov 2024 08:33:43 +0000 (17:33 +0900)
After 259125d53d98541623b69e83000b5543f2352f5e, network interfaces
declared by .netdev files are created after systemd-networkd sends READY
notification. So, even when networkd is started, the netdevs may not
be created yet, and 'ip' command may fail. Let's also check the return
code of the command.

This also
- drops never worked stdout checks,
- makes the test fail if the interface is not created within the timeout.

test/networkd-test.py

index 929290eab77def67ca98e78cb4bcecc9eaff34c5..7c201c484cb238487bf658ea0caa10170878bbd2 100755 (executable)
@@ -960,10 +960,13 @@ exec $(systemctl cat systemd-networkd.service | sed -n '/^ExecStart=/ {{ s/^.*=/
 
         # wait until devices got created
         for _ in range(50):
-            out = subprocess.check_output(['ip', 'a', 'show', 'dev', self.if_router])
-            if b'state UP' in out and b'scope global' in out:
+            if subprocess.run(['ip', 'link', 'show', 'dev', self.if_router],
+                              stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0:
                 break
             time.sleep(0.1)
+        else:
+            subprocess.call(['ip', 'link', 'show', 'dev', self.if_router])
+            self.fail('Timed out waiting for {ifr} created.'.format(ifr=self.if_router))
 
     def shutdown_iface(self):
         '''Remove test interface and stop DHCP server'''