Merge lp:~rvb/maas/node-trans-log into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 3829
Proposed branch: lp:~rvb/maas/node-trans-log
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 84 lines (+25/-6)
3 files modified
src/maasserver/event_connect.py (+1/-1)
src/maasserver/models/node.py (+2/-2)
src/maasserver/models/tests/test_node.py (+22/-3)
To merge this branch: bzr merge lp:~rvb/maas/node-trans-log
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+256890@code.launchpad.net

Commit message

Log node status transition at info level: having the node status transitions in the log by default (i.e. logged at 'info' level) is tremendously helpful when debugging issues.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/event_connect.py'
2--- src/maasserver/event_connect.py 2015-03-25 15:33:23 +0000
3+++ src/maasserver/event_connect.py 2015-04-21 08:50:22 +0000
4@@ -45,7 +45,7 @@
5 NODE_STATUS_CHOICES_DICT[node.status],
6 )
7
8- # Special-case for allocating ndoes: we can include usernames here
9+ # Special-case for allocating nodes: we can include usernames here
10 # to make the event log more useful.
11 if node.status == NODE_STATUS.ALLOCATED:
12 description += " (to %s)" % node.owner.username
13
14=== modified file 'src/maasserver/models/node.py'
15--- src/maasserver/models/node.py 2015-04-16 19:52:24 +0000
16+++ src/maasserver/models/node.py 2015-04-21 08:50:22 +0000
17@@ -726,8 +726,8 @@
18 # Valid transition.
19 if old_status is not None:
20 stat = map_enum_reverse(NODE_STATUS, ignore=['DEFAULT'])
21- maaslog.debug(
22- "%s: Transition status from %s to %s",
23+ maaslog.info(
24+ "%s: Status transition from %s to %s",
25 self.hostname, stat[old_status], stat[self.status])
26 pass
27 else:
28
29=== modified file 'src/maasserver/models/tests/test_node.py'
30--- src/maasserver/models/tests/test_node.py 2015-04-16 14:15:25 +0000
31+++ src/maasserver/models/tests/test_node.py 2015-04-21 08:50:22 +0000
32@@ -119,7 +119,10 @@
33 from provisioningserver.rpc.exceptions import NoConnectionsAvailable
34 from provisioningserver.rpc.power import QUERY_POWER_TYPES
35 from provisioningserver.rpc.testing import always_succeed_with
36-from provisioningserver.utils.enum import map_enum
37+from provisioningserver.utils.enum import (
38+ map_enum,
39+ map_enum_reverse,
40+)
41 from testtools import ExpectedException
42 from testtools.matchers import (
43 Contains,
44@@ -746,7 +749,7 @@
45 self.assertThat(node._set_status, MockCalledOnceWith(
46 node, node.system_id, status=NODE_STATUS.FAILED_DISK_ERASING))
47 # It's logged too.
48- self.assertThat(logger.output, Equals(
49+ self.assertThat(logger.output, Contains(
50 "%s: Could not start node for disk erasure: %s\n"
51 % (node.hostname, error_message)))
52
53@@ -1438,7 +1441,7 @@
54 self.assertThat(node._set_status, MockCalledOnceWith(
55 node, node.system_id, status=status))
56 # It's logged too.
57- self.assertThat(logger.output, Equals(
58+ self.assertThat(logger.output, Contains(
59 "%s: Could not start node for commissioning: %s\n"
60 % (node.hostname, error_message)))
61
62@@ -1553,6 +1556,22 @@
63 NodeStateViolation, node.abort_commissioning,
64 factory.make_admin())
65
66+ def test_full_clean_logs_node_status_transition(self):
67+ node = factory.make_Node(
68+ status=NODE_STATUS.DEPLOYING, owner=factory.make_User())
69+ node.status = NODE_STATUS.DEPLOYED
70+
71+ with LoggerFixture("maas") as logger:
72+ node.full_clean()
73+
74+ stat = map_enum_reverse(NODE_STATUS)
75+ self.assertThat(logger.output.strip(), Equals(
76+ "%s: Status transition from %s to %s" % (
77+ node.hostname, stat[NODE_STATUS.DEPLOYING],
78+ stat[NODE_STATUS.DEPLOYED])
79+ )
80+ )
81+
82 def test_full_clean_checks_status_transition_and_raises_if_invalid(self):
83 # RETIRED -> ALLOCATED is an invalid transition.
84 node = factory.make_Node(