← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~raharper/cloud-init:eni-bridge-multiline-keys into cloud-init:master

 

Ryan Harper has proposed merging ~raharper/cloud-init:eni-bridge-multiline-keys into cloud-init:master.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~raharper/cloud-init/+git/cloud-init/+merge/324702

Fix eni rendering for bridge parameters which require repeated key for values
    
There are a few bridge parameters which require repeating the key with each
value in the list when rendering eni.  Extend the network unittests to cover
all of the known bridge parameters and check we render eni and netplan
correctly.
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~raharper/cloud-init:eni-bridge-multiline-keys into cloud-init:master.
diff --git a/cloudinit/net/eni.py b/cloudinit/net/eni.py
index 9819d4f..93be07f 100644
--- a/cloudinit/net/eni.py
+++ b/cloudinit/net/eni.py
@@ -75,6 +75,15 @@ def _iface_add_attrs(iface, index):
         'subnets',
         'type',
     ]
+
+    # The following parameters require repetitive entries of the key for
+    # each of the values
+    multiline_keys = [
+        'bridge_pathcost',
+        'bridge_portprio',
+        'bridge_waitport',
+    ]
+
     renames = {'mac_address': 'hwaddress'}
     if iface['type'] not in ['bond', 'bridge', 'vlan']:
         ignore_map.append('mac_address')
@@ -82,6 +91,10 @@ def _iface_add_attrs(iface, index):
     for key, value in iface.items():
         if not value or key in ignore_map:
             continue
+        if key in multiline_keys:
+            for v in value:
+                content.append("    {0} {1}".format(renames.get(key, key), v))
+            continue
         if type(value) == list:
             value = " ".join(value)
         content.append("    {0} {1}".format(renames.get(key, key), value))
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 167ed01..b3b5432 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -511,8 +511,20 @@ iface bond0 inet6 dhcp
 auto br0
 iface br0 inet static
     address 192.168.14.2/24
+    bridge_ageing 250
+    bridge_bridgeprio 22
+    bridge_fd 1
+    bridge_gcint 2
+    bridge_hello 1
+    bridge_maxage 10
+    bridge_pathcost eth3 50
+    bridge_pathcost eth4 75
+    bridge_portprio eth3 28
+    bridge_portprio eth4 14
     bridge_ports eth3 eth4
     bridge_stp off
+    bridge_waitport 1 eth3
+    bridge_waitport 2 eth4
 
 # control-alias br0
 iface br0 inet6 static
@@ -642,6 +654,15 @@ 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
+                        parameters:
+                            ageing-time: 250
+                            forward-delay: 1
+                            hello-time: 1
+                            max-age: 10
+                            path-cost:
+                                eth3: 50
+                                eth4: 75
+                            priority: 22
                 vlans:
                     bond0.200:
                         dhcp4: true
@@ -752,9 +773,23 @@ pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true
                       forwarding: 1
                       # basically anything in /proc/sys/net/ipv6/conf/.../
                   params:
-                      bridge_stp: 'off'
-                      bridge_fd: 0
+                      bridge_ageing: 250
+                      bridge_bridgeprio: 22
+                      bridge_fd: 1
+                      bridge_gcint: 2
+                      bridge_hello: 1
+                      bridge_maxage: 10
                       bridge_maxwait: 0
+                      bridge_pathcost:
+                        - eth3 50
+                        - eth4 75
+                      bridge_portprio:
+                        - eth3 28
+                        - eth4 14
+                      bridge_stp: 'off'
+                      bridge_waitport:
+                        - 1 eth3
+                        - 2 eth4
                   subnets:
                       - type: static
                         address: 192.168.14.2/24

Follow ups