← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~raharper/cloud-init:fix/add-netplan-fixed-grat-arp-spelling into cloud-init:master

 

Ryan Harper has proposed merging ~raharper/cloud-init:fix/add-netplan-fixed-grat-arp-spelling into cloud-init:master.

Commit message:
netplan: update netplan key mappings for gratuitous-arp
    
Previous versions of netplan included a misspelling for the
bond parameter around gratuitous-arp.  This has been fixed and released
and cloud-init needs to accept both values.  This branch fixes the
key that will be rendered and transforms the previous misspelling
when capturing network_state.
    
LP: #1827238


Requested reviews:
  cloud-init commiters (cloud-init-dev)
Related bugs:
  Bug #1827238 in cloud-init: "Machines fail to deploy because cloud-init needs to accept both netplan spellings for grat arp"
  https://bugs.launchpad.net/cloud-init/+bug/1827238

For more details, see:
https://code.launchpad.net/~raharper/cloud-init/+git/cloud-init/+merge/366935
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~raharper/cloud-init:fix/add-netplan-fixed-grat-arp-spelling into cloud-init:master.
diff --git a/cloudinit/net/network_state.py b/cloudinit/net/network_state.py
index 4d19f56..91046b5 100644
--- a/cloudinit/net/network_state.py
+++ b/cloudinit/net/network_state.py
@@ -36,7 +36,7 @@ NET_CONFIG_TO_V2 = {
              'bond-miimon': 'mii-monitor-interval',
              'bond-min-links': 'min-links',
              'bond-mode': 'mode',
-             'bond-num-grat-arp': 'gratuitious-arp',
+             'bond-num-grat-arp': 'gratuitous-arp',
              'bond-primary': 'primary',
              'bond-primary-reselect': 'primary-reselect-policy',
              'bond-updelay': 'up-delay',
@@ -707,6 +707,13 @@ class NetworkStateInterpreter(object):
             item_params = dict((key, value) for (key, value) in
                                item_cfg.items() if key not in
                                NETWORK_V2_KEY_FILTER)
+            if 'gratuitious-arp' in item_params['parameters']:
+                params = item_params['parameters']
+                old_key = 'gratuitious-arp'
+                new_key = 'gratuitous-arp'
+                params[new_key] = copy.copy(params[old_key])
+                del params[old_key]
+
             v1_cmd = {
                 'type': cmd_type,
                 'name': item_name,
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index e85e964..464b73e 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -407,6 +407,37 @@ network:
                 - maas
 """
 
+NETPLAN_BOND_GRAT_ARP = """
+network:
+    bonds:
+        bond0:
+            interfaces:
+            - ens3
+            macaddress: 68:05:ca:64:d3:6c
+            mtu: 9000
+            parameters:
+                gratuitious-arp: 1
+        bond1:
+            interfaces:
+            - ens4
+            macaddress: 68:05:ca:64:d3:6d
+            mtu: 9000
+            parameters:
+                gratuitous-arp: 2
+    ethernets:
+        ens3:
+            dhcp4: false
+            dhcp6: false
+            match:
+                macaddress: 52:54:00:ab:cd:ef
+        ens4:
+            dhcp4: false
+            dhcp6: false
+            match:
+                macaddress: 52:54:00:11:22:ff
+    version: 2
+"""
+
 NETPLAN_DHCP_FALSE = """
 version: 2
 ethernets:
@@ -3589,6 +3620,21 @@ class TestNetplanRoundTrip(CiTestCase):
             entry['expected_netplan'].splitlines(),
             files['/etc/netplan/50-cloud-init.yaml'].splitlines())
 
+    def test_render_output_supports_both_grat_arp_spelling(self):
+        entry = {
+            'yaml': NETPLAN_BOND_GRAT_ARP,
+            'expected_netplan': NETPLAN_BOND_GRAT_ARP.replace('gratuitious',
+                                                              'gratuitous'),
+        }
+        network_config = yaml.load(entry['yaml']).get('network')
+        files = self._render_and_read(network_config=network_config)
+        print(entry['expected_netplan'])
+        print('-- expected ^ | v rendered --')
+        print(files['/etc/netplan/50-cloud-init.yaml'])
+        self.assertEqual(
+            entry['expected_netplan'].splitlines(),
+            files['/etc/netplan/50-cloud-init.yaml'].splitlines())
+
 
 class TestEniRoundTrip(CiTestCase):
 

Follow ups