]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-network: add get_operstate() and check_operstate() helper functions
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 15 May 2019 09:25:30 +0000 (18:25 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 18 May 2019 20:27:46 +0000 (05:27 +0900)
test/test-network/systemd-networkd-tests.py

index 5c8b5db9eac5c106dfb7cc188e0094c83f39ac15..ca91367d5d863c16fbf2d7b67b8273d786fd5ce7 100755 (executable)
@@ -220,6 +220,19 @@ class Utilities():
             args += ['--any']
         subprocess.check_call(args)
 
+    def get_operstate(self, link, show_status=True, setup_state='configured'):
+        output = subprocess.check_output(['networkctl', 'status', link], universal_newlines=True).rstrip()
+        if show_status:
+            print(output)
+        for line in output.splitlines():
+            if 'State:' in line and (not setup_state or setup_state in line):
+                return line.split()[1]
+        return None
+
+    def check_operstate(self, link, expected, show_status=True, setup_state='configured'):
+        self.assertRegex(self.get_operstate(link, show_status, setup_state), expected)
+
+
 class NetworkdNetDevTests(unittest.TestCase, Utilities):
 
     links =[