net renderers miss metric value in per-subnet routes

Bug #1805871 reported by Ryan Harper on 2018-11-29
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
cloud-init (Ubuntu)
Undecided
Unassigned

Bug Description

When rendering a per-subnet route with a metric, the value is ignored due to clobbering of the looping variable.

Consider this v1 input:

{
    "version": 1,
    "config": [
        {
            "type": "physical",
            "name": "eno3",
            "mac_address": "aa:bb:cc:dd:ee:ff",
            "subnets": [
                {
                    "control": "auto",
                    "type": "static",
                    "address": "192.168.14.13",
                    "netmask": "255.255.255.0",
                    "routes": [
                        {
                            "destination": "192.168.14.0/24",
                            "type": "route",
                            "gateway": "192.168.14.254",
                            "metric": 10000
                        }
                    ]
                }
            ]
        },
        {
            "type": "nameserver",
            "address": [
                "8.8.8.8"
            ],
            "search": []
        }
    ]
}

This should result in a netplan where we have a route entry with the correct gateway value and the metric, like this:

network:
    version: 2
    ethernets:
        eno3:
            addresses:
            - 192.168.14.13/24
            match:
                macaddress: aa:bb:cc:dd:ee:ff
            nameservers:
                addresses:
                - 8.8.8.8
                search: []
            routes:
            - metric: 10000
              to: 192.168.14.0/24
              via: 192.168.14.254
            set-name: eno3

But instead, we get this:

network:
    version: 2
    ethernets:
        eno3:
            addresses:
            - 192.168.14.13/24
            match:
                macaddress: aa:bb:cc:dd:ee:ff
            nameservers:
                addresses:
                - 8.8.8.8
                search: []
            routes:
            - to: 192.168.14.0/24
              via: 192.168.14.254
            set-name: eno3

The bug is in here in _extract_addresses in cloudinit/net/netplan.py

            for route in subnet.get('routes', []):
                to_net = "%s/%s" % (route.get('network'),
                                    route.get('prefix'))
                route = { # BUG! clobbers looping variable route
                    'via': route.get('gateway'),
                    'to': to_net,
                }
                if 'metric' in route:
                    route.update({'metric': route.get('metric', 100)})
                routes.append(new_route)

Related branches

Ryan Harper (raharper) wrote :

Note, this also affects the eni and sysconfig router as well.

summary: - netplan renderer misses metric value in per-subnet routes
+ net renderers miss metric value in per-subnet routes
Ryan Harper (raharper) wrote :

*renderers*

This bug is fixed with commit 6aef6c7d to cloud-init on branch master.
To view that commit see the following URL:
https://git.launchpad.net/cloud-init/commit/?id=6aef6c7d

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package cloud-init - 18.5-1-g5b065316-0ubuntu1

---------------
cloud-init (18.5-1-g5b065316-0ubuntu1) disco; urgency=medium

  * New upstream snapshot.
    - Update to pylint 2.2.2.
    - Release 18.5 (LP: #1808380)
    - tests: add Disco release [Joshua Powers]
    - net: render 'metric' values in per-subnet routes (LP: #1805871)
    - write_files: add support for appending to files. [James Baxter]
    - config: On ubuntu select cloud archive mirrors for armel, armhf, arm64.
      (LP: #1805854)
    - dhclient-hook: cleanups, tests and fix a bug on 'down' event.
    - NoCloud: Allow top level 'network' key in network-config. (LP: #1798117)
    - ovf: Fix ovf network config generation gateway/routes (LP: #1806103)

 -- Ryan Harper <email address hidden> Fri, 14 Dec 2018 14:45:46 -0600

Changed in cloud-init (Ubuntu):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers