Skip to content

Commit

Permalink
wait-online: new tests for routable waiting
Browse files Browse the repository at this point in the history
  • Loading branch information
slyon committed Jun 24, 2024
1 parent eafdacd commit 1f5c78d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
75 changes: 74 additions & 1 deletion tests/generator/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ def test_systemd_generator(self):
id: 43
link-local: []
addresses: [10.0.0.2/24]
eth99.44:
link: eth99
id: 44
link-local: [ipv6]
bridges:
br0:
dhcp4: true
Expand Down Expand Up @@ -186,7 +190,8 @@ def test_systemd_generator(self):
[Service]
ExecStart=
ExecStart=/lib/systemd/systemd-networkd-wait-online -i eth99.43:degraded -i br0:degraded -i lo:carrier -i eth99.42:carrier\n''')
ExecStart=/lib/systemd/systemd-networkd-wait-online -i lo:carrier -i eth99.42:carrier -i eth99.44:degraded
ExecStart=/lib/systemd/systemd-networkd-wait-online --any -o routable -i eth99.43 -i br0\n''')

# should be a no-op the second time while the stamp exists
out = subprocess.check_output([generator, '--root-dir', self.workdir.name, outdir, outdir, outdir],
Expand Down Expand Up @@ -233,6 +238,74 @@ def test_systemd_generator_all_optional(self):
with open(override, 'r') as f:
self.assertEqual(f.read(), '''[Unit]
ConditionPathIsSymbolicLink=/run/systemd/generator/network-online.target.wants/systemd-networkd-wait-online.service
''')

def test_systemd_wait_online_only_non_routable(self):
conf = os.path.join(self.confdir, 'a.yaml')
os.makedirs(os.path.dirname(conf))
with open(conf, 'w') as f:
f.write('''network:
version: 2
ethernets:
nomatchfound: # non-optional, but cannot be matched to a physical interface on the test runner
dhcp4: true
vlans:
eth99.44:
link: nomatchfound
id: 44
link-local: [ipv6]''')
outdir = os.path.join(self.workdir.name, 'out')
os.mkdir(outdir)

generator = os.path.join(self.workdir.name, 'systemd', 'system-generators', 'netplan')
os.makedirs(os.path.dirname(generator))
os.symlink(exe_generate, generator)

service_dir = os.path.join(self.workdir.name, 'run', 'systemd', 'system')
override = os.path.join(service_dir, 'systemd-networkd-wait-online.service.d', '10-netplan.conf')
subprocess.check_call([generator, '--root-dir', self.workdir.name, outdir, outdir, outdir])
self.assertTrue(os.path.isfile(override))
with open(override, 'r') as f:
self.assertEqual(f.read(), '''[Unit]
ConditionPathIsSymbolicLink=/run/systemd/generator/network-online.target.wants/systemd-networkd-wait-online.service
[Service]
ExecStart=
ExecStart=/lib/systemd/systemd-networkd-wait-online -i eth99.44:degraded
''')

def test_systemd_wait_online_only_routable(self):
conf = os.path.join(self.confdir, 'a.yaml')
os.makedirs(os.path.dirname(conf))
with open(conf, 'w') as f:
f.write('''network:
version: 2
bridges:
br0:
dhcp4: true''')
outdir = os.path.join(self.workdir.name, 'out')
os.mkdir(outdir)

generator = os.path.join(self.workdir.name, 'systemd', 'system-generators', 'netplan')
os.makedirs(os.path.dirname(generator))
os.symlink(exe_generate, generator)

subprocess.check_call([generator, '--root-dir', self.workdir.name, outdir, outdir, outdir])
n = os.path.join(self.workdir.name, 'run', 'systemd', 'network', '10-netplan-br0.network')
self.assertTrue(os.path.exists(n))
os.unlink(n)

service_dir = os.path.join(self.workdir.name, 'run', 'systemd', 'system')
override = os.path.join(service_dir, 'systemd-networkd-wait-online.service.d', '10-netplan.conf')
subprocess.check_call([generator, '--root-dir', self.workdir.name, outdir, outdir, outdir])
self.assertTrue(os.path.isfile(override))
with open(override, 'r') as f:
self.assertEqual(f.read(), '''[Unit]
ConditionPathIsSymbolicLink=/run/systemd/generator/network-online.target.wants/systemd-networkd-wait-online.service
[Service]
ExecStart=
ExecStart=/lib/systemd/systemd-networkd-wait-online --any -o routable -i br0
''')

def test_systemd_generator_noconf(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/ethernets.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def test_systemd_networkd_wait_online(self):
[Service]
ExecStart=
ExecStart=/lib/systemd/systemd-networkd-wait-online -i %s:degraded -i br0:degraded -i findme:carrier
ExecStart=/lib/systemd/systemd-networkd-wait-online -i %s:routable -i br0:routable -i findme:carrier
''' % self.dev_e2_client)


Expand Down

0 comments on commit 1f5c78d

Please sign in to comment.