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

Proposed by Ryan Harper
Status: Merged
Approved by: Scott Moser
Approved revision: 2b6f1a5d33f3b0398be20fcabab2e07e2a26b0fc
Merged at revision: 00b678c61a54f176625d3f937971215faf6af2cd
Proposed branch: ~raharper/cloud-init:eni-bridge-multiline-keys
Merge into: cloud-init:master
Diff against target: 98 lines (+50/-2)
2 files modified
cloudinit/net/eni.py (+13/-0)
tests/unittests/test_net.py (+37/-2)
Reviewer Review Type Date Requested Status
Scott Moser Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+324702@code.launchpad.net

Description of the change

Fix eni rendering for bridge params which require repeating key for vals

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.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) :
review: Approve

Update scan failed

At least one of the branches involved have failed to scan. You can manually schedule a rescan if required.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/net/eni.py b/cloudinit/net/eni.py
2index 9819d4f..93be07f 100644
3--- a/cloudinit/net/eni.py
4+++ b/cloudinit/net/eni.py
5@@ -75,6 +75,15 @@ def _iface_add_attrs(iface, index):
6 'subnets',
7 'type',
8 ]
9+
10+ # The following parameters require repetitive entries of the key for
11+ # each of the values
12+ multiline_keys = [
13+ 'bridge_pathcost',
14+ 'bridge_portprio',
15+ 'bridge_waitport',
16+ ]
17+
18 renames = {'mac_address': 'hwaddress'}
19 if iface['type'] not in ['bond', 'bridge', 'vlan']:
20 ignore_map.append('mac_address')
21@@ -82,6 +91,10 @@ def _iface_add_attrs(iface, index):
22 for key, value in iface.items():
23 if not value or key in ignore_map:
24 continue
25+ if key in multiline_keys:
26+ for v in value:
27+ content.append(" {0} {1}".format(renames.get(key, key), v))
28+ continue
29 if type(value) == list:
30 value = " ".join(value)
31 content.append(" {0} {1}".format(renames.get(key, key), value))
32diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
33index 167ed01..b3b5432 100644
34--- a/tests/unittests/test_net.py
35+++ b/tests/unittests/test_net.py
36@@ -511,8 +511,20 @@ iface bond0 inet6 dhcp
37 auto br0
38 iface br0 inet static
39 address 192.168.14.2/24
40+ bridge_ageing 250
41+ bridge_bridgeprio 22
42+ bridge_fd 1
43+ bridge_gcint 2
44+ bridge_hello 1
45+ bridge_maxage 10
46+ bridge_pathcost eth3 50
47+ bridge_pathcost eth4 75
48+ bridge_portprio eth3 28
49+ bridge_portprio eth4 14
50 bridge_ports eth3 eth4
51 bridge_stp off
52+ bridge_waitport 1 eth3
53+ bridge_waitport 2 eth4
54
55 # control-alias br0
56 iface br0 inet6 static
57@@ -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
58 interfaces:
59 - eth3
60 - eth4
61+ parameters:
62+ ageing-time: 250
63+ forward-delay: 1
64+ hello-time: 1
65+ max-age: 10
66+ path-cost:
67+ eth3: 50
68+ eth4: 75
69+ priority: 22
70 vlans:
71 bond0.200:
72 dhcp4: true
73@@ -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
74 forwarding: 1
75 # basically anything in /proc/sys/net/ipv6/conf/.../
76 params:
77- bridge_stp: 'off'
78- bridge_fd: 0
79+ bridge_ageing: 250
80+ bridge_bridgeprio: 22
81+ bridge_fd: 1
82+ bridge_gcint: 2
83+ bridge_hello: 1
84+ bridge_maxage: 10
85 bridge_maxwait: 0
86+ bridge_pathcost:
87+ - eth3 50
88+ - eth4 75
89+ bridge_portprio:
90+ - eth3 28
91+ - eth4 14
92+ bridge_stp: 'off'
93+ bridge_waitport:
94+ - 1 eth3
95+ - 2 eth4
96 subnets:
97 - type: static
98 address: 192.168.14.2/24

Subscribers

People subscribed via source and target branches