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
=== modified file 'src/maasserver/networking_preseed.py'
--- src/maasserver/networking_preseed.py 2014-10-02 04:14:09 +0000
+++ src/maasserver/networking_preseed.py 2014-10-02 13:17:35 +0000
@@ -25,10 +25,14 @@
2525
26__metaclass__ = type26__metaclass__ = type
27__all__ = [27__all__ = [
28 'compose_curtin_network_preseed_for',
28 'generate_networking_config',29 'generate_networking_config',
29 ]30 ]
3031
32import json
33
31from lxml import etree34from lxml import etree
35from maasserver.clusterrpc.osystems import compose_curtin_network_preseed
32from maasserver.dns.zonegenerator import get_dns_server_address36from maasserver.dns.zonegenerator import get_dns_server_address
33from maasserver.exceptions import UnresolvableHost37from maasserver.exceptions import UnresolvableHost
34from maasserver.models.nodeprobeddetails import get_probed_details38from maasserver.models.nodeprobeddetails import get_probed_details
@@ -317,3 +321,19 @@
317 if len(macs) == 0:321 if len(macs) == 0:
318 macs = node.macaddress_set.all()322 macs = node.macaddress_set.all()
319 return [normalise_mac(unicode(mac.mac_address)) for mac in macs]323 return [normalise_mac(unicode(mac.mac_address)) for mac in macs]
324
325
326def compose_curtin_network_preseed_for(node):
327 """Compose OS-dependent preseed for configuring networking on `node`.
328
329 :param node: A `Node`.
330 :return: A list of preseed strings.
331 """
332 config = {
333 'interfaces': extract_network_interfaces(node),
334 'auto_interfaces': find_macs_for_automatic_interfaces(node),
335 'ips_mapping': map_static_ips(node),
336 'gateways_mapping': map_gateways(node),
337 }
338 preseed = compose_curtin_network_preseed(node, config)
339 return [json.dumps(item) for item in preseed]
320340
=== modified file 'src/maasserver/preseed.py'
--- src/maasserver/preseed.py 2014-10-01 16:50:53 +0000
+++ src/maasserver/preseed.py 2014-10-02 13:17:35 +0000
@@ -52,6 +52,7 @@
52 Config,52 Config,
53 DHCPLease,53 DHCPLease,
54 )54 )
55from maasserver.networking_preseed import compose_curtin_network_preseed_for
55from maasserver.node_status import COMMISSIONING_LIKE_STATUSES56from maasserver.node_status import COMMISSIONING_LIKE_STATUSES
56from maasserver.server_address import get_maas_facing_server_host57from maasserver.server_address import get_maas_facing_server_host
57from maasserver.third_party_drivers import get_third_party_driver58from maasserver.third_party_drivers import get_third_party_driver
@@ -135,6 +136,7 @@
135 return [yaml.safe_dump(reporter)]136 return [yaml.safe_dump(reporter)]
136137
137138
139# This function is being replaced with compose_curtin_network_preseed_for.
138def compose_curtin_network_preseed(node):140def compose_curtin_network_preseed(node):
139 """Return a list of curtin preseeds for configuring a node's networking.141 """Return a list of curtin preseeds for configuring a node's networking.
140142
@@ -205,7 +207,7 @@
205 installer_url = get_curtin_installer_url(node)207 installer_url = get_curtin_installer_url(node)
206 main_config = get_curtin_config(node)208 main_config = get_curtin_config(node)
207 reporter_config = compose_curtin_maas_reporter(node)209 reporter_config = compose_curtin_maas_reporter(node)
208 network_config = compose_curtin_network_preseed(node)210 network_config = compose_curtin_network_preseed_for(node)
209 return pack_install(211 return pack_install(
210 configs=[main_config] + reporter_config + network_config,212 configs=[main_config] + reporter_config + network_config,
211 args=[installer_url])213 args=[installer_url])
212214
=== modified file 'src/maasserver/rpc/testing/mixins.py'
--- src/maasserver/rpc/testing/mixins.py 2014-09-10 16:20:31 +0000
+++ src/maasserver/rpc/testing/mixins.py 2014-10-02 13:17:35 +0000
@@ -22,14 +22,19 @@
22 RunningEventLoopFixture,22 RunningEventLoopFixture,
23 )23 )
24from maasserver.testing.factory import factory24from maasserver.testing.factory import factory
25from provisioningserver.rpc.cluster import GetPreseedData25from provisioningserver.rpc.cluster import (
26 ComposeCurtinNetworkPreseed,
27 GetPreseedData,
28 )
29from provisioningserver.rpc.testing import always_succeed_with
2630
2731
28class PreseedRPCMixin:32class PreseedRPCMixin:
29 """Set-up a live RPC environment for testing.33 """Set-up a live RPC environment for testing.
3034
31 It creates a cluster connected by RPC that responds to the35 It creates a cluster connected by RPC that responds to the
32 `GetPreseedData` call with a simple `NotImplementedError`.36 `GetPreseedData` call with a simple `NotImplementedError`. The
37 `ComposeCurtinNetworkPreseed` call returns an empty list.
3338
34 Tests that mix this in can use their ``rpc_cluster`` attribute (an39 Tests that mix this in can use their ``rpc_cluster`` attribute (an
35 instance of :py:class:`MockLiveRegionToClusterRPCFixture`) to control the40 instance of :py:class:`MockLiveRegionToClusterRPCFixture`) to control the
@@ -48,6 +53,8 @@
48 # GetPreseedData call with a simple NotImplementedError.53 # GetPreseedData call with a simple NotImplementedError.
49 self.rpc_nodegroup = factory.make_NodeGroup()54 self.rpc_nodegroup = factory.make_NodeGroup()
50 self.rpc_cluster = self.rpc_fixture.makeCluster(55 self.rpc_cluster = self.rpc_fixture.makeCluster(
51 self.rpc_nodegroup, GetPreseedData)56 self.rpc_nodegroup, GetPreseedData, ComposeCurtinNetworkPreseed)
52 self.rpc_cluster.GetPreseedData.side_effect = (57 self.rpc_cluster.GetPreseedData.side_effect = (
53 NotImplementedError())58 NotImplementedError())
59 self.rpc_cluster.ComposeCurtinNetworkPreseed.side_effect = (
60 always_succeed_with({'data': []}))
5461
=== modified file 'src/maasserver/tests/test_networking_preseed.py'
--- src/maasserver/tests/test_networking_preseed.py 2014-10-02 04:12:31 +0000
+++ src/maasserver/tests/test_networking_preseed.py 2014-10-02 13:17:35 +0000
@@ -15,6 +15,7 @@
15__all__ = [15__all__ = [
16 ]16 ]
1717
18import json
18from random import randint19from random import randint
1920
20from maasserver import networking_preseed21from maasserver import networking_preseed
@@ -26,6 +27,7 @@
26from maasserver.exceptions import UnresolvableHost27from maasserver.exceptions import UnresolvableHost
27from maasserver.networking_preseed import (28from maasserver.networking_preseed import (
28 add_ip_to_mapping,29 add_ip_to_mapping,
30 compose_curtin_network_preseed_for,
29 extract_mac_string,31 extract_mac_string,
30 extract_network_interfaces,32 extract_network_interfaces,
31 find_macs_for_automatic_interfaces,33 find_macs_for_automatic_interfaces,
@@ -43,6 +45,7 @@
43from maasserver.testing.factory import factory45from maasserver.testing.factory import factory
44from maasserver.testing.testcase import MAASServerTestCase46from maasserver.testing.testcase import MAASServerTestCase
45from maastesting.matchers import MockCalledOnceWith47from maastesting.matchers import MockCalledOnceWith
48from netaddr import IPAddress
46from testtools.matchers import HasLength49from testtools.matchers import HasLength
4750
4851
@@ -754,3 +757,51 @@
754 self.assertItemsEqual(757 self.assertItemsEqual(
755 [normalise_mac(unicode(mac1)), normalise_mac(unicode(mac2))],758 [normalise_mac(unicode(mac1)), normalise_mac(unicode(mac2))],
756 find_macs_for_automatic_interfaces(node))759 find_macs_for_automatic_interfaces(node))
760
761
762class TestComposeCurtinNetworkPreseedFor(MAASServerTestCase):
763
764 def test__composes_config(self):
765 fake = self.patch_autospec(
766 networking_preseed, 'compose_curtin_network_preseed')
767 fake.return_value = []
768 node = factory.make_Node()
769 node.nodegroup.accept()
770 network = factory.make_ipv4_network(slash=24)
771 router = factory.pick_ip_in_network(network)
772 static_low = unicode(IPAddress(network.first + 1))
773 static_high = unicode(IPAddress(network.first + 2))
774 dyn_low = unicode(IPAddress(network.first + 3))
775 dyn_high = unicode(IPAddress(network.first + 4))
776 interface = factory.make_NodeGroupInterface(
777 node.nodegroup, network=network, router_ip=router,
778 static_ip_range_low=static_low, static_ip_range_high=static_high,
779 ip_range_low=dyn_low, ip_range_high=dyn_high,
780 management=NODEGROUPINTERFACE_MANAGEMENT.DHCP)
781 mac = factory.make_MACAddress(node=node, cluster_interface=interface)
782 extract_interfaces = self.patch_autospec(
783 networking_preseed, 'extract_network_interfaces')
784 extract_interfaces.return_value = [mac.mac_address]
785
786 compose_curtin_network_preseed_for(node)
787
788 expected_config = {
789 'interfaces': [mac.mac_address],
790 'auto_interfaces': [mac.mac_address],
791 'ips_mapping': {},
792 'gateways_mapping': {mac.mac_address: [router]},
793 }
794 self.assertThat(fake, MockCalledOnceWith(node, expected_config))
795
796 def test__returns_preseeds_as_list_of_text(self):
797 fake = self.patch_autospec(
798 networking_preseed, 'compose_curtin_network_preseed')
799 preseed_data = {factory.make_name('key'): factory.make_name('value')}
800 fake.return_value = [preseed_data]
801 node = factory.make_Node()
802
803 preseed = compose_curtin_network_preseed_for(node)
804
805 self.assertIsInstance(preseed, list)
806 [data] = preseed
807 self.assertEqual(preseed_data, json.loads(data))
757808
=== modified file 'src/maasserver/tests/test_preseed.py'
--- src/maasserver/tests/test_preseed.py 2014-09-25 19:38:57 +0000
+++ src/maasserver/tests/test_preseed.py 2014-10-02 13:17:35 +0000
@@ -74,6 +74,7 @@
74from maasserver.utils import absolute_reverse74from maasserver.utils import absolute_reverse
75from maastesting.matchers import MockCalledOnceWith75from maastesting.matchers import MockCalledOnceWith
76from metadataserver.models import NodeKey76from metadataserver.models import NodeKey
77from mock import ANY
77from provisioningserver.rpc.exceptions import NoConnectionsAvailable78from provisioningserver.rpc.exceptions import NoConnectionsAvailable
78from provisioningserver.utils import locate_config79from provisioningserver.utils import locate_config
79from provisioningserver.utils.enum import map_enum80from provisioningserver.utils.enum import map_enum
@@ -885,8 +886,14 @@
885 node.nodegroup, management=NODEGROUPINTERFACE_MANAGEMENT.DHCP)886 node.nodegroup, management=NODEGROUPINTERFACE_MANAGEMENT.DHCP)
886 arch, subarch = node.architecture.split('/')887 arch, subarch = node.architecture.split('/')
887 self.configure_get_boot_images_for_node(node, 'xinstall')888 self.configure_get_boot_images_for_node(node, 'xinstall')
889
888 user_data = get_curtin_userdata(node)890 user_data = get_curtin_userdata(node)
889 # Just check that the user data looks good.891
892 self.expectThat(
893 self.rpc_cluster.ComposeCurtinNetworkPreseed,
894 MockCalledOnceWith(
895 ANY, osystem=node.get_osystem(), config=ANY,
896 disable_ipv4=node.disable_ipv4))
890 self.assertIn("PREFIX='curtin'", user_data)897 self.assertIn("PREFIX='curtin'", user_data)
891898
892899