launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #11252
[Merge] lp:~jtv/maas/startup-refresh into lp:maas
Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/startup-refresh into lp:maas.
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~jtv/maas/startup-refresh/+merge/120915
As discussed with Julian. If the worker isn't picking up tasks yet, rabbit will retry so there is no worry about synchronization between webapp startup and celery startup.
I extracted the simple loop over all node groups; didn't really seem worth unit-testing on its own. Instead I integration-test it through its two call sites: API and startup. A future implementation might make use of celery broadcasts, but then again, I don't get the impression that it would buy us much.
Jeroen
--
https://code.launchpad.net/~jtv/maas/startup-refresh/+merge/120915
Your team MAAS Maintainers is requested to review the proposed merge of lp:~jtv/maas/startup-refresh into lp:maas.
=== modified file 'src/maasserver/api.py'
--- src/maasserver/api.py 2012-08-20 10:52:29 +0000
+++ src/maasserver/api.py 2012-08-23 05:23:15 +0000
@@ -124,7 +124,6 @@
Node,
NodeGroup,
)
-from maasserver.refresh_worker import refresh_worker
from piston.doc import generate_doc
from piston.handler import (
AnonymousBaseHandler,
@@ -881,8 +880,7 @@
does not know its node-group name or API credentials yet) but the
information will be sent only to the known workers.
"""
- for nodegroup in NodeGroup.objects.all():
- refresh_worker(nodegroup)
+ NodeGroup.objects.refresh_workers()
return HttpResponse("Sending worker refresh.", status=httplib.OK)
=== modified file 'src/maasserver/models/nodegroup.py'
--- src/maasserver/models/nodegroup.py 2012-08-21 11:09:22 +0000
+++ src/maasserver/models/nodegroup.py 2012-08-23 05:23:15 +0000
@@ -24,6 +24,7 @@
from maasserver import DefaultMeta
from maasserver.dhcp import is_dhcp_management_enabled
from maasserver.models.timestampedmodel import TimestampedModel
+from maasserver.refresh_worker import refresh_worker
from piston.models import (
KEY_SIZE,
Token,
@@ -95,6 +96,11 @@
"""For Django, a node group's name is a natural key."""
return self.get(name=name)
+ def refresh_workers(self):
+ """Send refresh tasks to all node-group workers."""
+ for nodegroup in self.all():
+ refresh_worker(nodegroup)
+
class NodeGroup(TimestampedModel):
=== modified file 'src/maasserver/start_up.py'
--- src/maasserver/start_up.py 2012-08-14 15:45:41 +0000
+++ src/maasserver/start_up.py 2012-08-23 05:23:15 +0000
@@ -60,3 +60,6 @@
# Regenerate MAAS's DNS configuration.
write_full_dns_config(reload_retry=True)
+
+ # Send secrets etc. to workers.
+ NodeGroup.objects.refresh_workers()
=== modified file 'src/maasserver/tests/test_start_up.py'
--- src/maasserver/tests/test_start_up.py 2012-08-15 04:02:30 +0000
+++ src/maasserver/tests/test_start_up.py 2012-08-23 05:23:15 +0000
@@ -23,13 +23,20 @@
)
from maasserver import start_up
from maasserver.models.nodegroup import NodeGroup
+from maastesting.celery import CeleryFixture
from maastesting.fakemethod import FakeMethod
from maastesting.testcase import TestCase
+from provisioningserver import tasks
+from testresources import FixtureResource
class TestStartUp(TestCase):
"""Testing for the method `start_up`."""
+ resources = (
+ ('celery', FixtureResource(CeleryFixture())),
+ )
+
def setUp(self):
super(TestStartUp, self).setUp()
self.patch(start_up, 'LOCK_FILE_NAME', self.make_file())
@@ -54,6 +61,15 @@
start_up.start_up()
self.assertEqual(1, NodeGroup.objects.all().count())
+ def test_start_up_refreshes_workers(self):
+ patched_handlers = tasks.refresh_functions.copy()
+ patched_handlers['nodegroup_name'] = FakeMethod()
+ self.patch(tasks, 'refresh_functions', patched_handlers)
+ start_up.start_up()
+ self.assertIn(
+ (NodeGroup.objects.ensure_master().name, ),
+ patched_handlers['nodegroup_name'].extract_args())
+
def test_start_up_runs_in_exclusion(self):
called = Value('b', False)