Skip to content

Commit

Permalink
Clear instance_info when removing lease from a node
Browse files Browse the repository at this point in the history
If a node had instance_info set but was not deployed, then
removing the lease would not clear the instance_info. This change
fixes that issue.
  • Loading branch information
tzumainn committed Nov 5, 2024
1 parent 9436150 commit a1766f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions esi_leap/resource_objects/ironic_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ def remove_lease(self, lease):
"path": "/lessee",
}
)
if len(self._get_node().instance_info) > 0:
patches.append(
{
"op": "remove",
"path": "/instance_info",
}
)
if len(patches) > 0:
get_ironic_client().node.update(self._uuid, patches)
state = self._get_node().provision_state
Expand Down
4 changes: 3 additions & 1 deletion esi_leap/tests/resource_objects/test_ironic_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self):
self.uuid = fake_uuid
self.resource_class = "baremetal"
self.power_state = "off"
self.instance_info = {"foo": "bar"}


class FakeLease(object):
Expand Down Expand Up @@ -187,13 +188,14 @@ 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, 1)
self.assertEqual(mock_gn.call_count, 2)
self.assertEqual(mock_client.call_count, 2)
mock_client.return_value.node.update.assert_called_once_with(
fake_uuid,
[
{"op": "remove", "path": "/properties/lease_uuid"},
{"op": "remove", "path": "/lessee"},
{"op": "remove", "path": "/instance_info"},
],
)
mock_client.return_value.node.set_provision_state.assert_called_once_with(
Expand Down

0 comments on commit a1766f8

Please sign in to comment.