Merge lp:~jtv/maas/use-compose-curtin-network-preseed into lp:~maas-committers/maas/trunk

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 3178
Proposed branch: lp:~jtv/maas/use-compose-curtin-network-preseed
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 209 lines (+92/-5)
5 files modified
src/maasserver/networking_preseed.py (+20/-0)
src/maasserver/preseed.py (+3/-1)
src/maasserver/rpc/testing/mixins.py (+10/-3)
src/maasserver/tests/test_networking_preseed.py (+51/-0)
src/maasserver/tests/test_preseed.py (+8/-1)
To merge this branch: bzr merge lp:~jtv/maas/use-compose-curtin-network-preseed
Reviewer Review Type Date Requested Status
Graham Binns (community) Approve
Review via email: mp+236824@code.launchpad.net

Commit message

Configure networking on a node (when using Curtin) by asking the operating system driver on the cluster controller to generate configuration from scratch.

For now, that means “on Ubuntu generate /etc/network/interfaces and /etc/udev/rules.d/70-persistent-net.rules, and otherwise, do nothing.” This replaces the code that uploaded a script to the node if the OS was Ubuntu, and executed it to amend networking config.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

Approved, with comments; something needs to change w.r.t exception handling, but there are a couple of ways you can do it, so I'll leave it up to you.

review: Approve
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Removed the pointless exception transformations. Thanks for figuring that out.

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Yay! It comes through the CI and it can deploy nodes. Still working to get a node without IPv4 set up though.

Revision history for this message
MAAS Lander (maas-lander) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (19.5 KiB)

