Unset value crashes

Bug #1943023 reported by Michael Vogt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Netplan
New
Undecided
Unassigned

Bug Description

While working on a workaround for https://bugs.launchpad.net/netplan/+bug/1942930 I ran into the following issue (and maybe I'm holding it wrong, feedback very welcome :).

Snapd wants to set a new value, e.g. "network.bridges.br54.dhcp4=true" - because of the way snapd works internally it only has a completely merged config so it does not know if there was a value or a subtree for the given key before but it knows what it should be after. So the new workaround code does now unset anythng in snapd that was changed by the user. So "network.bridges.br54.dhcp4=true" becomes: "network.bridges.br54.dhcp4=null" and "network.bridges.br54.dhcp4=true".

However when I do this I get on my test system, I get:
# netplan get
network:
  ethernets:
    all-en:
      dhcp4: true
      match:
        name: en*
    all-eth:
      dhcp4: true
      match:
        name: eth*
  version: 2

# netplan set network.bridges.br54.dhcp4=null 90-snapd-conf
Traceback (most recent call last):
  File "/usr/sbin/netplan", line 23, in <module>
    netplan.main()
  File "/usr/share/netplan/netplan/cli/core.py", line 50, in main
    self.run_command()
  File "/usr/share/netplan/netplan/cli/utils.py", line 264, in run_command
    self.func()
  File "/usr/share/netplan/netplan/cli/commands/set.py", line 52, in run
    self.run_command()
  File "/usr/share/netplan/netplan/cli/utils.py", line 264, in run_command
    self.func()
  File "/usr/share/netplan/netplan/cli/commands/set.py", line 98, in command_set
    self.write_file(subtree, hint + '.yaml', self.root_dir)
  File "/usr/share/netplan/netplan/cli/commands/set.py", line 167, in write_file
    raise Exception('Invalid input: {}'.format(set_tree))
Exception: Invalid input: {'network': {'bridges': {'br54': {'dhcp4': None}}}}

I will look again into a workaround for this but it seems this should not crash(?).

Michael Vogt (mvo)
summary: - Unset value crahes
+ Unset value crashes
Revision history for this message
Simon Chopin (schopin) wrote : Re: [Bug 1943023] [NEW] Unset value crashes

Hello Michael :)

Quoting Michael Vogt (2021-09-08 12:11:06)
> Public bug reported:
>
> While working on a workaround for
> https://bugs.launchpad.net/netplan/+bug/1942930 I ran into the following
> issue (and maybe I'm holding it wrong, feedback very welcome :).
>
> Snapd wants to set a new value, e.g. "network.bridges.br54.dhcp4=true" -
> because of the way snapd works internally it only has a completely
> merged config so it does not know if there was a value or a subtree for
> the given key before but it knows what it should be after. So the new
> workaround code does now unset anythng in snapd that was changed by the
> user. So "network.bridges.br54.dhcp4=true" becomes:
> "network.bridges.br54.dhcp4=null" and "network.bridges.br54.dhcp4=true".

I'm not clear about your reason for unsetting the key first. Is the set
subcommand unable to replace an existing value?

[...]
> # netplan set network.bridges.br54.dhcp4=null 90-snapd-conf
> Traceback (most recent call last):
> File "/usr/sbin/netplan", line 23, in <module>
> netplan.main()
> File "/usr/share/netplan/netplan/cli/core.py", line 50, in main
> self.run_command()
> File "/usr/share/netplan/netplan/cli/utils.py", line 264, in run_command
> self.func()
> File "/usr/share/netplan/netplan/cli/commands/set.py", line 52, in run
> self.run_command()
> File "/usr/share/netplan/netplan/cli/utils.py", line 264, in run_command
> self.func()
> File "/usr/share/netplan/netplan/cli/commands/set.py", line 98, in command_set
> self.write_file(subtree, hint + '.yaml', self.root_dir)
> File "/usr/share/netplan/netplan/cli/commands/set.py", line 167, in write_file
> raise Exception('Invalid input: {}'.format(set_tree))
> Exception: Invalid input: {'network': {'bridges': {'br54': {'dhcp4': None}}}}
>
> I will look again into a workaround for this but it seems this should
> not crash(?).

I'm not clear if that's a genuine crash, as in "unexpected program
state", or poor error reporting, but in any case this isn't very
user-friendly :D

Revision history for this message
Michael Vogt (mvo) wrote :

Hey Simon, thanks for your reply!

Replacing is fine for scalar values but if a map/subtree changes then netplan will merge new/old values AIUI so if I have something like:

$ netplan get
network:
  bridges:
    br54:
      dhcp4: true
      dhcp6: true
  renderer: NetworkManager
  version: 2

and if I want the new state to be (and I only have this information):

network:
  bridges:
    br54:
      dhcp4: true
  renderer: NetworkManager
  version: 2

(i.e. dhcp6 should get removed). I can't just do:
$ sudo netplan set 'network.bridges.br54={"dhcp4": true}'
because that will just merge old/new and dhcp6 stays here.

Unfortunately because of the way snapd works internally I only know the "end" state but not the exact change so I need something like:
$ sudo netplan set-but-do-not-merge 'network.bridges.br54={"dhcp4": true}'
which I tried to do via "unset first, then set to new value" which lead to the crash :)

Anyway, I will look at another workaround for this but I felt it was worth reporting.

Revision history for this message
Lukas Märdian (slyon) wrote :

Actually I think this is running into the same program state as LP: #1946957 (e.g. we unset something, but the hint file does not exist), which is not being handled properly. I'm marking this as a duplicate.

Revision history for this message
Simon Chopin (schopin) wrote : Re: [Bug 1943023] Re: Unset value crashes

I'm wondering how the new `netplan get` implementation fares with this.
IIRC its handling of nulls is more generic than the current one, so it
might be allright.

(that'd be https://github.com/canonical/netplan/pull/241 for those
following at home)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.