Merge lp:~julian-edwards/maas/mark-failed-twice into lp:~maas-committers/maas/trunk

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: no longer in the source branch.
Merged at revision: 2969
Proposed branch: lp:~julian-edwards/maas/mark-failed-twice
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 32 lines (+11/-0)
2 files modified
src/maasserver/models/node.py (+3/-0)
src/maasserver/models/tests/test_node.py (+8/-0)
To merge this branch: bzr merge lp:~julian-edwards/maas/mark-failed-twice
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+234410@code.launchpad.net

Commit message

If Node.mark_failed() is called when the node is already in a failed state, ignore it.

Description of the change

This could be seen as papering over an underlying problem and I won't disagree with that, but this is not a bad thing to do anyway.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

I think you're doing the right thing. A second mark-as-failed might come from a concurrent job, such as the power poller.

review: Approve
Revision history for this message
Julian Edwards (julian-edwards) wrote :

Cheers.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/models/node.py'
--- src/maasserver/models/node.py 2014-09-10 16:20:57 +0000
+++ src/maasserver/models/node.py 2014-09-12 02:42:45 +0000
@@ -1272,6 +1272,9 @@
1272 self.status = failed_statuses_mapping[self.status]1272 self.status = failed_statuses_mapping[self.status]
1273 self.error_description = error_description1273 self.error_description = error_description
1274 self.save()1274 self.save()
1275 elif self.status in failed_statuses_mapping.viewvalues():
1276 # Silently ignore a request to fail an already failed node.
1277 pass
1275 else:1278 else:
1276 raise NodeStateViolation(1279 raise NodeStateViolation(
1277 "The status of the node is %s; this status cannot "1280 "The status of the node is %s; this status cannot "
12781281
=== modified file 'src/maasserver/models/tests/test_node.py'
--- src/maasserver/models/tests/test_node.py 2014-09-10 16:20:57 +0000
+++ src/maasserver/models/tests/test_node.py 2014-09-12 02:42:45 +0000
@@ -1152,6 +1152,14 @@
1152 description = factory.make_name('error-description')1152 description = factory.make_name('error-description')
1153 self.assertRaises(NodeStateViolation, node.mark_failed, description)1153 self.assertRaises(NodeStateViolation, node.mark_failed, description)
11541154
1155 def test_mark_failed_ignores_if_already_failed(self):
1156 status = random.choice([
1157 NODE_STATUS.FAILED_DEPLOYMENT, NODE_STATUS.FAILED_COMMISSIONING])
1158 node = factory.make_Node(status=status)
1159 description = factory.make_name('error-description')
1160 node.mark_failed(description)
1161 self.assertEqual(status, node.status)
1162
1155 def test_mark_broken_changes_status_to_broken(self):1163 def test_mark_broken_changes_status_to_broken(self):
1156 node = factory.make_Node(1164 node = factory.make_Node(
1157 status=NODE_STATUS.NEW, owner=factory.make_User())1165 status=NODE_STATUS.NEW, owner=factory.make_User())