Skip to content

Commit

Permalink
Disable node console and expire console auth tokens when a lease expires
Browse files Browse the repository at this point in the history
  • Loading branch information
tzumainn committed Dec 10, 2024
1 parent 676fe4d commit 6e09dff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions esi_leap/resource_objects/ironic_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down
11 changes: 9 additions & 2 deletions esi_leap/tests/resource_objects/test_ironic_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
[
Expand All @@ -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"
)
Expand Down

0 comments on commit 6e09dff

Please sign in to comment.