Merge ~ack/maas:1887797-remove-machine-pod-error into maas:master

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: c75e353dffa2e1def3dc838952b32674f501747c
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ack/maas:1887797-remove-machine-pod-error
Merge into: maas:master
Diff against target: 82 lines (+24/-12)
2 files modified
src/maasserver/models/node.py (+13/-4)
src/maasserver/models/tests/test_node.py (+11/-8)
Reviewer Review Type Date Requested Status
Adam Collard (community) Approve
MAAS Lander Needs Fixing
Review via email: mp+397432@code.launchpad.net

Commit message

LP: #1887797 - don't fail machine removal if Pod action fails

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b 1887797-remove-machine-pod-error lp:~ack/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/9161/console
COMMIT: e740923ed84001aa5aabe1c4b4eb957854f9ceaf

review: Needs Fixing
Revision history for this message
Adam Collard (adam-collard) :
review: Approve

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/maasserver/models/node.py b/src/maasserver/models/node.py
index 98a2635..105ac72 100644
--- a/src/maasserver/models/node.py
+++ b/src/maasserver/models/node.py
@@ -2942,7 +2942,7 @@ class Node(CleanSave, TimestampedModel):
2942 client_idents = pod.get_client_identifiers()2942 client_idents = pod.get_client_identifiers()
29432943
2944 @transactional2944 @transactional
2945 def _save(machine_id, pod_id, hints):2945 def _save(machine_id, pod_id, result):
2946 from maasserver.models.bmc import Pod2946 from maasserver.models.bmc import Pod
29472947
2948 machine = Machine.objects.filter(id=machine_id).first()2948 machine = Machine.objects.filter(id=machine_id).first()
@@ -2958,9 +2958,16 @@ class Node(CleanSave, TimestampedModel):
2958 machine_id=machine_id2958 machine_id=machine_id
2959 ).delete()2959 ).delete()
2960 super(Node, machine).delete()2960 super(Node, machine).delete()
2961
2962 if isinstance(result, Failure):
2963 maaslog.warning(
2964 f"{self.hostname}: Failure decomposing machine: {result.value}"
2965 )
2966 return
2967
2961 pod = Pod.objects.filter(id=pod_id).first()2968 pod = Pod.objects.filter(id=pod_id).first()
2962 if pod is not None:2969 if pod is not None:
2963 pod.sync_hints(hints)2970 pod.sync_hints(result)
29642971
2965 maaslog.info("%s: Decomposing machine", self.hostname)2972 maaslog.info("%s: Decomposing machine", self.hostname)
29662973
@@ -2973,8 +2980,10 @@ class Node(CleanSave, TimestampedModel):
2973 pod_id=pod.id,2980 pod_id=pod.id,
2974 name=pod.name,2981 name=pod.name,
2975 )2982 )
2976 d.addCallback(2983 d.addBoth(
2977 lambda hints: (deferToDatabase(_save, self.id, pod.id, hints))2984 lambda result: (
2985 deferToDatabase(_save, self.id, pod.id, result)
2986 )
2978 )2987 )
2979 d.addCallback(lambda _: request_commissioning_results(pod))2988 d.addCallback(lambda _: request_commissioning_results(pod))
2980 else:2989 else:
diff --git a/src/maasserver/models/tests/test_node.py b/src/maasserver/models/tests/test_node.py
index bd6d54d..e63ffa5 100644
--- a/src/maasserver/models/tests/test_node.py
+++ b/src/maasserver/models/tests/test_node.py
@@ -73,7 +73,6 @@ from maasserver.exceptions import (
73 IPAddressCheckFailed,73 IPAddressCheckFailed,
74 NetworkingResetProblem,74 NetworkingResetProblem,
75 NodeStateViolation,75 NodeStateViolation,
76 PodProblem,
77 PowerProblem,76 PowerProblem,
78 StaticIPAddressExhaustion,77 StaticIPAddressExhaustion,
79)78)
@@ -6055,14 +6054,18 @@ class TestDecomposeMachineTransactional(
6055 interface = transactional(reload_object)(interface)6054 interface = transactional(reload_object)(interface)
6056 self.assertIsNone(interface)6055 self.assertIsNone(interface)
60576056
6058 def test_errors_raised_up(self):6057 def test_delete_doesnt_fail_removal(self):
6058 mock_log_warning = self.patch(node_module.maaslog, "warning")
6059 pod, machine, hints, client = self.create_pod_machine_and_hints()6059 pod, machine, hints, client = self.create_pod_machine_and_hints()
6060 client.return_value = defer.fail(PodActionFail())6060 client.return_value = defer.fail(PodActionFail("bang!"))
6061 with ExpectedException(PodProblem):6061 with post_commit_hooks:
6062 with post_commit_hooks:6062 machine.delete()
6063 machine.delete()6063 mock_log_warning.assert_called_with(
6064 machine = transactional(reload_object)(machine)6064 f"{machine.hostname}: Failure decomposing machine: "
6065 self.assertIsNotNone(machine)6065 "Unable to decompose machine because: bang!"
6066 )
6067 # the machine is still deleted
6068 self.assertIsNone(transactional(reload_object)(machine))
60666069
6067 def test_release_deletes_dynamic_machine(self):6070 def test_release_deletes_dynamic_machine(self):
6068 owner = transactional(factory.make_User)()6071 owner = transactional(factory.make_User)()

Subscribers

People subscribed via source and target branches