From 3c4884903ddf72fc28648656b6532f6e3dfe9d30 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Mon, 5 Oct 2020 17:36:45 +0200 Subject: [PATCH] Wiping agent tokens on reboot via API - take 2 Because of using an incorrect variable, reboot was treated as power on, and the token was not wiped. Change-Id: I656450c2bedc3dc0d20a70de78cc29bf64d5fe85 Story: #2008097 Task: #40799 (cherry picked from commit e39858dd8c4e4fa2d2779280090b034dd594601c) --- ironic/conductor/utils.py | 4 ++-- ironic/tests/unit/conductor/test_utils.py | 6 +++++- releasenotes/notes/token-reboot-3f18cf73e4dd10d3.yaml | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/token-reboot-3f18cf73e4dd10d3.yaml diff --git a/ironic/conductor/utils.py b/ironic/conductor/utils.py index 473c3d4783..a20431089f 100644 --- a/ironic/conductor/utils.py +++ b/ironic/conductor/utils.py @@ -288,8 +288,8 @@ def node_power_action(task, new_state, timeout=None): # NOTE(dtantsur): wipe token on shutting down, otherwise a reboot in # fast-track (or an accidentally booted agent) will cause subsequent # actions to fail. - if target_state in (states.POWER_OFF, states.SOFT_POWER_OFF, - states.REBOOT, states.SOFT_REBOOT): + if new_state in (states.POWER_OFF, states.SOFT_POWER_OFF, + states.REBOOT, states.SOFT_REBOOT): wipe_internal_info_on_power_off(node) node.save() diff --git a/ironic/tests/unit/conductor/test_utils.py b/ironic/tests/unit/conductor/test_utils.py index a449bf8de0..c096a54261 100644 --- a/ironic/tests/unit/conductor/test_utils.py +++ b/ironic/tests/unit/conductor/test_utils.py @@ -278,10 +278,13 @@ class NodePowerActionTestCase(db_base.DbTestCase): @mock.patch.object(fake.FakePower, 'get_power_state', autospec=True) def test_node_power_action_power_reboot(self, get_power_mock, reboot_mock): """Test for reboot a node.""" + dii = {'agent_secret_token': 'token', + 'agent_cached_deploy_steps': ['steps']} node = obj_utils.create_test_node(self.context, uuid=uuidutils.generate_uuid(), driver='fake-hardware', - power_state=states.POWER_ON) + power_state=states.POWER_ON, + driver_internal_info=dii) task = task_manager.TaskManager(self.context, node.uuid) conductor_utils.node_power_action(task, states.REBOOT) @@ -292,6 +295,7 @@ class NodePowerActionTestCase(db_base.DbTestCase): self.assertEqual(states.POWER_ON, node['power_state']) self.assertIsNone(node['target_power_state']) self.assertIsNone(node['last_error']) + self.assertNotIn('agent_secret_token', node['driver_internal_info']) @mock.patch.object(fake.FakePower, 'get_power_state', autospec=True) def test_node_power_action_invalid_state(self, get_power_mock): diff --git a/releasenotes/notes/token-reboot-3f18cf73e4dd10d3.yaml b/releasenotes/notes/token-reboot-3f18cf73e4dd10d3.yaml new file mode 100644 index 0000000000..2c1904a895 --- /dev/null +++ b/releasenotes/notes/token-reboot-3f18cf73e4dd10d3.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + Fixes wiping agent token on rebooting via API.