Merge lp:~jtv/maas/custom-dhcp 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: 1055
Proposed branch: lp:~jtv/maas/custom-dhcp
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 189 lines (+53/-19)
6 files modified
HACKING.txt (+17/-8)
etc/celeryconfig.py (+5/-2)
src/maasserver/models/nodegroup.py (+6/-1)
src/maasserver/tests/test_nodegroup.py (+4/-0)
src/provisioningserver/tasks.py (+9/-5)
src/provisioningserver/tests/test_tasks.py (+12/-3)
To merge this branch: bzr merge lp:~jtv/maas/custom-dhcp
Reviewer Review Type Date Requested Status
John A Meinel (community) Approve
Review via email: mp+124671@code.launchpad.net

Commit message

Use our own dhcpd instance, so we can tell it which network interfaces to service.

This must be accompanied by a matching packaging change which installs the maas-dhcp-server Upstart script as part of maas-dhcp.

As a drive-by, I added the “-n” option to a sudo command. Makes sudo fail if it would need to prompt for a password.

Description of the change

The “sudo -n” was Raphaël's suggestion. The accompanying packaging branch is at https://code.launchpad.net/~jtv/maas/packaging-custom-dhcpd/+merge/124594

Jeroen

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

Would it make sense to gather up all the files that need to be written under sudo and do them with one call rather than several? Do we get a decent error message up to users if sudo fails because of '-n' (or just a stacktrace in python because the command failed?)

Otherwise looks fine to me.

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

Good questions — and luckily I provided answers in my predecessor branch! In that preparatory branch I extracted the sudo_write_file helper, and in view of Raphaël's painful debugging experience, made it check sudo's return code and report sudo's error message. I haven't looked into how that message gets displayed, really, so there may be separate work to be done on that.

I see some value in bundling up the rewriting of files, but there isn't much to bundle anyway. Plus it's all done synchronously to service restarts, so arguably the real value would be in ensuring that we retry on failure.

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

Attempt to merge into lp:maas failed due to conflicts:

