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
=== modified file 'HACKING.txt'
--- HACKING.txt 2012-09-17 14:25:54 +0000
+++ HACKING.txt 2012-09-24 06:50:26 +0000
@@ -270,23 +270,32 @@
270^^^^^^^^^^^^^^^^270^^^^^^^^^^^^^^^^
271271
272MAAS requires a properly configured DHCP server so it can boot machines using272MAAS requires a properly configured DHCP server so it can boot machines using
273PXE. MAAS works with the ISC DHCP server; install it if it's not already273PXE. MAAS can work with its own instance of the ISC DHCP server, if you
274installed::274install the maas-dhcp package::
275275
276 $ sudo apt-get install isc-dhcp-server276 $ sudo apt-get install maas-dhcp
277277
278There is a tool to generate a configuration that will work with MAAS::278If you choose to run your own ISC DHCP server, there is a bit more
279configuration to do. First, run this tool to generate a configuration that
280will work with MAAS::
279281
280 $ maas-provision generate-dhcp-config [options]282 $ maas-provision generate-dhcp-config [options]
281283
282Run ``maas-provision generate-dhcp-config -h`` to see the options. You will284Run ``maas-provision generate-dhcp-config -h`` to see the options. You will
283need to provide various IP details such as the range of IP addresses to assign285need to provide various IP details such as the range of IP addresses to assign
284to clients. You can use the generated output to configure your system's ISC286to clients. You can use the generated output to configure your system's ISC
285DHCP server, by putting the configuration in the ``/etc/dhcp/dhcpd.conf`` file.287DHCP server, by inserting the configuration in the ``/etc/dhcp/dhcpd.conf``
288file.
289
290Also, edit /etc/default/isc-dhcp-server to set the INTERFACES variable to just
291the network interfaces that should be serviced by this DHCP server.
286292
287Now restart dhcpd::293Now restart dhcpd::
288294
289 $ sudo /etc/init.d/isc-dhcp-server restart295 $ sudo service isc-dhcp-server restart
296
297None of this work is needed if you let MAAS run its own DHCP server by
298installing ``maas-dhcp``.
290299
291300
292Development services301Development services
293302
=== modified file 'etc/celeryconfig.py'
--- etc/celeryconfig.py 2012-09-20 12:53:00 +0000
+++ etc/celeryconfig.py 2012-09-24 06:50:26 +0000
@@ -35,10 +35,13 @@
35DNS_RNDC_PORT = 95435DNS_RNDC_PORT = 954
3636
37# DHCP leases file, as maintained by ISC dhcpd.37# DHCP leases file, as maintained by ISC dhcpd.
38DHCP_LEASES_FILE = '/var/lib/dhcp/dhcpd.leases'38DHCP_LEASES_FILE = '/var/lib/maas/dhcpd.leases'
3939
40# ISC dhcpd configuration file.40# ISC dhcpd configuration file.
41DHCP_CONFIG_FILE = '/etc/dhcp/dhcpd.conf'41DHCP_CONFIG_FILE = '/etc/maas/dhcpd.conf'
42
43# List of interfaces that the dhcpd should service (if managed by MAAS).
44DHCP_INTERFACES_FILE = '/var/lib/maas/dhcpd-interfaces'
4245
43# Broken connection information.46# Broken connection information.
44# Format: transport://userid:password@hostname:port/virtual_host47# Format: transport://userid:password@hostname:port/virtual_host
4548
=== modified file 'src/maasserver/models/nodegroup.py'
--- src/maasserver/models/nodegroup.py 2012-09-20 15:10:21 +0000
+++ src/maasserver/models/nodegroup.py 2012-09-24 06:50:26 +0000
@@ -30,13 +30,18 @@
30from maasserver.models.nodegroupinterface import NodeGroupInterface30from maasserver.models.nodegroupinterface import NodeGroupInterface
31from maasserver.models.timestampedmodel import TimestampedModel31from maasserver.models.timestampedmodel import TimestampedModel
32from maasserver.refresh_worker import refresh_worker32from maasserver.refresh_worker import refresh_worker
33from maasserver.server_address import get_maas_facing_server_address
33from maasserver.utils.orm import get_one34from maasserver.utils.orm import get_one
35from netaddr import IPAddress
34from piston.models import (36from piston.models import (
35 KEY_SIZE,37 KEY_SIZE,
36 Token,38 Token,
37 )39 )
38from provisioningserver.omshell import generate_omapi_key40from provisioningserver.omshell import generate_omapi_key
39from provisioningserver.tasks import add_new_dhcp_host_map41from provisioningserver.tasks import (
42 add_new_dhcp_host_map,
43 write_dhcp_config,
44 )
4045
4146
42class NodeGroupManager(Manager):47class NodeGroupManager(Manager):
4348
=== modified file 'src/maasserver/tests/test_nodegroup.py'
--- src/maasserver/tests/test_nodegroup.py 2012-09-19 13:48:42 +0000
+++ src/maasserver/tests/test_nodegroup.py 2012-09-24 06:50:26 +0000
@@ -12,11 +12,15 @@
12__metaclass__ = type12__metaclass__ = type
13__all__ = []13__all__ = []
1414
15from django.conf import settings
16import maasserver
17from maasserver.dns import get_dns_server_address
15from maasserver.enum import (18from maasserver.enum import (
16 NODEGROUP_STATUS,19 NODEGROUP_STATUS,
17 NODEGROUPINTERFACE_MANAGEMENT,20 NODEGROUPINTERFACE_MANAGEMENT,
18 )21 )
19from maasserver.models import NodeGroup22from maasserver.models import NodeGroup
23from maasserver.server_address import get_maas_facing_server_address
20from maasserver.testing import reload_object24from maasserver.testing import reload_object
21from maasserver.testing.factory import factory25from maasserver.testing.factory import factory
22from maasserver.testing.testcase import TestCase26from maasserver.testing.testcase import TestCase
2327
=== modified file 'src/provisioningserver/tasks.py'
--- src/provisioningserver/tasks.py 2012-09-17 06:46:55 +0000
+++ src/provisioningserver/tasks.py 2012-09-24 06:50:26 +0000
@@ -29,7 +29,10 @@
29 )29 )
3030
31from celery.task import task31from celery.task import task
32from celeryconfig import DHCP_CONFIG_FILE32from celeryconfig import (
33 DHCP_CONFIG_FILE,
34 DHCP_INTERFACES_FILE,
35 )
33from provisioningserver import boot_images36from provisioningserver import boot_images
34from provisioningserver.auth import (37from provisioningserver.auth import (
35 record_api_credentials,38 record_api_credentials,
@@ -306,18 +309,19 @@
306def write_dhcp_config(**kwargs):309def write_dhcp_config(**kwargs):
307 """Write out the DHCP configuration file and restart the DHCP server.310 """Write out the DHCP configuration file and restart the DHCP server.
308311
312 :param dhcp_interfaces: Space-separated list of interfaces that the
313 DHCP server should listen on.
309 :param **kwargs: Keyword args passed to dhcp.config.get_config()314 :param **kwargs: Keyword args passed to dhcp.config.get_config()
310 """315 """
311 sudo_write_file(316 sudo_write_file(DHCP_CONFIG_FILE, config.get_config(**kwargs))
312 DHCP_CONFIG_FILE, config.get_config(**kwargs), encoding='ascii',317 sudo_write_file(DHCP_INTERFACES_FILE, kwargs.get('dhcp_interfaces', ''))
313 mode=0744)
314 restart_dhcp_server()318 restart_dhcp_server()
315319
316320
317@task321@task
318def restart_dhcp_server():322def restart_dhcp_server():
319 """Restart the DHCP server."""323 """Restart the DHCP server."""
320 check_call(['sudo', 'service', 'isc-dhcp-server', 'restart'])324 check_call(['sudo', '-n', 'service', 'maas-dhcp-server', 'restart'])
321325
322326
323# =====================================================================327# =====================================================================
324328
=== modified file 'src/provisioningserver/tests/test_tasks.py'
--- src/provisioningserver/tests/test_tasks.py 2012-09-17 10:55:11 +0000
+++ src/provisioningserver/tests/test_tasks.py 2012-09-24 06:50:26 +0000
@@ -24,7 +24,10 @@
24from apiclient.creds import convert_tuple_to_string24from apiclient.creds import convert_tuple_to_string
25from apiclient.maas_client import MAASClient25from apiclient.maas_client import MAASClient
26from apiclient.testing.credentials import make_api_credentials26from apiclient.testing.credentials import make_api_credentials
27from celeryconfig import DHCP_CONFIG_FILE27from celeryconfig import (
28 DHCP_CONFIG_FILE,
29 DHCP_INTERFACES_FILE,
30 )
28from maastesting.celery import CeleryFixture31from maastesting.celery import CeleryFixture
29from maastesting.factory import factory32from maastesting.factory import factory
30from maastesting.fakemethod import (33from maastesting.fakemethod import (
@@ -255,18 +258,24 @@
255 content = config.get_config(**config_params).encode("ascii")258 content = config.get_config(**config_params).encode("ascii")
256 mocked_proc.communicate.assert_any_call(content)259 mocked_proc.communicate.assert_any_call(content)
257260
261 # Similarly, it also writes the DHCPD interfaces to
262 # /var/lib/maas/dhcpd-interfaces.
263 mocked_popen.assert_any_call(
264 ["sudo", "-n", "maas-provision", "atomic-write", "--filename",
265 DHCP_INTERFACES_FILE, "--mode", "0744"], stdin=PIPE)
266
258 # Finally it should restart the dhcp server.267 # Finally it should restart the dhcp server.
259 check_call_args = mocked_check_call.call_args268 check_call_args = mocked_check_call.call_args
260 self.assertEqual(269 self.assertEqual(
261 check_call_args[0][0],270 check_call_args[0][0],
262 ['sudo', 'service', 'isc-dhcp-server', 'restart'])271 ['sudo', '-n', 'service', 'maas-dhcp-server', 'restart'])
263272
264 def test_restart_dhcp_server_sends_command(self):273 def test_restart_dhcp_server_sends_command(self):
265 recorder = FakeMethod()274 recorder = FakeMethod()
266 self.patch(tasks, 'check_call', recorder)275 self.patch(tasks, 'check_call', recorder)
267 restart_dhcp_server()276 restart_dhcp_server()
268 self.assertEqual(277 self.assertEqual(
269 (1, (['sudo', 'service', 'isc-dhcp-server', 'restart'],)),278 (1, (['sudo', '-n', 'service', 'maas-dhcp-server', 'restart'],)),
270 (recorder.call_count, recorder.extract_args()[0]))279 (recorder.call_count, recorder.extract_args()[0]))
271280
272281