The attempt to merge lp:~jtv/maas/use-compose-curtin-network-preseed into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Get:2 http://security.ubuntu.com trusty-security Release [59.7 kB]
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Get:4 http://nova.clouds.archive.ubuntu.com trusty-updates Release [59.7 kB]
Get:5 http://security.ubuntu.com trusty-security/main Sources [46.3 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Get:6 http://security.ubuntu.com trusty-security/universe Sources [10.8 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Get:7 http://security.ubuntu.com trusty-security/main amd64 Packages [146 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Get:8 http://security.ubuntu.com trusty-security/universe amd64 Packages [49.0 kB]
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Get:9 http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources [125 kB]
Get:10 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources [86.2 kB]
Get:11 http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [337 kB]
Get:12 http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [209 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en
Fetched 1,130 kB in 0s (1,886 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb curl daemontools debhelper dh-apport distro-info dnsutils firefox freeipmi-tools ipython isc-dhcp-common libjs-raphael libjs-yui3-full libjs-yui3-min libpq-dev make pep8 postgresql pyflakes python-amqplib python-bzrlib python-celery python-convoy python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-jinja2 python-jsonschema python-lockfile python-lxml python-mimeparse python-mock python-netaddr python-netifaces python-nose python-oauth python-oops python-oops-amqp python-oops-datedir-repo python-oops-twisted python-oops-wsgi p...

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Lint from review change: imports became unused!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/networking_preseed.py'
2--- src/maasserver/networking_preseed.py 2014-10-02 04:14:09 +0000
3+++ src/maasserver/networking_preseed.py 2014-10-02 13:17:35 +0000
4@@ -25,10 +25,14 @@
5
6 __metaclass__ = type
7 __all__ = [
8+ 'compose_curtin_network_preseed_for',
9 'generate_networking_config',
10 ]
11
12+import json
13+
14 from lxml import etree
15+from maasserver.clusterrpc.osystems import compose_curtin_network_preseed
16 from maasserver.dns.zonegenerator import get_dns_server_address
17 from maasserver.exceptions import UnresolvableHost
18 from maasserver.models.nodeprobeddetails import get_probed_details
19@@ -317,3 +321,19 @@
20 if len(macs) == 0:
21 macs = node.macaddress_set.all()
22 return [normalise_mac(unicode(mac.mac_address)) for mac in macs]
23+
24+
25+def compose_curtin_network_preseed_for(node):
26+ """Compose OS-dependent preseed for configuring networking on `node`.
27+
28+ :param node: A `Node`.
29+ :return: A list of preseed strings.
30+ """
31+ config = {
32+ 'interfaces': extract_network_interfaces(node),
33+ 'auto_interfaces': find_macs_for_automatic_interfaces(node),
34+ 'ips_mapping': map_static_ips(node),
35+ 'gateways_mapping': map_gateways(node),
36+ }
37+ preseed = compose_curtin_network_preseed(node, config)
38+ return [json.dumps(item) for item in preseed]
39
40=== modified file 'src/maasserver/preseed.py'
41--- src/maasserver/preseed.py 2014-10-01 16:50:53 +0000
42+++ src/maasserver/preseed.py 2014-10-02 13:17:35 +0000
43@@ -52,6 +52,7 @@
44 Config,
45 DHCPLease,
46 )
47+from maasserver.networking_preseed import compose_curtin_network_preseed_for
48 from maasserver.node_status import COMMISSIONING_LIKE_STATUSES
49 from maasserver.server_address import get_maas_facing_server_host
50 from maasserver.third_party_drivers import get_third_party_driver
51@@ -135,6 +136,7 @@
52 return [yaml.safe_dump(reporter)]
53
54
55+# This function is being replaced with compose_curtin_network_preseed_for.
56 def compose_curtin_network_preseed(node):
57 """Return a list of curtin preseeds for configuring a node's networking.
58
59@@ -205,7 +207,7 @@
60 installer_url = get_curtin_installer_url(node)
61 main_config = get_curtin_config(node)
62 reporter_config = compose_curtin_maas_reporter(node)
63- network_config = compose_curtin_network_preseed(node)
64+ network_config = compose_curtin_network_preseed_for(node)
65 return pack_install(
66 configs=[main_config] + reporter_config + network_config,
67 args=[installer_url])
68
69=== modified file 'src/maasserver/rpc/testing/mixins.py'
70--- src/maasserver/rpc/testing/mixins.py 2014-09-10 16:20:31 +0000
71+++ src/maasserver/rpc/testing/mixins.py 2014-10-02 13:17:35 +0000
72@@ -22,14 +22,19 @@
73 RunningEventLoopFixture,
74 )
75 from maasserver.testing.factory import factory
76-from provisioningserver.rpc.cluster import GetPreseedData
77+from provisioningserver.rpc.cluster import (
78+ ComposeCurtinNetworkPreseed,
79+ GetPreseedData,
80+ )
81+from provisioningserver.rpc.testing import always_succeed_with
82
83
84 class PreseedRPCMixin:
85 """Set-up a live RPC environment for testing.
86
87 It creates a cluster connected by RPC that responds to the
88- `GetPreseedData` call with a simple `NotImplementedError`.
89+ `GetPreseedData` call with a simple `NotImplementedError`. The
90+ `ComposeCurtinNetworkPreseed` call returns an empty list.
91
92 Tests that mix this in can use their ``rpc_cluster`` attribute (an
93 instance of :py:class:`MockLiveRegionToClusterRPCFixture`) to control the
94@@ -48,6 +53,8 @@
95 # GetPreseedData call with a simple NotImplementedError.
96 self.rpc_nodegroup = factory.make_NodeGroup()
97 self.rpc_cluster = self.rpc_fixture.makeCluster(
98- self.rpc_nodegroup, GetPreseedData)
99+ self.rpc_nodegroup, GetPreseedData, ComposeCurtinNetworkPreseed)
100 self.rpc_cluster.GetPreseedData.side_effect = (
101 NotImplementedError())
102+ self.rpc_cluster.ComposeCurtinNetworkPreseed.side_effect = (
103+ always_succeed_with({'data': []}))
104
105=== modified file 'src/maasserver/tests/test_networking_preseed.py'
106--- src/maasserver/tests/test_networking_preseed.py 2014-10-02 04:12:31 +0000
107+++ src/maasserver/tests/test_networking_preseed.py 2014-10-02 13:17:35 +0000
108@@ -15,6 +15,7 @@
109 __all__ = [
110 ]
111
112+import json
113 from random import randint
114
115 from maasserver import networking_preseed
116@@ -26,6 +27,7 @@
117 from maasserver.exceptions import UnresolvableHost
118 from maasserver.networking_preseed import (
119 add_ip_to_mapping,
120+ compose_curtin_network_preseed_for,
121 extract_mac_string,
122 extract_network_interfaces,
123 find_macs_for_automatic_interfaces,
124@@ -43,6 +45,7 @@
125 from maasserver.testing.factory import factory
126 from maasserver.testing.testcase import MAASServerTestCase
127 from maastesting.matchers import MockCalledOnceWith
128+from netaddr import IPAddress
129 from testtools.matchers import HasLength
130
131
132@@ -754,3 +757,51 @@
133 self.assertItemsEqual(
134 [normalise_mac(unicode(mac1)), normalise_mac(unicode(mac2))],
135 find_macs_for_automatic_interfaces(node))
136+
137+
138+class TestComposeCurtinNetworkPreseedFor(MAASServerTestCase):
139+
140+ def test__composes_config(self):
141+ fake = self.patch_autospec(
142+ networking_preseed, 'compose_curtin_network_preseed')
143+ fake.return_value = []
144+ node = factory.make_Node()
145+ node.nodegroup.accept()
146+ network = factory.make_ipv4_network(slash=24)
147+ router = factory.pick_ip_in_network(network)
148+ static_low = unicode(IPAddress(network.first + 1))
149+ static_high = unicode(IPAddress(network.first + 2))
150+ dyn_low = unicode(IPAddress(network.first + 3))
151+ dyn_high = unicode(IPAddress(network.first + 4))
152+ interface = factory.make_NodeGroupInterface(
153+ node.nodegroup, network=network, router_ip=router,
154+ static_ip_range_low=static_low, static_ip_range_high=static_high,
155+ ip_range_low=dyn_low, ip_range_high=dyn_high,
156+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP)
157+ mac = factory.make_MACAddress(node=node, cluster_interface=interface)
158+ extract_interfaces = self.patch_autospec(
159+ networking_preseed, 'extract_network_interfaces')
160+ extract_interfaces.return_value = [mac.mac_address]
161+
162+ compose_curtin_network_preseed_for(node)
163+
164+ expected_config = {
165+ 'interfaces': [mac.mac_address],
166+ 'auto_interfaces': [mac.mac_address],
167+ 'ips_mapping': {},
168+ 'gateways_mapping': {mac.mac_address: [router]},
169+ }
170+ self.assertThat(fake, MockCalledOnceWith(node, expected_config))
171+
172+ def test__returns_preseeds_as_list_of_text(self):
173+ fake = self.patch_autospec(
174+ networking_preseed, 'compose_curtin_network_preseed')
175+ preseed_data = {factory.make_name('key'): factory.make_name('value')}
176+ fake.return_value = [preseed_data]
177+ node = factory.make_Node()
178+
179+ preseed = compose_curtin_network_preseed_for(node)
180+
181+ self.assertIsInstance(preseed, list)
182+ [data] = preseed
183+ self.assertEqual(preseed_data, json.loads(data))
184
185=== modified file 'src/maasserver/tests/test_preseed.py'
186--- src/maasserver/tests/test_preseed.py 2014-09-25 19:38:57 +0000
187+++ src/maasserver/tests/test_preseed.py 2014-10-02 13:17:35 +0000
188@@ -74,6 +74,7 @@
189 from maasserver.utils import absolute_reverse
190 from maastesting.matchers import MockCalledOnceWith
191 from metadataserver.models import NodeKey
192+from mock import ANY
193 from provisioningserver.rpc.exceptions import NoConnectionsAvailable
194 from provisioningserver.utils import locate_config
195 from provisioningserver.utils.enum import map_enum
196@@ -885,8 +886,14 @@
197 node.nodegroup, management=NODEGROUPINTERFACE_MANAGEMENT.DHCP)
198 arch, subarch = node.architecture.split('/')
199 self.configure_get_boot_images_for_node(node, 'xinstall')
200+
201 user_data = get_curtin_userdata(node)
202- # Just check that the user data looks good.
203+
204+ self.expectThat(
205+ self.rpc_cluster.ComposeCurtinNetworkPreseed,
206+ MockCalledOnceWith(
207+ ANY, osystem=node.get_osystem(), config=ANY,
208+ disable_ipv4=node.disable_ipv4))
209 self.assertIn("PREFIX='curtin'", user_data)
210
211