text conflict in src/maasserver/models/nodegroup.py
text conflict in src/maasserver/tests/test_nodegroup.py

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'HACKING.txt'
2--- HACKING.txt 2012-09-17 14:25:54 +0000
3+++ HACKING.txt 2012-09-24 06:50:26 +0000
4@@ -270,23 +270,32 @@
5 ^^^^^^^^^^^^^^^^
6
7 MAAS requires a properly configured DHCP server so it can boot machines using
8-PXE. MAAS works with the ISC DHCP server; install it if it's not already
9-installed::
10-
11- $ sudo apt-get install isc-dhcp-server
12-
13-There is a tool to generate a configuration that will work with MAAS::
14+PXE. MAAS can work with its own instance of the ISC DHCP server, if you
15+install the maas-dhcp package::
16+
17+ $ sudo apt-get install maas-dhcp
18+
19+If you choose to run your own ISC DHCP server, there is a bit more
20+configuration to do. First, run this tool to generate a configuration that
21+will work with MAAS::
22
23 $ maas-provision generate-dhcp-config [options]
24
25 Run ``maas-provision generate-dhcp-config -h`` to see the options. You will
26 need to provide various IP details such as the range of IP addresses to assign
27 to clients. You can use the generated output to configure your system's ISC
28-DHCP server, by putting the configuration in the ``/etc/dhcp/dhcpd.conf`` file.
29+DHCP server, by inserting the configuration in the ``/etc/dhcp/dhcpd.conf``
30+file.
31+
32+Also, edit /etc/default/isc-dhcp-server to set the INTERFACES variable to just
33+the network interfaces that should be serviced by this DHCP server.
34
35 Now restart dhcpd::
36
37- $ sudo /etc/init.d/isc-dhcp-server restart
38+ $ sudo service isc-dhcp-server restart
39+
40+None of this work is needed if you let MAAS run its own DHCP server by
41+installing ``maas-dhcp``.
42
43
44 Development services
45
46=== modified file 'etc/celeryconfig.py'
47--- etc/celeryconfig.py 2012-09-20 12:53:00 +0000
48+++ etc/celeryconfig.py 2012-09-24 06:50:26 +0000
49@@ -35,10 +35,13 @@
50 DNS_RNDC_PORT = 954
51
52 # DHCP leases file, as maintained by ISC dhcpd.
53-DHCP_LEASES_FILE = '/var/lib/dhcp/dhcpd.leases'
54+DHCP_LEASES_FILE = '/var/lib/maas/dhcpd.leases'
55
56 # ISC dhcpd configuration file.
57-DHCP_CONFIG_FILE = '/etc/dhcp/dhcpd.conf'
58+DHCP_CONFIG_FILE = '/etc/maas/dhcpd.conf'
59+
60+# List of interfaces that the dhcpd should service (if managed by MAAS).
61+DHCP_INTERFACES_FILE = '/var/lib/maas/dhcpd-interfaces'
62
63 # Broken connection information.
64 # Format: transport://userid:password@hostname:port/virtual_host
65
66=== modified file 'src/maasserver/models/nodegroup.py'
67--- src/maasserver/models/nodegroup.py 2012-09-20 15:10:21 +0000
68+++ src/maasserver/models/nodegroup.py 2012-09-24 06:50:26 +0000
69@@ -30,13 +30,18 @@
70 from maasserver.models.nodegroupinterface import NodeGroupInterface
71 from maasserver.models.timestampedmodel import TimestampedModel
72 from maasserver.refresh_worker import refresh_worker
73+from maasserver.server_address import get_maas_facing_server_address
74 from maasserver.utils.orm import get_one
75+from netaddr import IPAddress
76 from piston.models import (
77 KEY_SIZE,
78 Token,
79 )
80 from provisioningserver.omshell import generate_omapi_key
81-from provisioningserver.tasks import add_new_dhcp_host_map
82+from provisioningserver.tasks import (
83+ add_new_dhcp_host_map,
84+ write_dhcp_config,
85+ )
86
87
88 class NodeGroupManager(Manager):
89
90=== modified file 'src/maasserver/tests/test_nodegroup.py'
91--- src/maasserver/tests/test_nodegroup.py 2012-09-19 13:48:42 +0000
92+++ src/maasserver/tests/test_nodegroup.py 2012-09-24 06:50:26 +0000
93@@ -12,11 +12,15 @@
94 __metaclass__ = type
95 __all__ = []
96
97+from django.conf import settings
98+import maasserver
99+from maasserver.dns import get_dns_server_address
100 from maasserver.enum import (
101 NODEGROUP_STATUS,
102 NODEGROUPINTERFACE_MANAGEMENT,
103 )
104 from maasserver.models import NodeGroup
105+from maasserver.server_address import get_maas_facing_server_address
106 from maasserver.testing import reload_object
107 from maasserver.testing.factory import factory
108 from maasserver.testing.testcase import TestCase
109
110=== modified file 'src/provisioningserver/tasks.py'
111--- src/provisioningserver/tasks.py 2012-09-17 06:46:55 +0000
112+++ src/provisioningserver/tasks.py 2012-09-24 06:50:26 +0000
113@@ -29,7 +29,10 @@
114 )
115
116 from celery.task import task
117-from celeryconfig import DHCP_CONFIG_FILE
118+from celeryconfig import (
119+ DHCP_CONFIG_FILE,
120+ DHCP_INTERFACES_FILE,
121+ )
122 from provisioningserver import boot_images
123 from provisioningserver.auth import (
124 record_api_credentials,
125@@ -306,18 +309,19 @@
126 def write_dhcp_config(**kwargs):
127 """Write out the DHCP configuration file and restart the DHCP server.
128
129+ :param dhcp_interfaces: Space-separated list of interfaces that the
130+ DHCP server should listen on.
131 :param **kwargs: Keyword args passed to dhcp.config.get_config()
132 """
133- sudo_write_file(
134- DHCP_CONFIG_FILE, config.get_config(**kwargs), encoding='ascii',
135- mode=0744)
136+ sudo_write_file(DHCP_CONFIG_FILE, config.get_config(**kwargs))
137+ sudo_write_file(DHCP_INTERFACES_FILE, kwargs.get('dhcp_interfaces', ''))
138 restart_dhcp_server()
139
140
141 @task
142 def restart_dhcp_server():
143 """Restart the DHCP server."""
144- check_call(['sudo', 'service', 'isc-dhcp-server', 'restart'])
145+ check_call(['sudo', '-n', 'service', 'maas-dhcp-server', 'restart'])
146
147
148 # =====================================================================
149
150=== modified file 'src/provisioningserver/tests/test_tasks.py'
151--- src/provisioningserver/tests/test_tasks.py 2012-09-17 10:55:11 +0000
152+++ src/provisioningserver/tests/test_tasks.py 2012-09-24 06:50:26 +0000
153@@ -24,7 +24,10 @@
154 from apiclient.creds import convert_tuple_to_string
155 from apiclient.maas_client import MAASClient
156 from apiclient.testing.credentials import make_api_credentials
157-from celeryconfig import DHCP_CONFIG_FILE
158+from celeryconfig import (
159+ DHCP_CONFIG_FILE,
160+ DHCP_INTERFACES_FILE,
161+ )
162 from maastesting.celery import CeleryFixture
163 from maastesting.factory import factory
164 from maastesting.fakemethod import (
165@@ -255,18 +258,24 @@
166 content = config.get_config(**config_params).encode("ascii")
167 mocked_proc.communicate.assert_any_call(content)
168
169+ # Similarly, it also writes the DHCPD interfaces to
170+ # /var/lib/maas/dhcpd-interfaces.
171+ mocked_popen.assert_any_call(
172+ ["sudo", "-n", "maas-provision", "atomic-write", "--filename",
173+ DHCP_INTERFACES_FILE, "--mode", "0744"], stdin=PIPE)
174+
175 # Finally it should restart the dhcp server.
176 check_call_args = mocked_check_call.call_args
177 self.assertEqual(
178 check_call_args[0][0],
179- ['sudo', 'service', 'isc-dhcp-server', 'restart'])
180+ ['sudo', '-n', 'service', 'maas-dhcp-server', 'restart'])
181
182 def test_restart_dhcp_server_sends_command(self):
183 recorder = FakeMethod()
184 self.patch(tasks, 'check_call', recorder)
185 restart_dhcp_server()
186 self.assertEqual(
187- (1, (['sudo', 'service', 'isc-dhcp-server', 'restart'],)),
188+ (1, (['sudo', '-n', 'service', 'maas-dhcp-server', 'restart'],)),
189 (recorder.call_count, recorder.extract_args()[0]))
190
191