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

Proposed by Graham Binns
Status: Merged
Approved by: Graham Binns
Approved revision: 3062
Merged at revision: 3062
Proposed branch: lp:~gmb/maas/fix-netboot_off
Merge into: lp: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
1=== modified file 'src/metadataserver/api.py'
2--- src/metadataserver/api.py 2014-09-23 12:16:45 +0000
3+++ src/metadataserver/api.py 2014-09-23 15:20:04 +0000
4@@ -304,16 +304,6 @@
5 """
6 node = get_queried_node(request, for_mac=mac)
7 node.set_netboot(False)
8-
9- # Build and register an event for "node installation finished".
10- # This is a best-guess. At the moment, netboot_off() only gets
11- # called when the node has finished installing, so it's an
12- # accurate predictor of the end of the install process.
13- type_name = EVENT_TYPES.NODE_INSTALLATION_FINISHED
14- event_details = EVENT_DETAILS[type_name]
15- Event.objects.register_event_and_event_type(
16- node.system_id, type_name, type_level=event_details.level,
17- event_description=event_details.description)
18 return rc.ALL_OK
19
20 @operation(idempotent=False)
21@@ -507,4 +497,15 @@
22 """
23 node = get_object_or_404(Node, system_id=system_id)
24 node.set_netboot(False)
25+
26+ # Build and register an event for "node installation finished".
27+ # This is a best-guess. At the moment, netboot_off() only gets
28+ # called when the node has finished installing, so it's an
29+ # accurate predictor of the end of the install process.
30+ type_name = EVENT_TYPES.NODE_INSTALLATION_FINISHED
31+ event_details = EVENT_DETAILS[type_name]
32+ Event.objects.register_event_and_event_type(
33+ node.system_id, type_name, type_level=event_details.level,
34+ type_description=event_details.description,
35+ event_description="Node disabled netboot")
36 return rc.ALL_OK
37
38=== modified file 'src/metadataserver/tests/test_api.py'
39--- src/metadataserver/tests/test_api.py 2014-09-23 12:16:45 +0000
40+++ src/metadataserver/tests/test_api.py 2014-09-23 15:20:04 +0000
41@@ -890,23 +890,6 @@
42 node = reload_object(node)
43 self.assertTrue(node.netboot, response)
44
45- def test_netboot_off_adds_installation_finished_event(self):
46- node = factory.make_Node(netboot=True)
47- client = make_node_client(node=node)
48- url = reverse('metadata-version', args=['latest'])
49- client.post(url, {'op': 'netboot_off'})
50- latest_event = Event.objects.filter(node=node).last()
51- self.assertEqual(
52- (
53- EVENT_TYPES.NODE_INSTALLATION_FINISHED,
54- EVENT_DETAILS[
55- EVENT_TYPES.NODE_INSTALLATION_FINISHED].description
56- ),
57- (
58- latest_event.type.name,
59- latest_event.description,
60- ))
61-
62
63 class TestAnonymousAPI(DjangoTestCase):
64
65@@ -974,6 +957,26 @@
66 response.content),
67 response)
68
69+ def test_anoymous_netboot_off_adds_installation_finished_event(self):
70+ node = factory.make_Node(netboot=True)
71+ anon_netboot_off_url = reverse(
72+ 'metadata-node-by-id', args=['latest', node.system_id])
73+ self.client.post(
74+ anon_netboot_off_url, {'op': 'netboot_off'})
75+ latest_event = Event.objects.filter(node=node).last()
76+ self.assertEqual(
77+ (
78+ EVENT_TYPES.NODE_INSTALLATION_FINISHED,
79+ EVENT_DETAILS[
80+ EVENT_TYPES.NODE_INSTALLATION_FINISHED].description,
81+ "Node disabled netboot",
82+ ),
83+ (
84+ latest_event.type.name,
85+ latest_event.type.description,
86+ latest_event.description,
87+ ))
88+
89
90 class TestEnlistViews(DjangoTestCase):
91 """Tests for the enlistment metadata views."""