Also wipe agent token on manual power off or reboot
We have a check in the code that is never true for manual power
actions because of what happens in the conductor manager. Remove it.
Conflicts:
ironic/conductor/utils.py
Change-Id: I50b7b78a41188c41e4944894851f1d12684f824a
(cherry picked from commit bc04a42a96
)
This commit is contained in:
parent
145d68e8f5
commit
d9183a0a33
|
@ -278,20 +278,18 @@ def node_power_action(task, new_state, timeout=None):
|
||||||
# Set the target_power_state and clear any last_error, if we're
|
# Set the target_power_state and clear any last_error, if we're
|
||||||
# starting a new operation. This will expose to other processes
|
# starting a new operation. This will expose to other processes
|
||||||
# and clients that work is in progress.
|
# and clients that work is in progress.
|
||||||
if node['target_power_state'] != target_state:
|
|
||||||
node['target_power_state'] = target_state
|
node['target_power_state'] = target_state
|
||||||
node['last_error'] = None
|
node['last_error'] = None
|
||||||
driver_internal_info = node.driver_internal_info
|
driver_internal_info = node.driver_internal_info
|
||||||
driver_internal_info['last_power_state_change'] = str(
|
driver_internal_info['last_power_state_change'] = str(
|
||||||
timeutils.utcnow().isoformat())
|
timeutils.utcnow().isoformat())
|
||||||
|
node.driver_internal_info = driver_internal_info
|
||||||
# NOTE(dtantsur): wipe token on shutting down, otherwise a reboot in
|
# NOTE(dtantsur): wipe token on shutting down, otherwise a reboot in
|
||||||
# fast-track (or an accidentally booted agent) will cause subsequent
|
# fast-track (or an accidentally booted agent) will cause subsequent
|
||||||
# actions to fail.
|
# actions to fail.
|
||||||
if target_state in (states.POWER_OFF, states.SOFT_POWER_OFF,
|
if target_state in (states.POWER_OFF, states.SOFT_POWER_OFF,
|
||||||
states.REBOOT, states.SOFT_REBOOT):
|
states.REBOOT, states.SOFT_REBOOT):
|
||||||
if not is_agent_token_pregenerated(node):
|
wipe_internal_info_on_power_off(node)
|
||||||
driver_internal_info.pop('agent_secret_token', False)
|
|
||||||
node.driver_internal_info = driver_internal_info
|
|
||||||
node.save()
|
node.save()
|
||||||
|
|
||||||
# take power action
|
# take power action
|
||||||
|
@ -451,6 +449,21 @@ def cleaning_error_handler(task, msg, tear_down_cleaning=True,
|
||||||
task.process_event('fail', target_state=target_state)
|
task.process_event('fail', target_state=target_state)
|
||||||
|
|
||||||
|
|
||||||
|
def wipe_internal_info_on_power_off(node):
|
||||||
|
"""Wipe information that should not survive reboot/power off."""
|
||||||
|
driver_internal_info = node.driver_internal_info
|
||||||
|
# DHCP may result in a new IP next time.
|
||||||
|
driver_internal_info.pop('agent_url', None)
|
||||||
|
if not is_agent_token_pregenerated(node):
|
||||||
|
# Wipe the token if it's not pre-generated, otherwise we'll refuse to
|
||||||
|
# generate it again for the newly booted agent.
|
||||||
|
driver_internal_info.pop('agent_secret_token', False)
|
||||||
|
# Wipe cached steps since they may change after reboot.
|
||||||
|
driver_internal_info.pop('agent_cached_deploy_steps', None)
|
||||||
|
driver_internal_info.pop('agent_cached_clean_steps', None)
|
||||||
|
node.driver_internal_info = driver_internal_info
|
||||||
|
|
||||||
|
|
||||||
def wipe_token_and_url(task):
|
def wipe_token_and_url(task):
|
||||||
"""Remove agent URL and token from the task."""
|
"""Remove agent URL and token from the task."""
|
||||||
info = task.node.driver_internal_info
|
info = task.node.driver_internal_info
|
||||||
|
|
|
@ -381,6 +381,7 @@ class NodePowerActionTestCase(db_base.DbTestCase):
|
||||||
self.assertEqual(states.POWER_OFF, node['power_state'])
|
self.assertEqual(states.POWER_OFF, node['power_state'])
|
||||||
self.assertEqual(states.NOSTATE, node['target_power_state'])
|
self.assertEqual(states.NOSTATE, node['target_power_state'])
|
||||||
self.assertIsNone(node['last_error'])
|
self.assertIsNone(node['last_error'])
|
||||||
|
self.assertNotIn('agent_secret_token', node['driver_internal_info'])
|
||||||
|
|
||||||
@mock.patch.object(conductor_utils, 'LOG', autospec=True)
|
@mock.patch.object(conductor_utils, 'LOG', autospec=True)
|
||||||
@mock.patch.object(fake.FakePower, 'set_power_state', autospec=True)
|
@mock.patch.object(fake.FakePower, 'set_power_state', autospec=True)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Fixes wiping the agent secret token on manual power off or reboot. Also
|
||||||
|
makes sure to remove the agent URL since it may potentially change.
|
Loading…
Reference in New Issue