launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #10740
[Merge] lp:~rvb/maas/set-up-method into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/set-up-method into lp:maas with lp:~rvb/maas/dns-setting-cleanup as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/maas/set-up-method/+merge/118756
This branch adds a start_up method responsible for initializing the application when in starts up (that method is called from wsgi.py [prod environment] and from the 'runserver' command [demo environment]).
It simply refactors the existing calls into the start_up method and also adds the call the DNS config writing task.
Note that I choose to create a separate module for this method because I wanted to make clear that it was called at very special times and had very specific restrictions (see the method's docstring).
--
https://code.launchpad.net/~rvb/maas/set-up-method/+merge/118756
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/set-up-method into lp:maas.
=== modified file 'contrib/wsgi.py'
--- contrib/wsgi.py 2012-08-01 09:30:17 +0000
+++ contrib/wsgi.py 2012-08-08 15:08:22 +0000
@@ -26,8 +26,5 @@
os.environ['DJANGO_SETTINGS_MODULE'] = 'maas.settings'
application = django.core.handlers.wsgi.WSGIHandler()
-from maasserver.maasavahi import setup_maas_avahi_service
-setup_maas_avahi_service()
-
-from maasserver.models import NodeGroup
-NodeGroup.objects.ensure_master()
+from maasserver.start_up import start_up
+start_up()
=== modified file 'src/maasserver/management/commands/runserver.py'
--- src/maasserver/management/commands/runserver.py 2012-06-22 20:24:20 +0000
+++ src/maasserver/management/commands/runserver.py 2012-08-08 15:08:22 +0000
@@ -19,7 +19,7 @@
from django.core.management.commands.runserver import BaseRunserverCommand
from django.core.servers import basehttp
from django.core.servers.basehttp import WSGIServer
-from maasserver.maasavahi import setup_maas_avahi_service
+from maasserver.start_up import start_up
import oops
from oops_datedir_repo import DateDirRepo
from oops_wsgi import (
@@ -68,7 +68,7 @@
# Monkey patch basehttp.WSGIServer.
setattr(basehttp, 'WSGIServer', ThreadedWSGIServer)
- setup_maas_avahi_service()
+ start_up()
return super(Command, self).run(*args, **options)
def get_handler(self, *args, **kwargs):
=== added file 'src/maasserver/start_up.py'
--- src/maasserver/start_up.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/start_up.py 2012-08-08 15:08:22 +0000
@@ -0,0 +1,42 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Start up utilities for the MAAS server."""
+
+from __future__ import (
+ absolute_import,
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = [
+ 'start_up'
+ ]
+
+
+from maasserver.dns import write_full_dns_config
+from maasserver.maasavahi import setup_maas_avahi_service
+from maasserver.models import NodeGroup
+
+
+def start_up():
+ """Start up this MAAS server.
+
+ This is used to:
+ - make sure the singletons required by the application are created
+ - sync the configuration of the external systems driven by MAAS
+
+ This method is called when the MAAS application starts up.
+ In production, it's called from the WSGI script so this shouldn't block
+ at any costs. It should simply call very simple methods or Celery tasks.
+ """
+
+ # Publish the MAAS server existence over Avahi.
+ setup_maas_avahi_service()
+
+ # Make sure that the master nodegroup is created.
+ NodeGroup.objects.ensure_master()
+
+ # Regenerate MAAS's DNS configuration.
+ write_full_dns_config(reload_retry=True)
=== added file 'src/maasserver/tests/test_start_up.py'
--- src/maasserver/tests/test_start_up.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/tests/test_start_up.py 2012-08-08 15:08:22 +0000
@@ -0,0 +1,42 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Test the start up utility."""
+
+from __future__ import (
+ absolute_import,
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = []
+
+from maasserver import start_up
+from maasserver.models.nodegroup import NodeGroup
+from maastesting.fakemethod import FakeMethod
+from maastesting.testcase import TestCase
+
+
+class TestStartUp(TestCase):
+ """Testing for the method `start_up`."""
+
+ def test_start_up_calls_setup_maas_avahi_service(self):
+ recorder = FakeMethod()
+ self.patch(start_up, 'setup_maas_avahi_service', recorder)
+ start_up.start_up()
+ self.assertEqual(
+ (1, [()]),
+ (recorder.call_count, recorder.extract_args()))
+
+ def test_start_up_calls_write_full_dns_config(self):
+ recorder = FakeMethod()
+ self.patch(start_up, 'write_full_dns_config', recorder)
+ start_up.start_up()
+ self.assertEqual(
+ (1, [()]),
+ (recorder.call_count, recorder.extract_args()))
+
+ def test_start_up_creates_master_nodegroup(self):
+ start_up.start_up()
+ self.assertEqual(1, NodeGroup.objects.all().count())