Merge lp:~gmb/maas/fix-netboot_off into lp:~maas-committers/maas/trunk

Proposed by Graham Binns
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 3062
Proposed branch: lp:~gmb/maas/fix-netboot_off
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 91 lines (+31/-27)
2 files modified
src/metadataserver/api.py (+11/-10)
src/metadataserver/tests/test_api.py (+20/-17)
To merge this branch: bzr merge lp:~gmb/maas/fix-netboot_off
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+235659@code.launchpad.net

Commit message

Move the emission of the "installation finished" event to the anonymous API handler in metadataserver.api; previously it was on the non-anonymous handler and was never getting called.

Also fixed a bug in the emission code itself so that the description is set meaningfully.

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/metadataserver/api.py'
--- src/metadataserver/api.py 2014-09-23 12:16:45 +0000
+++ src/metadataserver/api.py 2014-09-23 15:20:04 +0000
@@ -304,16 +304,6 @@
304 """304 """
305 node = get_queried_node(request, for_mac=mac)305 node = get_queried_node(request, for_mac=mac)
306 node.set_netboot(False)306 node.set_netboot(False)
307
308 # Build and register an event for "node installation finished".
309 # This is a best-guess. At the moment, netboot_off() only gets
310 # called when the node has finished installing, so it's an
311 # accurate predictor of the end of the install process.
312 type_name = EVENT_TYPES.NODE_INSTALLATION_FINISHED
313 event_details = EVENT_DETAILS[type_name]
314 Event.objects.register_event_and_event_type(
315 node.system_id, type_name, type_level=event_details.level,
316 event_description=event_details.description)
317 return rc.ALL_OK307 return rc.ALL_OK
318308
319 @operation(idempotent=False)309 @operation(idempotent=False)
@@ -507,4 +497,15 @@
507 """497 """
508 node = get_object_or_404(Node, system_id=system_id)498 node = get_object_or_404(Node, system_id=system_id)
509 node.set_netboot(False)499 node.set_netboot(False)
500
501 # Build and register an event for "node installation finished".
502 # This is a best-guess. At the moment, netboot_off() only gets
503 # called when the node has finished installing, so it's an
504 # accurate predictor of the end of the install process.
505 type_name = EVENT_TYPES.NODE_INSTALLATION_FINISHED
506 event_details = EVENT_DETAILS[type_name]
507 Event.objects.register_event_and_event_type(
508 node.system_id, type_name, type_level=event_details.level,
509 type_description=event_details.description,
510 event_description="Node disabled netboot")
510 return rc.ALL_OK511 return rc.ALL_OK
511512
=== modified file 'src/metadataserver/tests/test_api.py'
--- src/metadataserver/tests/test_api.py 2014-09-23 12:16:45 +0000
+++ src/metadataserver/tests/test_api.py 2014-09-23 15:20:04 +0000
@@ -890,23 +890,6 @@
890 node = reload_object(node)890 node = reload_object(node)
891 self.assertTrue(node.netboot, response)891 self.assertTrue(node.netboot, response)
892892
893 def test_netboot_off_adds_installation_finished_event(self):
894 node = factory.make_Node(netboot=True)
895 client = make_node_client(node=node)
896 url = reverse('metadata-version', args=['latest'])
897 client.post(url, {'op': 'netboot_off'})
898 latest_event = Event.objects.filter(node=node).last()
899 self.assertEqual(
900 (
901 EVENT_TYPES.NODE_INSTALLATION_FINISHED,
902 EVENT_DETAILS[
903 EVENT_TYPES.NODE_INSTALLATION_FINISHED].description
904 ),
905 (
906 latest_event.type.name,
907 latest_event.description,
908 ))
909
910893
911class TestAnonymousAPI(DjangoTestCase):894class TestAnonymousAPI(DjangoTestCase):
912895
@@ -974,6 +957,26 @@
974 response.content),957 response.content),
975 response)958 response)
976959
960 def test_anoymous_netboot_off_adds_installation_finished_event(self):
961 node = factory.make_Node(netboot=True)
962 anon_netboot_off_url = reverse(
963 'metadata-node-by-id', args=['latest', node.system_id])
964 self.client.post(
965 anon_netboot_off_url, {'op': 'netboot_off'})
966 latest_event = Event.objects.filter(node=node).last()
967 self.assertEqual(
968 (
969 EVENT_TYPES.NODE_INSTALLATION_FINISHED,
970 EVENT_DETAILS[
971 EVENT_TYPES.NODE_INSTALLATION_FINISHED].description,
972 "Node disabled netboot",
973 ),
974 (
975 latest_event.type.name,
976 latest_event.type.description,
977 latest_event.description,
978 ))
979
977980
978class TestEnlistViews(DjangoTestCase):981class TestEnlistViews(DjangoTestCase):
979 """Tests for the enlistment metadata views."""982 """Tests for the enlistment metadata views."""