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
1=== modified file 'src/maasserver/models/node.py'
2--- src/maasserver/models/node.py 2014-09-10 16:20:57 +0000
3+++ src/maasserver/models/node.py 2014-09-12 02:42:45 +0000
4@@ -1272,6 +1272,9 @@
5 self.status = failed_statuses_mapping[self.status]
6 self.error_description = error_description
7 self.save()
8+ elif self.status in failed_statuses_mapping.viewvalues():
9+ # Silently ignore a request to fail an already failed node.
10+ pass
11 else:
12 raise NodeStateViolation(
13 "The status of the node is %s; this status cannot "
14
15=== modified file 'src/maasserver/models/tests/test_node.py'
16--- src/maasserver/models/tests/test_node.py 2014-09-10 16:20:57 +0000
17+++ src/maasserver/models/tests/test_node.py 2014-09-12 02:42:45 +0000
18@@ -1152,6 +1152,14 @@
19 description = factory.make_name('error-description')
20 self.assertRaises(NodeStateViolation, node.mark_failed, description)
21
22+ def test_mark_failed_ignores_if_already_failed(self):
23+ status = random.choice([
24+ NODE_STATUS.FAILED_DEPLOYMENT, NODE_STATUS.FAILED_COMMISSIONING])
25+ node = factory.make_Node(status=status)
26+ description = factory.make_name('error-description')
27+ node.mark_failed(description)
28+ self.assertEqual(status, node.status)
29+
30 def test_mark_broken_changes_status_to_broken(self):
31 node = factory.make_Node(
32 status=NODE_STATUS.NEW, owner=factory.make_User())