diff options
author | Zuul <zuul@review.opendev.org> | 2021-04-14 12:13:37 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2021-04-14 12:13:37 +0000 |
commit | c72997d8d0c80f29fcaf452092f1e66e7270a427 (patch) | |
tree | b808f0505bb6e3d203361c567181fbea8c0807f4 | |
parent | 5bac375f73ac417b156516d0dc1ee113896edc54 (diff) | |
parent | b395181b1b1381ff0802744807a981df8453bc40 (diff) | |
download | ironic-python-agent-c72997d8d0c80f29fcaf452092f1e66e7270a427.tar.gz |
Merge "Always fall back to sysrq when power off fails"
-rw-r--r-- | ironic_python_agent/extensions/standby.py | 23 | ||||
-rw-r--r-- | ironic_python_agent/tests/unit/extensions/test_standby.py | 7 | ||||
-rw-r--r-- | releasenotes/notes/container-poweroff-d9ffb637cf1cee6c.yaml | 5 |
3 files changed, 25 insertions, 10 deletions
diff --git a/ironic_python_agent/extensions/standby.py b/ironic_python_agent/extensions/standby.py index 5f1b9945..496833a9 100644 --- a/ironic_python_agent/extensions/standby.py +++ b/ironic_python_agent/extensions/standby.py @@ -748,15 +748,24 @@ class StandbyExtension(base.BaseAgentExtension): self.sync() except errors.CommandExecutionError as e: LOG.warning('Failed to sync file system buffers: % s', e) + try: _, stderr = utils.execute(command, use_standard_locale=True) - if 'ignoring request.' in stderr: - LOG.debug('%s command failed with error %s, ' - 'falling back to sysrq-trigger.', command, stderr) - if command == 'poweroff': - utils.execute("echo o > /proc/sysrq-trigger", shell=True) - elif command == 'reboot': - utils.execute("echo b > /proc/sysrq-trigger", shell=True) + except processutils.ProcessExecutionError as e: + LOG.warning('%s command failed with error %s, ' + 'falling back to sysrq-trigger', command, e) + else: + if 'ignoring request' in stderr: + LOG.warning('%s command has been ignored, ' + 'falling back to sysrq-trigger', command) + else: + return + + try: + if command == 'poweroff': + utils.execute("echo o > /proc/sysrq-trigger", shell=True) + elif command == 'reboot': + utils.execute("echo b > /proc/sysrq-trigger", shell=True) except processutils.ProcessExecutionError as e: raise errors.SystemRebootError(e.exit_code, e.stdout, e.stderr) diff --git a/ironic_python_agent/tests/unit/extensions/test_standby.py b/ironic_python_agent/tests/unit/extensions/test_standby.py index 9f138e47..79b4a6ca 100644 --- a/ironic_python_agent/tests/unit/extensions/test_standby.py +++ b/ironic_python_agent/tests/unit/extensions/test_standby.py @@ -1049,9 +1049,10 @@ class TestStandbyExtension(base.IronicAgentTest): @mock.patch('ironic_python_agent.utils.execute', autospec=True) def test_run_shutdown_command_valid_poweroff_sysrq(self, execute_mock): - execute_mock.side_effect = [('', ''), ('', ''), ('', - 'Running in chroot, ignoring request.'), - ('', '')] + execute_mock.side_effect = [ + ('', ''), ('', ''), + processutils.ProcessExecutionError(''), + ('', '')] self.agent_extension._run_shutdown_command('poweroff') calls = [mock.call('hwclock', '-v', '--systohc'), diff --git a/releasenotes/notes/container-poweroff-d9ffb637cf1cee6c.yaml b/releasenotes/notes/container-poweroff-d9ffb637cf1cee6c.yaml new file mode 100644 index 00000000..8b2e68a6 --- /dev/null +++ b/releasenotes/notes/container-poweroff-d9ffb637cf1cee6c.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixes fall-back to sysrq when powering off or rebooting the node from + inside a container. |