Merge lp:~mpontillo/maas/netplan--part2--tests into lp:~maas-committers/maas/trunk

Proposed by Mike Pontillo
Status: Superseded
Proposed branch: lp:~mpontillo/maas/netplan--part2--tests
Merge into: lp:~maas-committers/maas/trunk
Prerequisite: lp:~mpontillo/maas/netplan--part2
Diff against target: 186 lines (+171/-1)
1 file modified
src/maasserver/tests/test_preseed_network.py (+171/-1)
To merge this branch: bzr merge lp:~mpontillo/maas/netplan--part2--tests
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+317715@code.launchpad.net

This proposal has been superseded by a proposal from 2017-03-06.

Commit message

Implement tests for Netplan YAML.Support netplan (v2 YAML) rendering in the network preseed generator.

Drive-by fix to allow preseed YAML to be rendered for nodes with NULL IP addresses (such as AUTO addresses that have not been assigned yet) to be rendered (without those addresses). It would be nice if a special syntax existed for "TBD" addresses, so we could show these for debugging purposes.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/tests/test_preseed_network.py'
2--- src/maasserver/tests/test_preseed_network.py 2017-02-22 14:55:09 +0000
3+++ src/maasserver/tests/test_preseed_network.py 2017-03-06 09:05:41 +0000
4@@ -16,7 +16,10 @@
5 IPADDRESS_TYPE,
6 )
7 from maasserver.models.staticroute import StaticRoute
8-from maasserver.preseed_network import compose_curtin_network_config
9+from maasserver.preseed_network import (
10+ compose_curtin_network_config,
11+ NodeNetworkConfiguration,
12+)
13 from maasserver.testing.factory import factory
14 from maasserver.testing.testcase import MAASServerTestCase
15 from netaddr import IPNetwork
16@@ -461,3 +464,170 @@
17 net_config += self.collectDNSConfig(node)
18 config = compose_curtin_network_config(node)
19 self.assertNetworkConfig(net_config, config)
20+
21+
22+class TestNetplan(MAASServerTestCase):
23+
24+ def _render_netplan_dict(self, node):
25+ return NodeNetworkConfiguration(node, version=2).config
26+
27+ def test__single_ethernet_interface(self):
28+ node = factory.make_Node()
29+ factory.make_Interface(
30+ node=node, name='eth0', mac_address="00:01:02:03:04:05")
31+ netplan = self._render_netplan_dict(node)
32+ expected_netplan = {
33+ 'network': {
34+ 'version': 2,
35+ 'ethernets': {
36+ 'eth0': {
37+ 'match': {'macaddress': '00:01:02:03:04:05'},
38+ 'mtu': 1500,
39+ 'set-name': 'eth0'
40+ },
41+ },
42+ }
43+ }
44+ self.expectThat(netplan, Equals(expected_netplan))
45+
46+ def test__multiple_ethernet_interfaces(self):
47+ node = factory.make_Node()
48+ factory.make_Interface(
49+ node=node, name='eth0', mac_address="00:01:02:03:04:05")
50+ factory.make_Interface(
51+ node=node, name='eth1', mac_address="02:01:02:03:04:05")
52+ netplan = self._render_netplan_dict(node)
53+ expected_netplan = {
54+ 'network': {
55+ 'version': 2,
56+ 'ethernets': {
57+ 'eth0': {
58+ 'match': {'macaddress': '00:01:02:03:04:05'},
59+ 'mtu': 1500,
60+ 'set-name': 'eth0'
61+ },
62+ 'eth1': {
63+ 'match': {'macaddress': '02:01:02:03:04:05'},
64+ 'mtu': 1500,
65+ 'set-name': 'eth1'
66+ },
67+ },
68+ },
69+ }
70+ self.expectThat(netplan, Equals(expected_netplan))
71+
72+ def test__bond(self):
73+ node = factory.make_Node()
74+ eth0 = factory.make_Interface(
75+ node=node, name='eth0', mac_address="00:01:02:03:04:05")
76+ eth1 = factory.make_Interface(
77+ node=node, name='eth1', mac_address="02:01:02:03:04:05")
78+ factory.make_Interface(
79+ INTERFACE_TYPE.BOND,
80+ node=node, name='bond0', parents=[eth0, eth1])
81+ netplan = self._render_netplan_dict(node)
82+ expected_netplan = {
83+ 'network': {
84+ 'version': 2,
85+ 'ethernets': {
86+ 'eth0': {
87+ 'match': {'macaddress': '00:01:02:03:04:05'},
88+ 'mtu': 1500,
89+ 'set-name': 'eth0'
90+ },
91+ 'eth1': {
92+ 'match': {'macaddress': '02:01:02:03:04:05'},
93+ 'mtu': 1500,
94+ 'set-name': 'eth1'
95+ },
96+ },
97+ 'bonds': {
98+ 'bond0': {
99+ 'interfaces': ['eth0', 'eth1'],
100+ 'mtu': 1500
101+ },
102+ },
103+ }
104+ }
105+ self.expectThat(netplan, Equals(expected_netplan))
106+
107+ def test__bridge(self):
108+ node = factory.make_Node()
109+ eth0 = factory.make_Interface(
110+ node=node, name='eth0', mac_address="00:01:02:03:04:05")
111+ eth1 = factory.make_Interface(
112+ node=node, name='eth1', mac_address="02:01:02:03:04:05")
113+ factory.make_Interface(
114+ INTERFACE_TYPE.BRIDGE,
115+ node=node, name='br0', parents=[eth0, eth1])
116+ netplan = self._render_netplan_dict(node)
117+ expected_netplan = {
118+ 'network': {
119+ 'version': 2,
120+ 'ethernets': {
121+ 'eth0': {
122+ 'match': {'macaddress': '00:01:02:03:04:05'},
123+ 'mtu': 1500,
124+ 'set-name': 'eth0'
125+ },
126+ 'eth1': {
127+ 'match': {'macaddress': '02:01:02:03:04:05'},
128+ 'mtu': 1500,
129+ 'set-name': 'eth1'
130+ },
131+ },
132+ 'bridges': {
133+ 'br0': {
134+ 'interfaces': ['eth0', 'eth1'],
135+ 'mtu': 1500
136+ },
137+ },
138+ }
139+ }
140+ self.expectThat(netplan, Equals(expected_netplan))
141+
142+ def test__bridged_bond(self):
143+ node = factory.make_Node()
144+ eth0 = factory.make_Interface(
145+ node=node, name='eth0', mac_address="00:01:02:03:04:05")
146+ eth1 = factory.make_Interface(
147+ node=node, name='eth1', mac_address="02:01:02:03:04:05")
148+ bond0 = factory.make_Interface(
149+ INTERFACE_TYPE.BOND,
150+ node=node, name='bond0', parents=[eth0, eth1])
151+ factory.make_Interface(
152+ INTERFACE_TYPE.BRIDGE,
153+ node=node, name='br0', parents=[bond0])
154+ netplan = self._render_netplan_dict(node)
155+ expected_netplan = {
156+ 'network': {
157+ 'version': 2,
158+ 'ethernets': {
159+ 'eth0': {
160+ 'match': {'macaddress': '00:01:02:03:04:05'},
161+ 'mtu': 1500,
162+ 'set-name': 'eth0'
163+ },
164+ 'eth1': {
165+ 'match': {'macaddress': '02:01:02:03:04:05'},
166+ 'mtu': 1500,
167+ 'set-name': 'eth1'
168+ },
169+ },
170+ 'bonds': {
171+ 'bond0': {
172+ 'interfaces': ['eth0', 'eth1'],
173+ 'mtu': 1500
174+ },
175+ },
176+ 'bridges': {
177+ 'br0': {
178+ 'interfaces': ['bond0'],
179+ 'mtu': 1500
180+ },
181+ },
182+ }
183+ }
184+ self.expectThat(netplan, Equals(expected_netplan))
185+
186+