Merge lp:~rvb/maas/check-commissioning-bug-1084292-1.2 into lp:maas/1.2

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 1333
Proposed branch: lp:~rvb/maas/check-commissioning-bug-1084292-1.2
Merge into: lp:maas/1.2
Diff against target: 110 lines (+38/-23)
2 files modified
src/maasserver/api.py (+17/-15)
src/maasserver/tests/test_api.py (+21/-8)
To merge this branch: bzr merge lp:~rvb/maas/check-commissioning-bug-1084292-1.2
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+137796@code.launchpad.net

Commit message

Backport revision 1392.

Description of the change

Backport revision 1392.

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/api.py'
--- src/maasserver/api.py 2012-12-04 04:05:17 +0000
+++ src/maasserver/api.py 2012-12-04 10:32:25 +0000
@@ -707,21 +707,6 @@
707 """Accept a node's enlistment: not allowed to anonymous users."""707 """Accept a node's enlistment: not allowed to anonymous users."""
708 raise Unauthorized("You must be logged in to accept nodes.")708 raise Unauthorized("You must be logged in to accept nodes.")
709709
710 @operation(idempotent=False)
711 def check_commissioning(self, request):
712 """Check all commissioning nodes to see if they are taking too long.
713
714 Anything that has been commissioning for longer than
715 settings.COMMISSIONING_TIMEOUT is moved into the FAILED_TESTS status.
716 """
717 interval = timedelta(minutes=settings.COMMISSIONING_TIMEOUT)
718 cutoff = datetime.now() - interval
719 query = Node.objects.filter(
720 status=NODE_STATUS.COMMISSIONING, updated__lte=cutoff)
721 query.update(status=NODE_STATUS.FAILED_TESTS)
722 # Note that Django doesn't call save() on updated nodes here,
723 # but I don't think anything requires its effects anyway.
724
725 @classmethod710 @classmethod
726 def resource_uri(cls, *args, **kwargs):711 def resource_uri(cls, *args, **kwargs):
727 return ('nodes_handler', [])712 return ('nodes_handler', [])
@@ -840,6 +825,23 @@
840 return filter(None, nodes)825 return filter(None, nodes)
841826
842 @operation(idempotent=False)827 @operation(idempotent=False)
828 def check_commissioning(self, request):
829 """Check all commissioning nodes to see if they are taking too long.
830
831 Anything that has been commissioning for longer than
832 settings.COMMISSIONING_TIMEOUT is moved into the FAILED_TESTS status.
833 """
834 interval = timedelta(minutes=settings.COMMISSIONING_TIMEOUT)
835 cutoff = datetime.now() - interval
836 query = Node.objects.filter(
837 status=NODE_STATUS.COMMISSIONING, updated__lte=cutoff)
838 results = list(query)
839 query.update(status=NODE_STATUS.FAILED_TESTS)
840 # Note that Django doesn't call save() on updated nodes here,
841 # but I don't think anything requires its effects anyway.
842 return results
843
844 @operation(idempotent=False)
843 def release(self, request):845 def release(self, request):
844 """Release multiple nodes.846 """Release multiple nodes.
845847
846848
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2012-12-04 04:26:52 +0000
+++ src/maasserver/tests/test_api.py 2012-12-04 10:32:25 +0000
@@ -3346,24 +3346,28 @@
3346 (response.status_code, response.content))3346 (response.status_code, response.content))
33473347
33483348
3349class TestAnonymousCommissioningTimeout(APIv10TestMixin, TestCase):3349class TestCommissioningTimeout(APIv10TestMixin, LoggedInTestCase):
3350 """Testing of commissioning timeout API."""3350 """Testing of commissioning timeout API."""
33513351
3352 def test_check_with_no_action(self):3352 def test_check_with_no_action(self):
3353 node = factory.make_node(status=NODE_STATUS.READY)3353 node = factory.make_node(status=NODE_STATUS.READY)
3354 self.client.post(3354 response = self.client.post(
3355 self.get_uri('nodes/'), {'op': 'check_commissioning'})3355 self.get_uri('nodes/'), {'op': 'check_commissioning'})
3356 # Anything that's not commissioning should be ignored.3356 # Anything that's not commissioning should be ignored.
3357 node = reload_object(node)3357 node = reload_object(node)
3358 self.assertEqual(NODE_STATUS.READY, node.status)3358 self.assertEqual(
3359 (httplib.OK, NODE_STATUS.READY),
3360 (response.status_code, node.status))
33593361
3360 def test_check_with_commissioning_but_not_expired_node(self):3362 def test_check_with_commissioning_but_not_expired_node(self):
3361 node = factory.make_node(3363 node = factory.make_node(
3362 status=NODE_STATUS.COMMISSIONING)3364 status=NODE_STATUS.COMMISSIONING)
3363 self.client.post(3365 response = self.client.post(
3364 self.get_uri('nodes/'), {'op': 'check_commissioning'})3366 self.get_uri('nodes/'), {'op': 'check_commissioning'})
3365 node = reload_object(node)3367 node = reload_object(node)
3366 self.assertEqual(NODE_STATUS.COMMISSIONING, node.status)3368 self.assertEqual(
3369 (httplib.OK, NODE_STATUS.COMMISSIONING),
3370 (response.status_code, node.status))
33673371
3368 def test_check_with_commissioning_and_expired_node(self):3372 def test_check_with_commissioning_and_expired_node(self):
3369 # Have an interval 1 second longer than the timeout.3373 # Have an interval 1 second longer than the timeout.
@@ -3373,10 +3377,19 @@
3373 status=NODE_STATUS.COMMISSIONING, created=datetime.now(),3377 status=NODE_STATUS.COMMISSIONING, created=datetime.now(),
3374 updated=updated_at)3378 updated=updated_at)
33753379
3376 self.client.post(3380 response = self.client.post(
3377 self.get_uri('nodes/'), {'op': 'check_commissioning'})3381 self.get_uri('nodes/'), {'op': 'check_commissioning'})
3378 node = reload_object(node)3382 self.assertEqual(
3379 self.assertEqual(NODE_STATUS.FAILED_TESTS, node.status)3383 (
3384 httplib.OK,
3385 NODE_STATUS.FAILED_TESTS,
3386 [node.system_id]
3387 ),
3388 (
3389 response.status_code,
3390 reload_object(node).status,
3391 [node['system_id'] for node in json.loads(response.content)],
3392 ))
33803393
33813394
3382class TestPXEConfigAPI(AnonAPITestCase):3395class TestPXEConfigAPI(AnonAPITestCase):

Subscribers

People subscribed via source and target branches

to status/vote changes: