KeyError on optional parameters on bridge

Bug #1879673 reported by Felix Engelmann
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
cloud-init
Undecided
Unassigned

Bug Description

I use NoCloud with network-config-format-v2
and the following network config according to
https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v2.html#bridges

/var/lib/cloud/seed/nocloud-net/network-config:
version: 2
ethernets:
  eth0:
    match: {name: "eth0"}
  eth1:
    match: {name: "eth1"}
bridges:
  br0:
    interfaces: [eth1]

cloud-init init fails with a Python error:

2020-05-20 09:53:24,474 - util.py[WARNING]: failed stage init
failed run of stage init
------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 653, in status_wrapper
    ret = functor(name, args)
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 362, in main_init
    init.apply_network_config(bring_up=bool(mode != sources.DSMODE_LOCAL))
  File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 708, in apply_network_config
    return self.distro.apply_network_config(netcfg, bring_up=bring_up)
  File "/usr/lib/python3/dist-packages/cloudinit/distros/__init__.py", line 180, in apply_network_config
    dev_names = self._write_network_config(netconfig)
  File "/usr/lib/python3/dist-packages/cloudinit/distros/debian.py", line 115, in _write_network_config
    return self._supported_write_network_config(netconfig)
  File "/usr/lib/python3/dist-packages/cloudinit/distros/__init__.py", line 95, in _supported_write_network_config
    renderer.render_network_config(network_config)
  File "/usr/lib/python3/dist-packages/cloudinit/net/renderer.py", line 55, in render_network_config
    network_state=parse_net_config_data(network_config),
  File "/usr/lib/python3/dist-packages/cloudinit/net/network_state.py", line 76, in parse_net_config_data
    nsi.parse_config(skip_broken=skip_broken)
  File "/usr/lib/python3/dist-packages/cloudinit/net/network_state.py", line 292, in parse_config
    self.parse_config_v2(skip_broken=skip_broken)
  File "/usr/lib/python3/dist-packages/cloudinit/net/network_state.py", line 323, in parse_config_v2
    handler(self, command)
  File "/usr/lib/python3/dist-packages/cloudinit/net/network_state.py", line 599, in handle_bridges
    self._handle_bond_bridge(command, cmd_type='bridge')
  File "/usr/lib/python3/dist-packages/cloudinit/net/network_state.py", line 728, in _handle_bond_bridge
    params = item_params['parameters']
KeyError: 'parameters'

It may be fixed by changing:
https://github.com/canonical/cloud-init/blob/master/cloudinit/net/network_state.py#L728
to
   params = item_params.get('parameters', {})
as the parameters key is optional.

The workaround is to add an empty
   parameters: {}
mapping to your bridge

Related branches

Revision history for this message
Paride Legovini (paride) wrote :

Hello Felix and thanks for your bug report. Could you please run:

  cloud-init collect-logs

right after the problem occurs, and attach the generated tarball to this bug report? The context information in those logs will help us to better understand what's going on.

I'm setting the status of this report to Incomplete for the moment, please change it back to New after commenting back. Thanks!

Changed in cloud-init:
status: New → Incomplete
Revision history for this message
Brian Candler (b-candler) wrote :

I get the same error. network-config has:

version: 2
ethernets:
  ens3:
    accept-ra: false
bridges:
  br0:
    interfaces:
      - ens3
    forward-delay: 0
    stp: false
    accept-ra: false
    addresses:
      - 192.168.122.250/24
      - 2001:db8:0:0::250/64
    gateway4: 192.168.122.1
    gateway6: 2001:db8:0:0::254
    nameservers:
      addresses:
        - 192.168.122.1
      search:
        - ws.nsrc.org

and /var/log/cloud-init-output.log shows:

