X Tutup
Skip to content

Commit a1a42fd

Browse files
authored
Merge pull request systemd#22277 from yuwata/test-network-activation-policy
test-network: fixes for test_activation_policy
2 parents e0c694c + 073ad7e commit a1a42fd

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

test/test-network/systemd-networkd-tests.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,21 @@ def check_link_exists(self, link):
594594
def check_link_attr(self, *args):
595595
self.assertEqual(read_link_attr(*args[:-1]), args[-1]);
596596

597+
def wait_activated(self, link, state='down', timeout=20, fail_assert=True):
598+
# wait for the interface is activated.
599+
invocation_id = check_output('systemctl show systemd-networkd -p InvocationID --value')
600+
needle = f'{link}: Bringing link {state}'
601+
flag = state.upper()
602+
for iteration in range(timeout+1):
603+
output = check_output('journalctl _SYSTEMD_INVOCATION_ID=' + invocation_id)
604+
if needle in output and flag in check_output(f'ip link show {link}'):
605+
return True
606+
if iteration < timeout:
607+
time.sleep(1)
608+
if fail_assert:
609+
self.fail(f'Timed out waiting for {link} activated.')
610+
return False
611+
597612
def wait_operstate(self, link, operstate='degraded', setup_state='configured', setup_timeout=5, fail_assert=True):
598613
"""Wait for the link to reach the specified operstate and/or setup state.
599614
@@ -3053,21 +3068,20 @@ def test_bind_carrier(self):
30533068
self.wait_operstate('test1', 'routable')
30543069

30553070
def _test_activation_policy(self, test):
3056-
self.setUp()
30573071
conffile = '25-activation-policy.network'
30583072
if test:
30593073
conffile = f'{conffile}.d/{test}.conf'
30603074
copy_unit_to_networkd_unit_path('11-dummy.netdev', conffile, dropins=False)
30613075
start_networkd()
30623076

30633077
always = test.startswith('always')
3064-
if test == 'manual':
3065-
initial_up = 'UP' in check_output('ip link show test1')
3066-
else:
3067-
initial_up = not test.endswith('down') # note: default is up
3078+
initial_up = test != 'manual' and not test.endswith('down') # note: default is up
30683079
expect_up = initial_up
30693080
next_up = not expect_up
30703081

3082+
if test.endswith('down'):
3083+
self.wait_activated('test1')
3084+
30713085
for iteration in range(4):
30723086
with self.subTest(iteration=iteration, expect_up=expect_up):
30733087
operstate = 'routable' if expect_up else 'off'
@@ -3087,16 +3101,17 @@ def _test_activation_policy(self, test):
30873101
check_output('ip link set dev test1 down')
30883102
expect_up = initial_up if always else next_up
30893103
next_up = not next_up
3090-
3091-
self.tearDown()
3104+
if always:
3105+
time.sleep(1)
30923106

30933107
def test_activation_policy(self):
30943108
for test in ['up', 'always-up', 'manual', 'always-down', 'down', '']:
30953109
with self.subTest(test=test):
3110+
self.setUp()
30963111
self._test_activation_policy(test)
3112+
self.tearDown()
30973113

30983114
def _test_activation_policy_required_for_online(self, policy, required):
3099-
self.setUp()
31003115
conffile = '25-activation-policy.network'
31013116
units = ['11-dummy.netdev', '12-dummy.netdev', '12-dummy.network', conffile]
31023117
if policy:
@@ -3106,6 +3121,9 @@ def _test_activation_policy_required_for_online(self, policy, required):
31063121
copy_unit_to_networkd_unit_path(*units, dropins=False)
31073122
start_networkd()
31083123

3124+
if policy.endswith('down'):
3125+
self.wait_activated('test1')
3126+
31093127
if policy.endswith('down') or policy == 'manual':
31103128
self.wait_operstate('test1', 'off', setup_state='configuring')
31113129
else:
@@ -3131,13 +3149,13 @@ def _test_activation_policy_required_for_online(self, policy, required):
31313149
yesno = 'yes' if expected else 'no'
31323150
self.assertRegex(output, f'Required For Online: {yesno}')
31333151

3134-
self.tearDown()
3135-
31363152
def test_activation_policy_required_for_online(self):
31373153
for policy in ['up', 'always-up', 'manual', 'always-down', 'down', 'bound', '']:
31383154
for required in ['yes', 'no', '']:
31393155
with self.subTest(policy=policy, required=required):
3156+
self.setUp()
31403157
self._test_activation_policy_required_for_online(policy, required)
3158+
self.tearDown()
31413159

31423160
def test_domain(self):
31433161
copy_unit_to_networkd_unit_path('12-dummy.netdev', '24-search-domain.network')

0 commit comments

Comments
 (0)
X Tutup