Skip to content

Commit

Permalink
ATTN: Change /{usr/lib,run,etc}/netplan parsing order
Browse files Browse the repository at this point in the history
FR-5885
  • Loading branch information
slyon committed Jan 10, 2024
1 parent 3e38d4c commit 27f9890
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions doc/netplan-generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ For details of the configuration file format, see **`netplan`**(5).
: Print debugging output during the process.

`--root-dir` *`ROOT_DIR`*
: Instead of looking in `/{lib,etc,run}/netplan`, look in
`/ROOT_DIR/{lib,etc,run}/netplan`.
: Instead of looking in `/{lib,run,etc}/netplan`, look in
`/ROOT_DIR/{lib,run,etc}/netplan`.

`--mapping` *`MAPPING`*
: Instead of generating output files, parse the configuration files
Expand Down
2 changes: 1 addition & 1 deletion doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## YAML configuration
Netplan configuration files use the
[YAML (v1.1)](http://yaml.org/spec/1.1/current.html) format. All files in
`/{lib,etc,run}/netplan/*.yaml` are considered and are supposed to use
`/{lib,run,etc}/netplan/*.yaml` are considered and are supposed to use
restrictive file permissions (`600`/`rw-------`), i.e. owner (root) read-write
only.

Expand Down
8 changes: 4 additions & 4 deletions doc/structure-id.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Distribution installers, cloud instantiation, image builds for particular
devices, or any other way to deploy an operating system put its desired
network configuration into YAML configuration file(s). During
early boot, the Netplan "network renderer" runs which reads
`/{lib,etc,run}/netplan/*.yaml` and writes configuration to `/run` to hand
`/{lib,run,etc}/netplan/*.yaml` and writes configuration to `/run` to hand
off control of devices to the specified networking daemon.

- Configured devices get handled by systemd-networkd by default,
Expand All @@ -24,10 +24,10 @@ off control of devices to the specified networking daemon.

Netplan configuration files use the
[YAML](http://yaml.org/spec/1.1/current.html) format. All
`/{lib,etc,run}/netplan/*.yaml` are considered. Lexicographically later files
`/{lib,run,etc}/netplan/*.yaml` are considered. Lexicographically later files
(regardless of in which directory they are) amend (new mapping keys) or
override (same mapping keys) previous ones. A file in `/run/netplan`
completely shadows a file with same name in `/etc/netplan`, and a file in
override (same mapping keys) previous ones. A file in `/etc/netplan`
completely shadows a file with same name in `/run/netplan`, and a file in
either of those directories shadows a file with the same name in `/lib/netplan`.

The top-level node in a Netplan configuration file is a `network:` mapping
Expand Down
4 changes: 2 additions & 2 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ unlink_glob(const char* rootdir, const char* _glob)
}

/**
* Return a glob of all *.yaml files in /{lib,etc,run}/netplan/ (in this order)
* Return a glob of all *.yaml files in /{lib,run,etc}/netplan/ (in this order)
*/
int find_yaml_glob(const char* rootdir, glob_t* out_glob)
{
int rc;
g_autofree char* rglob = g_build_path(G_DIR_SEPARATOR_S,
rootdir ?: G_DIR_SEPARATOR_S,
"{lib,etc,run}/netplan/*.yaml", NULL);
"{lib,run,etc}/netplan/*.yaml", NULL);
rc = glob(rglob, GLOB_BRACE, NULL, out_glob);
if (rc != 0 && rc != GLOB_NOMATCH) {
// LCOV_EXCL_START
Expand Down
22 changes: 14 additions & 8 deletions tests/generator/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import textwrap

from .base import TestBase, ND_DHCP4, ND_DHCP6, ND_DHCPYES, ND_EMPTY, NM_MANAGED, NM_UNMANAGED
from .base import TestBase, ND_DHCP4, ND_DHCP6, ND_DHCPYES, ND_EMPTY, ND_WITHIP, NM_MANAGED, NM_UNMANAGED


class TestNetworkd(TestBase):
Expand Down Expand Up @@ -1692,7 +1692,7 @@ def test_ref(self):
def test_def_in_run(self):
rundir = os.path.join(self.workdir.name, 'run', 'netplan')
os.makedirs(rundir)
# override b.yaml definition for enred
# gets overridden by b.yaml definition for enred in /etc
with open(os.path.join(rundir, 'b.yaml'), 'w') as f:
f.write('''network:
version: 2
Expand All @@ -1704,17 +1704,23 @@ def test_def_in_run(self):
version: 2
ethernets: {enblue: {dhcp4: true}}''')

# write /etc/netplan/a.yaml and /etc/netplan/b.yaml
self.generate('''network:
version: 2
ethernets:
engreen: {dhcp4: true}''', confs={'b': '''network:
ethernets: {engreen: {dhcp4: true}}''', confs={'b': '''network:
version: 2
ethernets: {enred: {wakeonlan: true}}'''})
ethernets:
enred:
wakeonlan: true # WOL will create a .link file
addresses: [10.0.0.42/24]
ignore-carrier: true'''})

# b.yaml in /run/ should completely shadow b.yaml in /etc, thus no enred.link
# b.yaml in /etc should completely shadow b.yaml in /run,
# producing enred.link with WOL settings
self.assert_networkd({'engreen.network': ND_DHCP4 % 'engreen',
'enred.network': ND_DHCP4 % 'enred',
'enblue.network': ND_DHCP4 % 'enblue'})
'enred.network': ND_WITHIP % ('enred', '10.0.0.42/24'),
'enblue.network': ND_DHCP4 % 'enblue',
'enred.link': '[Match]\nOriginalName=enred\n\n[Link]\nWakeOnLan=magic\n'})

def test_def_in_lib(self):
libdir = os.path.join(self.workdir.name, 'lib', 'netplan')
Expand Down

0 comments on commit 27f9890

Please sign in to comment.