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
=== modified file 'src/maasserver/event_connect.py'
--- src/maasserver/event_connect.py 2015-03-25 15:33:23 +0000
+++ src/maasserver/event_connect.py 2015-04-21 08:50:22 +0000
@@ -45,7 +45,7 @@
45 NODE_STATUS_CHOICES_DICT[node.status],45 NODE_STATUS_CHOICES_DICT[node.status],
46 )46 )
4747
48 # Special-case for allocating ndoes: we can include usernames here48 # Special-case for allocating nodes: we can include usernames here
49 # to make the event log more useful.49 # to make the event log more useful.
50 if node.status == NODE_STATUS.ALLOCATED:50 if node.status == NODE_STATUS.ALLOCATED:
51 description += " (to %s)" % node.owner.username51 description += " (to %s)" % node.owner.username
5252
=== modified file 'src/maasserver/models/node.py'
--- src/maasserver/models/node.py 2015-04-16 19:52:24 +0000
+++ src/maasserver/models/node.py 2015-04-21 08:50:22 +0000
@@ -726,8 +726,8 @@
726 # Valid transition.726 # Valid transition.
727 if old_status is not None:727 if old_status is not None:
728 stat = map_enum_reverse(NODE_STATUS, ignore=['DEFAULT'])728 stat = map_enum_reverse(NODE_STATUS, ignore=['DEFAULT'])
729 maaslog.debug(729 maaslog.info(
730 "%s: Transition status from %s to %s",730 "%s: Status transition from %s to %s",
731 self.hostname, stat[old_status], stat[self.status])731 self.hostname, stat[old_status], stat[self.status])
732 pass732 pass
733 else:733 else:
734734
=== modified file 'src/maasserver/models/tests/test_node.py'
--- src/maasserver/models/tests/test_node.py 2015-04-16 14:15:25 +0000
+++ src/maasserver/models/tests/test_node.py 2015-04-21 08:50:22 +0000
@@ -119,7 +119,10 @@
119from provisioningserver.rpc.exceptions import NoConnectionsAvailable119from provisioningserver.rpc.exceptions import NoConnectionsAvailable
120from provisioningserver.rpc.power import QUERY_POWER_TYPES120from provisioningserver.rpc.power import QUERY_POWER_TYPES
121from provisioningserver.rpc.testing import always_succeed_with121from provisioningserver.rpc.testing import always_succeed_with
122from provisioningserver.utils.enum import map_enum122from provisioningserver.utils.enum import (
123 map_enum,
124 map_enum_reverse,
125)
123from testtools import ExpectedException126from testtools import ExpectedException
124from testtools.matchers import (127from testtools.matchers import (
125 Contains,128 Contains,
@@ -746,7 +749,7 @@
746 self.assertThat(node._set_status, MockCalledOnceWith(749 self.assertThat(node._set_status, MockCalledOnceWith(
747 node, node.system_id, status=NODE_STATUS.FAILED_DISK_ERASING))750 node, node.system_id, status=NODE_STATUS.FAILED_DISK_ERASING))
748 # It's logged too.751 # It's logged too.
749 self.assertThat(logger.output, Equals(752 self.assertThat(logger.output, Contains(
750 "%s: Could not start node for disk erasure: %s\n"753 "%s: Could not start node for disk erasure: %s\n"
751 % (node.hostname, error_message)))754 % (node.hostname, error_message)))
752755
@@ -1438,7 +1441,7 @@
1438 self.assertThat(node._set_status, MockCalledOnceWith(1441 self.assertThat(node._set_status, MockCalledOnceWith(
1439 node, node.system_id, status=status))1442 node, node.system_id, status=status))
1440 # It's logged too.1443 # It's logged too.
1441 self.assertThat(logger.output, Equals(1444 self.assertThat(logger.output, Contains(
1442 "%s: Could not start node for commissioning: %s\n"1445 "%s: Could not start node for commissioning: %s\n"
1443 % (node.hostname, error_message)))1446 % (node.hostname, error_message)))
14441447
@@ -1553,6 +1556,22 @@
1553 NodeStateViolation, node.abort_commissioning,1556 NodeStateViolation, node.abort_commissioning,
1554 factory.make_admin())1557 factory.make_admin())
15551558
1559 def test_full_clean_logs_node_status_transition(self):
1560 node = factory.make_Node(
1561 status=NODE_STATUS.DEPLOYING, owner=factory.make_User())
1562 node.status = NODE_STATUS.DEPLOYED
1563
1564 with LoggerFixture("maas") as logger:
1565 node.full_clean()
1566
1567 stat = map_enum_reverse(NODE_STATUS)
1568 self.assertThat(logger.output.strip(), Equals(
1569 "%s: Status transition from %s to %s" % (
1570 node.hostname, stat[NODE_STATUS.DEPLOYING],
1571 stat[NODE_STATUS.DEPLOYED])
1572 )
1573 )
1574
1556 def test_full_clean_checks_status_transition_and_raises_if_invalid(self):1575 def test_full_clean_checks_status_transition_and_raises_if_invalid(self):
1557 # RETIRED -> ALLOCATED is an invalid transition.1576 # RETIRED -> ALLOCATED is an invalid transition.
1558 node = factory.make_Node(1577 node = factory.make_Node(