Cloud-init v. 19.4-33-gbb4131a2-0ubuntu1~18.04.1 running 'init-local' at Fri, 05 Jun 2020 20:24:41 +0000. Up 10.35 seconds.
2020-06-05 20:24:42,626 - util.py[WARNING]: failed stage init-local
failed run of stage init-local
------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 653, in status_wrapper
    ret = functor(name, args)
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 362, in main_init
    init.apply_network_config(bring_up=bool(mode != sources.DSMODE_LOCAL))
  File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 710, in apply_network_config
    return self.distro.apply_network_config(netcfg, bring_up=bring_up)
  File "/usr/lib/python3/dist-packages/cloudinit/distros/__init__.py", line 178, in apply_network_config
    dev_names = self._write_network_config(netconfig)
  File "/usr/lib/python3/dist-packages/cloudinit/distros/debian.py", line 115, in _write_network_config
    return self._supported_write_network_config(netconfig)
  File "/usr/lib/python3/dist-packages/cloudinit/distros/__init__.py", line 93, in _supported_write_network_config
    renderer.render_network_config(network_config)
  File "/usr/lib/python3/dist-packages/cloudinit/net/renderer.py", line 55, in render_network_config
    network_state=parse_net_config_data(network_config),
  File "/usr/lib/python3/dist-packages/cloudinit/net/network_state.py", line 78, in parse_net_config_data
    nsi.parse_config(skip_broken=skip_broken)
  File "/usr/lib/python3/dist-packages/cloudinit/net/network_state.py", line 295, in parse_config
    self.parse_config_v2(skip_broken=skip_broken)
  File "/usr/lib/python3/dist-packages/cloudinit/net/network_state.py", line 326, in parse_config_v2
    handler(self, command)
  File "/usr/lib/python3/dist-packages/cloudinit/net/network_state.py", line 602, in handle_bridges
    self._handle_bond_bridge(command, cmd_type='bridge')
  File "/usr/lib/python3/dist-packages/cloudinit/net/network_state.py", line 731, in _handle_bond_bridge
    params = item_params['parameters']
KeyError: 'parameters'

I will upload the requested logs bundle from my system.

Revision history for this message
Brian Candler (b-candler) wrote :
Revision history for this message
Brian Candler (b-candler) wrote :

I'd also add in the documentation at https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v2.html it's very unclear whether all the settings listed after "parameters" need to be nested under "parameters", because there are no examples of this.

In other words, it could be that the solution is to change

  br0:
    interfaces:
      - ens3
    forward-delay: 0
    stp: false
    accept-ra: false
    ...

to

  br0:
    interfaces:
      - ens3
    parameters:
      forward-delay: 0
      stp: false
    accept-ra: false
    ...

Of course, this bug still applies (you might not want to set any parameters at all).

On top of this, I think it would be be helpful if an error were reported when unknown parameters appear at the outer level.

Revision history for this message
Felix Engelmann (felix.engelmann) wrote :

Thank you for the logs Brian. I in my setting it was very difficult to extract the logs, as the collect-logs command itself failed.

Revision history for this message
Brian Candler (b-candler) wrote :

This was a regression introduced in cloud-init commit ded1ec81e3c6c37c5241b12fcc3c41182e675dff intended to fix LP #1827238

I have made a pull request to fix this:
https://code.launchpad.net/~b-candler/cloud-init/+git/cloud-init/+merge/385242

Revision history for this message
Paride Legovini (paride) wrote :

Hi Brian,

The development of cloud-init now happens on GitHub:

  https://github.com/canonical/cloud-init

Could you please resubmit your PR there? Thanks!

Revision history for this message
Brian Candler (b-candler) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for cloud-init because there has been no activity for 60 days.]

Changed in cloud-init:
status: Incomplete → Expired
Revision history for this message
James Falcon (falcojr) wrote : Fixed in cloud-init version 20.3.

This bug is believed to be fixed in cloud-init in version 20.3. If this is still a problem for you, please make a comment and set the state back to New

Thank you.

Changed in cloud-init:
status: Expired → Fix Released
Revision history for this message
Brian Candler (b-candler) wrote :

Latest cloud-init for ubuntu 18.04 is 20.2, and this doesn't have the fix.

Are there plans to backport 20.3 ?

Revision history for this message
Brian Candler (b-candler) wrote :

cloud-init 20.3 has appeared in Ubuntu 18.04, so as far as I'm concerned, this ticket can now be closed.

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

Other bug subscribers

Bug attachments