From acc06d8a68611cfc53c7eea5fbcd03f1074cb2a3 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 11 May 2024 01:58:06 +0900 Subject: [PATCH] test-network: make link_exists() take multiple arguments This also improves performance of test_delete_links(). --- test/test-network/systemd-networkd-tests.py | 32 ++++++++------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index da74eabce3d..d371ff193ee 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -555,8 +555,11 @@ def clear_system_units(): check_output('systemctl daemon-reload') check_output('systemctl restart systemd-udevd.service') -def link_exists(link): - return call_quiet(f'ip link show {link}') == 0 +def link_exists(*links): + for link in links: + if call_quiet(f'ip link show {link}') != 0: + return False + return True def link_resolve(link): return check_output(f'ip link show {link}').split(':')[1].strip() @@ -989,11 +992,11 @@ def tearDownModule(): class Utilities(): # pylint: disable=no-member - def check_link_exists(self, link, expected=True): + def check_link_exists(self, *link, expected=True): if expected: - self.assertTrue(link_exists(link)) + self.assertTrue(link_exists(*link)) else: - self.assertFalse(link_exists(link)) + self.assertFalse(link_exists(*link)) def check_link_attr(self, *args): self.assertEqual(read_link_attr(*args[:-1]), args[-1]) @@ -1015,17 +1018,11 @@ class Utilities(): self.assertEqual(read_ipv6_neigh_sysctl_attr(link, attribute), expected) def wait_links(self, *links, timeout=20, fail_assert=True): - def links_exist(*links): - for link in links: - if not link_exists(link): - return False - return True - for iteration in range(timeout + 1): if iteration > 0: time.sleep(1) - if links_exist(*links): + if link_exists(*links): return True if fail_assert: self.fail('Timed out waiting for all links to be created: ' + ', '.join(list(links))) @@ -1422,16 +1419,11 @@ class NetworkctlTests(unittest.TestCase, Utilities): self.assertIn('Network File: n/a', output) def test_delete_links(self): - copy_network_unit('11-dummy.netdev', '11-dummy.network', - '25-veth.netdev', '26-netdev-link-local-addressing-yes.network') + copy_network_unit('11-dummy.netdev', '25-veth.netdev') start_networkd() - - self.wait_online('test1:degraded', 'veth99:degraded', 'veth-peer:degraded') - + self.wait_links('test1', 'veth99', 'veth-peer') networkctl('delete', 'test1', 'veth99') - self.check_link_exists('test1', expected=False) - self.check_link_exists('veth99', expected=False) - self.check_link_exists('veth-peer', expected=False) + self.check_link_exists('test1', 'veth99', 'veth-peer', expected=False) def test_label(self): networkctl('label') -- 2.47.3