diff --git a/esi_leap/resource_objects/ironic_node.py b/esi_leap/resource_objects/ironic_node.py index 4115823..0f9b110 100644 --- a/esi_leap/resource_objects/ironic_node.py +++ b/esi_leap/resource_objects/ironic_node.py @@ -17,6 +17,7 @@ from esi_leap.common import exception from esi_leap.common import ironic import esi_leap.conf +from esi_leap.objects import console_auth_token from esi_leap.resource_objects import base from esi_leap.resource_objects import error @@ -162,7 +163,14 @@ def remove_lease(self, lease): } ) if len(patches) > 0: + # remove lease information and instance_info get_ironic_client().node.update(self._uuid, patches) + + # disable console and any console tokens + get_ironic_client().node.set_console_mode(self._uuid, False) + console_auth_token.ConsoleAuthToken.clean_console_tokens_for_node(self._uuid) + + # unprovision the node if needed state = self._get_node().provision_state if state == "active": get_ironic_client().node.set_provision_state(self._uuid, "deleted") diff --git a/esi_leap/tests/resource_objects/test_ironic_node.py b/esi_leap/tests/resource_objects/test_ironic_node.py index 12c3cd0..9bf2b68 100644 --- a/esi_leap/tests/resource_objects/test_ironic_node.py +++ b/esi_leap/tests/resource_objects/test_ironic_node.py @@ -168,13 +168,16 @@ def test_set_lease(self, client_mock): ], ) + @mock.patch( + "esi_leap.objects.console_auth_token.ConsoleAuthToken.clean_console_tokens_for_node" + ) @mock.patch( "esi_leap.resource_objects.ironic_node.IronicNode." "get_lessee_project_id" ) @mock.patch("esi_leap.resource_objects.ironic_node.IronicNode." "get_lease_uuid") @mock.patch("esi_leap.resource_objects.ironic_node.IronicNode._get_node") @mock.patch.object(ironic_node, "get_ironic_client", autospec=True) - def test_remove_lease(self, mock_client, mock_gn, mock_glu, mock_glpi): + def test_remove_lease(self, mock_client, mock_gn, mock_glu, mock_glpi, mock_cctfn): fake_get_node = FakeIronicNode() fake_get_node.provision_state = "active" fake_lease = FakeLease() @@ -189,7 +192,7 @@ def test_remove_lease(self, mock_client, mock_gn, mock_glu, mock_glpi): mock_glpi.assert_called_once() mock_glu.assert_called_once() self.assertEqual(mock_gn.call_count, 2) - self.assertEqual(mock_client.call_count, 2) + self.assertEqual(mock_client.call_count, 3) mock_client.return_value.node.update.assert_called_once_with( fake_uuid, [ @@ -198,6 +201,10 @@ def test_remove_lease(self, mock_client, mock_gn, mock_glu, mock_glpi): {"op": "remove", "path": "/instance_info"}, ], ) + mock_client.return_value.node.set_console_mode.assert_called_once_with( + fake_uuid, False + ) + mock_cctfn.assert_called_once_with(fake_uuid) mock_client.return_value.node.set_provision_state.assert_called_once_with( fake_uuid, "deleted" )