Unset a subtree crashes
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Netplan |
Fix Released
|
Undecided
|
Simon Chopin | ||
netplan.io (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | ||
Focal |
Fix Released
|
Undecided
|
Unassigned | ||
Hirsute |
Fix Released
|
Undecided
|
Unassigned | ||
Impish |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
[Impact]
The netplan CLI would crash when trying to set an entire device type
subtree to null, e.g. `netplan set devices.
configuration would remain unaffected. This is obviously undesirable, as
the only workaround is to explictly loop through all the definitions.
The fix comes in two parts:
* add some internal APIs to libnetplan to be able to list all defintions
of a given type, with some care taken in the consuming Python bindings
if the symbols aren't present.
* use this new API to, when encountering this special case, expand the
devtype subtree into all its definitions, letting the normal subtree
nullification feature taking it up from there.
[Test Plan]
Boot a VM image with at least one ethernet device.
Write the following config to /etc/netplan/
network:
version: 2
ethernets:
all-en:
dhcp4: true
match:
name: en*
all-eth:
dhcp4: true
match:
name: eth*
Check that it has been taken into account using this command
netplan get
Unset the definitions we added:
netplan set network.
This command should silently succeed.
Finally, check that there are no ethernet device configured by running
netplan get
[Where problems could occur]
This is backported from a branch with considerable changes in the API
and ABI handling of libnetplan, so some ABI breakage might slip through
unnoticed, even though steps have been taken to prevent it.
The most risk of regression is in the `netplan set` command, as it is
where the existing code actually changes behaviour. This could be
particularly bad as this could overwrite existing configuration files
with erroneous configuration, leading to non-functional networking.
Also, the DBus endpoints for netplan directly uses the `netplan set`
command, so its users could be impacted as well.
[Original report]
While working on the snapd netplan integration I ran into the following peculiar issue.
I want to unset a subtree of configuration, e.g. I have:
# netplan get
network:
version: 2
ethernets:
all-en:
dhcp4: true
match:
name: en*
all-eth:
dhcp4: true
match:
name: eth*
and want to remove all ethernet configuration. AIUI this can be done via setting the subtree to "null" (or did I misunderstood this)? If I try that I get:
# netplan set network.
Traceback (most recent call last):
File "/usr/sbin/
netplan.main()
File "/usr/share/
self.
File "/usr/share/
self.func()
File "/usr/share/
self.
File "/usr/share/
self.func()
File "/usr/share/
hints = self.split_
File "/usr/share/
for netdef in network.
TypeError: 'NoneType' object is not iterable
Do you have any hints how I can delete an entire subtree via the commandline (well, via dbus but it's a direct mapping so cmdline is fine).
This is Ubuntu Core 20 with netplan 0.102-0ubuntu1~
$ sudo netplan get
network:
bridges:
br54:
dhcp4: true
dhcp6: true
renderer: NetworkManager
version: 2
$ sudo netplan set network.
Traceback (most recent call last):
File "/usr/sbin/
netplan.main()
File "/usr/share/
self.
File "/usr/share/
self.func()
File "/usr/share/
self.
File "/usr/share/
self.func()
File "/usr/share/
hints = self.split_
File "/usr/share/
for netdef in network.
TypeError: 'NoneType' object is not iterable
Related branches
- Lukas Märdian: Approve
-
Diff: 995 lines (+967/-0)4 files modifieddebian/changelog (+14/-0)
debian/patches/0005-Implement-YAML-state-tracking-and-use-it-in-the-DBus.patch (+583/-0)
debian/patches/0006-netplan-set-make-it-possible-to-unset-a-whole-devtyp.patch (+368/-0)
debian/patches/series (+2/-0)
- Lukas Märdian: Pending requested
-
Diff: 1161 lines (+1007/-12) (has conflicts)7 files modifieddebian/changelog (+34/-0)
debian/control (+4/-0)
debian/gbp.conf (+4/-0)
debian/patches/0005-Implement-YAML-state-tracking-and-use-it-in-the-DBus.patch (+583/-0)
debian/patches/0006-netplan-set-make-it-possible-to-unset-a-whole-devtyp.patch (+368/-0)
debian/patches/series (+2/-0)
debian/tests/control (+12/-12)
- Lukas Märdian: Approve
-
Diff: 995 lines (+967/-0)4 files modifieddebian/changelog (+14/-0)
debian/patches/0005-Implement-YAML-state-tracking-and-use-it-in-the-DBus.patch (+583/-0)
debian/patches/0006-netplan-set-make-it-possible-to-unset-a-whole-devtyp.patch (+368/-0)
debian/patches/series (+2/-0)
Changed in netplan: | |
status: | New → Triaged |
Changed in netplan: | |
assignee: | nobody → Simon Chopin (schopin) |
description: | updated |
Changed in netplan: | |
status: | In Progress → Fix Released |
Yes. Looks like you discovered a bug here. bridges. br54=null
It works if you unset an "interface subtree", e.g.:
$ sudo netplan set network.
But apparently not if you delete a whole set of devices, that might be spread across a set of YAML files (like network. bridges= null, network=null).
I can reproduce the issue with a simple unit-test in `test_clie_ get_set. py` and we should fix it.
def test_set_ delete_ subtree( self):
f. write(' ''network: \n version: 2\n renderer: NetworkManager ['network. ethernets= null'])
self.assertTru e(os.path. isfile( self.path) )
print( out, flush=True) # debugging
self. assertIn( 'network: \n', out)
self. assertIn( ' version: 2\n', out)
self. assertIn( ' renderer: NetworkManager\n', out)
self. assertNotIn( 'ethernets: ', out)
with open(self.path, 'w') as f:
ethernets:
eth0: {addresses: [1.2.3.4/24]}''')
ret = self._set(
print(ret, flush=True) # debugging
with open(self.path, 'r') as f:
out = f.read()