Skip to content

Commit

Permalink
wait-online: do not require virtual devices to be created already
Browse files Browse the repository at this point in the history
  • Loading branch information
slyon committed Apr 24, 2024
1 parent a4f803e commit a00ec97
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/networkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1501,8 +1501,12 @@ _netplan_networkd_write_wait_online(const NetplanState* np_state, const char* ro
|| netplan_netdef_get_link_local_ipv6(def);
_netplan_address_iter_free(addr_iter);

// no matching => single interface, ignoring non-existing interfaces
if (!netplan_netdef_has_match(def) && g_hash_table_contains(system_interfaces, def->id)) {
// no matching => single physical interface, ignoring non-existing interfaces
// OR: virtual interfaces, those will be created later on and cannot have a matching condition
gboolean physical_no_match_or_virtual = FALSE
|| (!netplan_netdef_has_match(def) && g_hash_table_contains(system_interfaces, def->id))
|| (netplan_netdef_get_type(def) >= NETPLAN_DEF_TYPE_VIRTUAL);
if (physical_no_match_or_virtual) {
g_hash_table_replace(non_optional_interfaces, g_strdup(def->id), any_ips ? g_strdup("degraded") : g_strdup("carrier"));
} else if (def->set_name) { // matching on a single interface, to be renamed
_netplan_enumerate_interfaces(def, system_interfaces, non_optional_interfaces, any_ips ? "degraded" : "carrier", def->set_name, rootdir);
Expand Down
10 changes: 8 additions & 2 deletions tests/generator/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ def test_systemd_generator(self):
dhcp4: true
optional: true
lo:
addresses: ["127.0.0.1/8", "::1/128"]''')
addresses: ["127.0.0.1/8", "::1/128"]
bridges:
br0:
dhcp4: true''')
os.chmod(conf, mode=0o600)
outdir = os.path.join(self.workdir.name, 'out')
os.mkdir(outdir)
Expand All @@ -153,6 +156,9 @@ def test_systemd_generator(self):
n = os.path.join(self.workdir.name, 'run', 'systemd', 'network', '10-netplan-lo.network')
self.assertTrue(os.path.exists(n))
os.unlink(n)
n = os.path.join(self.workdir.name, 'run', 'systemd', 'network', '10-netplan-br0.network')
self.assertTrue(os.path.exists(n))
os.unlink(n)

# should auto-enable networkd and -wait-online
service_dir = os.path.join(self.workdir.name, 'run', 'systemd', 'system')
Expand All @@ -168,7 +174,7 @@ def test_systemd_generator(self):
[Service]
ExecStart=
ExecStart=/lib/systemd/systemd-networkd-wait-online -i lo:carrier\n''') # eth99 does not exist on the system
ExecStart=/lib/systemd/systemd-networkd-wait-online -i br0:degraded -i lo:carrier\n''') # eth99 does not exist on the system

# 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
8 changes: 6 additions & 2 deletions tests/integration/ethernets.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,12 @@ def test_systemd_networkd_wait_online(self):
set-name: "findme"
%(e2c)s:
addresses: ["10.0.0.1/24"]
bridges:
br0:
addresses: ["10.0.0.2/24"]
interfaces: [%(e2c)s]
''' % {'r': self.backend, 'ec_mac': self.dev_e_client_mac, 'e2c': self.dev_e2_client})
self.generate_and_settle([self.dev_e2_client])
self.generate_and_settle([self.dev_e2_client, 'br0'])
override = os.path.join('/run', 'systemd', 'system', 'systemd-networkd-wait-online.service.d', '10-netplan.conf')
self.assertTrue(os.path.isfile(override))

Expand All @@ -424,7 +428,7 @@ def test_systemd_networkd_wait_online(self):
[Service]
ExecStart=
ExecStart=/lib/systemd/systemd-networkd-wait-online -i %s:degraded -i findme:carrier
ExecStart=/lib/systemd/systemd-networkd-wait-online -i %s:degraded -i br0:degraded -i findme:carrier
''' % self.dev_e2_client)


Expand Down

0 comments on commit a00ec97

Please sign in to comment.