diff options
| author | Scott Moser <smoser@ubuntu.com> | 2018-08-06 19:33:54 +0000 | 
|---|---|---|
| committer | Server Team CI Bot <josh.powers+server-team-bot@canonical.com> | 2018-08-06 19:33:54 +0000 | 
| commit | 41f508da4f1e421f454136f3c84527a9911c63ff (patch) | |
| tree | 2f0c8d93881ea3fd0b81ec0b5bb6aa7cefce9905 | |
| parent | a6f95c72259f2890e4a9f9f11166310812173c68 (diff) | |
| download | vyos-cloud-init-41f508da4f1e421f454136f3c84527a9911c63ff.tar.gz vyos-cloud-init-41f508da4f1e421f454136f3c84527a9911c63ff.zip | |
netplan: Correctly render macaddress on a bonds and bridges when provided.
When converting network config v1 to netplan, we were not correctly
rendering the 'macaddress' key on a bond.  Not that the difference
in spelling between v1 'mac_address' and v2 'macaddress' is intentional.
Also fixed here is rendering of the macaddress for bridges.
LP: #1784699
| -rw-r--r-- | cloudinit/net/eni.py | 11 | ||||
| -rw-r--r-- | cloudinit/net/netplan.py | 4 | ||||
| -rw-r--r-- | tests/unittests/test_net.py | 6 | 
3 files changed, 19 insertions, 2 deletions
| diff --git a/cloudinit/net/eni.py b/cloudinit/net/eni.py index bd20a361..80be2429 100644 --- a/cloudinit/net/eni.py +++ b/cloudinit/net/eni.py @@ -247,8 +247,15 @@ def _parse_deb_config_data(ifaces, contents, src_dir, src_path):                  ifaces[currif]['bridge']['ports'] = []                  for iface in split[1:]:                      ifaces[currif]['bridge']['ports'].append(iface) -            elif option == "bridge_hw" and split[1].lower() == "mac": -                ifaces[currif]['bridge']['mac'] = split[2] +            elif option == "bridge_hw": +                # doc is confusing and thus some may put literal 'MAC' +                #    bridge_hw MAC <address> +                # but correct is: +                #    bridge_hw <address> +                if split[1].lower() == "mac": +                    ifaces[currif]['bridge']['mac'] = split[2] +                else: +                    ifaces[currif]['bridge']['mac'] = split[1]              elif option == "bridge_pathcost":                  if 'pathcost' not in ifaces[currif]['bridge']:                      ifaces[currif]['bridge']['pathcost'] = {} diff --git a/cloudinit/net/netplan.py b/cloudinit/net/netplan.py index 40143634..6352e78c 100644 --- a/cloudinit/net/netplan.py +++ b/cloudinit/net/netplan.py @@ -291,6 +291,8 @@ class Renderer(renderer.Renderer):                  if len(bond_config) > 0:                      bond.update({'parameters': bond_config}) +                if ifcfg.get('mac_address'): +                    bond['macaddress'] = ifcfg.get('mac_address').lower()                  slave_interfaces = ifcfg.get('bond-slaves')                  if slave_interfaces == 'none':                      _extract_bond_slaves_by_name(interfaces, bond, ifname) @@ -327,6 +329,8 @@ class Renderer(renderer.Renderer):                  if len(br_config) > 0:                      bridge.update({'parameters': br_config}) +                if ifcfg.get('mac_address'): +                    bridge['macaddress'] = ifcfg.get('mac_address').lower()                  _extract_addresses(ifcfg, bridge, ifname)                  bridges.update({ifname: bridge}) diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py index 5ab61cf2..58e5ea14 100644 --- a/tests/unittests/test_net.py +++ b/tests/unittests/test_net.py @@ -643,6 +643,7 @@ iface br0 inet static      bridge_stp off      bridge_waitport 1 eth3      bridge_waitport 2 eth4 +    hwaddress bb:bb:bb:bb:bb:aa  # control-alias br0  iface br0 inet6 static @@ -708,6 +709,7 @@ pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true                          interfaces:                          - eth1                          - eth2 +                        macaddress: aa:bb:cc:dd:ee:ff                          parameters:                              mii-monitor-interval: 100                              mode: active-backup @@ -720,6 +722,7 @@ pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true                          interfaces:                          - eth3                          - eth4 +                        macaddress: bb:bb:bb:bb:bb:aa                          nameservers:                              addresses:                              - 8.8.8.8 @@ -803,6 +806,7 @@ pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true                  IPV6ADDR=2001:1::1/64                  IPV6INIT=yes                  IPV6_DEFAULTGW=2001:4800:78ff:1b::1 +                MACADDR=bb:bb:bb:bb:bb:aa                  NETMASK=255.255.255.0                  NM_CONTROLLED=no                  ONBOOT=yes @@ -973,6 +977,7 @@ pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true                        use_tempaddr: 1                        forwarding: 1                        # basically anything in /proc/sys/net/ipv6/conf/.../ +                  mac_address: bb:bb:bb:bb:bb:aa                    params:                        bridge_ageing: 250                        bridge_bridgeprio: 22 @@ -1075,6 +1080,7 @@ pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true                       interfaces:                       - bond0s0                       - bond0s1 +                     macaddress: aa:bb:cc:dd:e8:ff                       mtu: 9000                       parameters:                           mii-monitor-interval: 100 | 
