Skip to content

Commit

Permalink
parse: handle redefinition of a place holder netdef
Browse files Browse the repository at this point in the history
If we find an interface with the same name of a place holder created
earlier, we just change the place holder type to the type of the
new interface and use it to store the configuration.

Without this logic the parser would fail if it finds an interface with
the same name of the place holder but of a different type.
  • Loading branch information
daniloegea committed Jun 28, 2023
1 parent 955cbac commit 9f87878
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -3071,8 +3071,13 @@ handle_network_type(NetplanParser* npp, yaml_node_t* node, const char* key_prefi
npp->current.netdef = npp->parsed_defs ? g_hash_table_lookup(npp->parsed_defs, scalar(key)) : NULL;
if (npp->current.netdef) {
/* already exists, overriding/amending previous definition */
if (npp->current.netdef->type != GPOINTER_TO_UINT(data))
return yaml_error(npp, key, error, "Updated definition '%s' changes device type", scalar(key));
if (npp->current.netdef->type != GPOINTER_TO_UINT(data)) {
/* If the existing netdef is a place holder, we just repurpose it */
if (npp->current.netdef->type == NETPLAN_DEF_TYPE_NM_PLACEHOLDER_)
npp->current.netdef->type = GPOINTER_TO_UINT(data);
else
return yaml_error(npp, key, error, "Updated definition '%s' changes device type", scalar(key));
}
} else {
npp->current.netdef = netplan_netdef_new(npp, scalar(key), GPOINTER_TO_UINT(data), npp->current.backend);
}
Expand Down
18 changes: 18 additions & 0 deletions tests/generator/test_vlans.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,21 @@ def test_vlan_parent_is_allowed_to_be_missing_for_nm(self):
[ipv6]
method=ignore
'''})

def test_vlan_with_missing_netdef_found_in_the_next_file_wont_fail(self):
''' If eth0 was registered as missing (and created as a placeholder netdef)
if shouldn't fail if it's defined in a file that was parsed *after* the file where
the VLAN is defined
'''
out = self.generate('''network:
renderer: NetworkManager
version: 2
vlans:
vlan100:
id: 100
link: eth0''', confs={'b': '''network:
renderer: NetworkManager
version: 2
ethernets: {eth0: {}}'''})

self.assertNotIn('Updated definition \'eth0\' changes device type', out)

0 comments on commit 9f87878

Please sign in to comment.