Merge ~larsks/cloud-init:lp/1665441 into cloud-init:master

Proposed by Lars Kellogg-Stedman
Status: Merged
Merged at revision: f81d6c7bde2af206d449de593b35773068270c84
Proposed branch: ~larsks/cloud-init:lp/1665441
Merge into: cloud-init:master
Diff against target: 123 lines (+88/-3)
2 files modified
cloudinit/net/sysconfig.py (+2/-2)
tests/unittests/test_net.py (+86/-1)
Reviewer Review Type Date Requested Status
cloud-init Commiters Pending
Review via email: mp+317553@code.launchpad.net

Description of the change

This corrects the problem reported in #1665441. The resulting files are incompatible with NetworkManager, but will work correctly in a legacy networking environment.

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

Lars,
Thanks so much for investigating and finding a fix.

I hate it when I provide a fix for a bug in someone's code and they ask for a unit test.

That said...
A unit test here will avoid a regression in the future. Could you add one?

If you don't add one, then I'm going to, and it will just take me longer to pull it.

~larsks/cloud-init:lp/1665441 updated
5e8bd6b... by Lars Kellogg-Stedman

unit tests for #1665441

This adds inputs and outputs to OS_SAMPLES to test the code path for a
network configuration that provides multiple subnets on the same
interface. This test will fail until the fix for #1665441 is
committed.

LP: #1665441

Revision history for this message
Lars Kellogg-Stedman (larsks) wrote :

I've added a unit test.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
2index 9be7407..19e220a 100644
3--- a/cloudinit/net/sysconfig.py
4+++ b/cloudinit/net/sysconfig.py
5@@ -283,10 +283,10 @@ class Renderer(renderer.Renderer):
6 cls._render_subnet(iface_cfg, route_cfg, iface_subnets[0])
7 elif len(iface_subnets) > 1:
8 for i, iface_subnet in enumerate(iface_subnets,
9- start=len(iface.children)):
10+ start=len(iface_cfg.children)):
11 iface_sub_cfg = iface_cfg.copy()
12 iface_sub_cfg.name = "%s:%s" % (iface_name, i)
13- iface.children.append(iface_sub_cfg)
14+ iface_cfg.children.append(iface_sub_cfg)
15 cls._render_subnet(iface_sub_cfg, route_cfg, iface_subnet)
16
17 @classmethod
18diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
19index b77d277..1b6288d 100644
20--- a/tests/unittests/test_net.py
21+++ b/tests/unittests/test_net.py
22@@ -163,6 +163,91 @@ nameserver 172.19.0.12
23 ('etc/udev/rules.d/70-persistent-net.rules',
24 "".join(['SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ',
25 'ATTR{address}=="fa:16:3e:ed:9a:59", NAME="eth0"\n']))]
26+ },
27+ {
28+ 'in_data': {
29+ "services": [{"type": "dns", "address": "172.19.0.12"}],
30+ "networks": [{
31+ "network_id": "public-ipv4",
32+ "type": "ipv4", "netmask": "255.255.252.0",
33+ "link": "tap1a81968a-79",
34+ "routes": [{
35+ "netmask": "0.0.0.0",
36+ "network": "0.0.0.0",
37+ "gateway": "172.19.3.254",
38+ }],
39+ "ip_address": "172.19.1.34", "id": "network0"
40+ },{
41+ "network_id": "private-ipv4",
42+ "type": "ipv4", "netmask": "255.255.255.0",
43+ "link": "tap1a81968a-79",
44+ "routes": [],
45+ "ip_address": "10.0.0.10", "id": "network1"
46+ }],
47+ "links": [
48+ {
49+ "ethernet_mac_address": "fa:16:3e:ed:9a:59",
50+ "mtu": None, "type": "bridge", "id":
51+ "tap1a81968a-79",
52+ "vif_id": "1a81968a-797a-400f-8a80-567f997eb93f"
53+ },
54+ ],
55+ },
56+ 'in_macs': {
57+ 'fa:16:3e:ed:9a:59': 'eth0',
58+ },
59+ 'out_sysconfig': [
60+ ('etc/sysconfig/network-scripts/ifcfg-eth0',
61+ """
62+# Created by cloud-init on instance boot automatically, do not edit.
63+#
64+BOOTPROTO=none
65+DEVICE=eth0
66+HWADDR=fa:16:3e:ed:9a:59
67+NM_CONTROLLED=no
68+ONBOOT=yes
69+TYPE=Ethernet
70+USERCTL=no
71+""".lstrip()),
72+ ('etc/sysconfig/network-scripts/ifcfg-eth0:0',
73+ """
74+# Created by cloud-init on instance boot automatically, do not edit.
75+#
76+BOOTPROTO=static
77+DEFROUTE=yes
78+DEVICE=eth0:0
79+GATEWAY=172.19.3.254
80+HWADDR=fa:16:3e:ed:9a:59
81+IPADDR=172.19.1.34
82+NETMASK=255.255.252.0
83+NM_CONTROLLED=no
84+ONBOOT=yes
85+TYPE=Ethernet
86+USERCTL=no
87+""".lstrip()),
88+ ('etc/sysconfig/network-scripts/ifcfg-eth0:1',
89+ """
90+# Created by cloud-init on instance boot automatically, do not edit.
91+#
92+BOOTPROTO=static
93+DEVICE=eth0:1
94+HWADDR=fa:16:3e:ed:9a:59
95+IPADDR=10.0.0.10
96+NETMASK=255.255.255.0
97+NM_CONTROLLED=no
98+ONBOOT=yes
99+TYPE=Ethernet
100+USERCTL=no
101+""".lstrip()),
102+ ('etc/resolv.conf',
103+ """
104+; Created by cloud-init on instance boot automatically, do not edit.
105+;
106+nameserver 172.19.0.12
107+""".lstrip()),
108+ ('etc/udev/rules.d/70-persistent-net.rules',
109+ "".join(['SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ',
110+ 'ATTR{address}=="fa:16:3e:ed:9a:59", NAME="eth0"\n']))]
111 }
112 ]
113
114@@ -529,8 +614,8 @@ USERCTL=no
115 self.assertEqual(expected_content, content)
116
117 def test_openstack_rendering_samples(self):
118- render_dir = self.tmp_dir()
119 for os_sample in OS_SAMPLES:
120+ render_dir = self.tmp_dir()
121 ex_input = os_sample['in_data']
122 ex_mac_addrs = os_sample['in_macs']
123 network_cfg = openstack.convert_net_json(

Subscribers

People subscribed via source and target branches