From 2be0b6fc5ebeb07211303d1e46d6180a96dfcae0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 15 May 2019 18:25:30 +0900 Subject: [PATCH] test-network: add get_operstate() and check_operstate() helper functions --- test/test-network/systemd-networkd-tests.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 5c8b5db9ea..ca91367d5d 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -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 =[