X Tutup
Skip to content

Commit 61764fe

Browse files
author
Dan Streetman
committed
test: add test to verify RequiredForOnline= setting with ActivationPolicy=
Add test to verify that the RequiredForOnline= value is correct based on the configuration of ActivationPolicy=
1 parent 003015a commit 61764fe

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Link]
2+
ActivationPolicy=bound
3+
4+
[Network]
5+
BindCarrier=dummy98
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Link]
2+
RequiredForOnline=no
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Link]
2+
RequiredForOnline=yes

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
17931793
units = [
17941794
'11-dummy.netdev',
17951795
'12-dummy.netdev',
1796+
'12-dummy.network',
17961797
'23-active-slave.network',
17971798
'24-keep-configuration-static.network',
17981799
'24-search-domain.network',
@@ -2801,6 +2802,50 @@ def test_activation_policy(self):
28012802
with self.subTest(test=test):
28022803
self._test_activation_policy(test)
28032804

2805+
def _test_activation_policy_required_for_online(self, policy, required):
2806+
self.setUp()
2807+
conffile = '25-activation-policy.network'
2808+
units = ['11-dummy.netdev', '12-dummy.netdev', '12-dummy.network', conffile]
2809+
if policy:
2810+
units += [f'{conffile}.d/{policy}.conf']
2811+
if required:
2812+
units += [f'{conffile}.d/required-{required}.conf']
2813+
copy_unit_to_networkd_unit_path(*units, dropins=False)
2814+
start_networkd()
2815+
2816+
if policy.endswith('down') or policy == 'manual':
2817+
self.wait_operstate('test1', 'off', setup_state='configuring')
2818+
else:
2819+
self.wait_online(['test1'])
2820+
2821+
if policy == 'always-down':
2822+
# if always-down, required for online is forced to no
2823+
expected = False
2824+
elif required:
2825+
# otherwise if required for online is specified, it should match that
2826+
expected = required == 'yes'
2827+
elif policy:
2828+
# otherwise if only policy specified, required for online defaults to
2829+
# true if policy is up, always-up, or bound
2830+
expected = policy.endswith('up') or policy == 'bound'
2831+
else:
2832+
# default is true, if neither are specified
2833+
expected = True
2834+
2835+
output = check_output(*networkctl_cmd, '-n', '0', 'status', 'test1', env=env)
2836+
print(output)
2837+
2838+
yesno = 'yes' if expected else 'no'
2839+
self.assertRegex(output, f'Required For Online: {yesno}')
2840+
2841+
self.tearDown()
2842+
2843+
def test_activation_policy_required_for_online(self):
2844+
for policy in ['up', 'always-up', 'manual', 'always-down', 'down', 'bound', '']:
2845+
for required in ['yes', 'no', '']:
2846+
with self.subTest(policy=policy, required=required):
2847+
self._test_activation_policy_required_for_online(policy, required)
2848+
28042849
def test_domain(self):
28052850
copy_unit_to_networkd_unit_path('12-dummy.netdev', '24-search-domain.network')
28062851
start_networkd()

0 commit comments

Comments
 (0)
X Tutup