launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #11296
[Merge] lp:~julian-edwards/maas/dhcp-task into lp:maas
Julian Edwards has proposed merging lp:~julian-edwards/maas/dhcp-task into lp:maas.
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~julian-edwards/maas/dhcp-task/+merge/121151
--
https://code.launchpad.net/~julian-edwards/maas/dhcp-task/+merge/121151
Your team MAAS Maintainers is requested to review the proposed merge of lp:~julian-edwards/maas/dhcp-task into lp:maas.
=== modified file 'src/maasserver/management/commands/config_master_dhcp.py'
--- src/maasserver/management/commands/config_master_dhcp.py 2012-07-19 03:01:45 +0000
+++ src/maasserver/management/commands/config_master_dhcp.py 2012-08-24 10:12:32 +0000
@@ -25,7 +25,10 @@
)
from django.core.management.base import BaseCommand
-from maasserver.models import NodeGroup
+from maasserver.models import (
+ Config,
+ NodeGroup,
+ )
dhcp_items = {
@@ -95,3 +98,8 @@
for item, value in settings.items():
setattr(master_nodegroup, item, value)
master_nodegroup.save()
+
+ # If DHCP management is enabled, create a Task that will
+ # write the config out.
+ if Config.objects.get_config('manage_dhcp'):
+ master_nodegroup.set_up_dhcp()
=== modified file 'src/maasserver/tests/test_commands_config_master_dhcp.py'
--- src/maasserver/tests/test_commands_config_master_dhcp.py 2012-08-07 21:15:54 +0000
+++ src/maasserver/tests/test_commands_config_master_dhcp.py 2012-08-24 10:12:32 +0000
@@ -15,10 +15,15 @@
from optparse import OptionValueError
from django.core.management import call_command
+from mock import Mock
from maasserver.management.commands.config_master_dhcp import name_option
-from maasserver.models import NodeGroup
+from maasserver.models import (
+ Config,
+ NodeGroup,
+ )
from maasserver.testing.factory import factory
from maasserver.testing.testcase import TestCase
+from provisioningserver import tasks
from testtools.matchers import MatchesStructure
@@ -50,6 +55,15 @@
class TestConfigMasterDHCP(TestCase):
+ def setUp(self):
+ super(TestConfigMasterDHCP, self).setUp()
+ # Make sure any attempts to write a dhcp config end up in a temp
+ # file rather than the system one.
+ conf_file = self.make_file(contents=factory.getRandomString())
+ self.patch(tasks, "DHCP_CONFIG_FILE", conf_file)
+ # Prevent DHCPD restarts.
+ self.patch(tasks, 'check_call', Mock())
+
def test_configures_dhcp_for_master_nodegroup(self):
settings = make_dhcp_settings()
call_command('config_master_dhcp', **settings)
@@ -117,3 +131,19 @@
def test_name_option_turns_dhcp_setting_name_into_option(self):
self.assertEqual('--subnet-mask', name_option('subnet_mask'))
+
+ def test_sets_up_dhcp_if_dhcp_enabled(self):
+ master = NodeGroup.objects.ensure_master()
+ self.patch(NodeGroup, 'set_up_dhcp', Mock())
+ settings = make_dhcp_settings()
+ Config.objects.set_config('manage_dhcp', True)
+ call_command('config_master_dhcp', **settings)
+ self.assertEqual(1, master.set_up_dhcp.call_count)
+
+ def test_ignores_set_up_dhcp_if_dhcp_disabled(self):
+ master = NodeGroup.objects.ensure_master()
+ self.patch(NodeGroup, 'set_up_dhcp', Mock())
+ settings = make_dhcp_settings()
+ Config.objects.set_config('manage_dhcp', False)
+ call_command('config_master_dhcp', **settings)
+ self.assertEqual(0, master.set_up_dhcp.call_count)