Skip to content

Commit 20dc04e

Browse files
committed
Reboot and Poweroff fails with coreos IPA image
The CoreOS IPA images do not support poweroff/reboot due to running in a chroot. For this case, we fall back to forcing poweroff or reboot via sysrq commands Change-Id: I75d68b6308beba299d043e43a5fa1671b6ef3ada Closes-Bug: #1628367
1 parent 4cf29db commit 20dc04e

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

ironic_python_agent/extensions/standby.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,15 @@ def _run_shutdown_command(self, command):
499499
except errors.CommandExecutionError as e:
500500
LOG.warning('Failed to sync file system buffers: % s', e)
501501
try:
502-
utils.execute(command, check_exit_code=[0])
502+
_, stderr = utils.execute(command, use_standard_locale=True,
503+
check_exit_code=[0])
504+
if 'ignoring request.' in stderr:
505+
LOG.debug('%s command failed with error %s, '
506+
'falling back to sysrq-trigger.', command, stderr)
507+
if command == 'poweroff':
508+
utils.execute("echo o > /proc/sysrq-trigger", shell=True)
509+
elif command == 'reboot':
510+
utils.execute("echo b > /proc/sysrq-trigger", shell=True)
503511
except processutils.ProcessExecutionError as e:
504512
raise errors.SystemRebootError(e.exit_code, e.stdout, e.stderr)
505513

ironic_python_agent/tests/unit/extensions/test_standby.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,34 @@ def test_run_shutdown_command_valid(self, execute_mock):
679679

680680
self.agent_extension._run_shutdown_command('poweroff')
681681
calls = [mock.call('sync'),
682-
mock.call('poweroff', check_exit_code=[0])]
682+
mock.call('poweroff', use_standard_locale=True,
683+
check_exit_code=[0])]
684+
execute_mock.assert_has_calls(calls)
685+
686+
@mock.patch('ironic_python_agent.utils.execute', autospec=True)
687+
def test_run_shutdown_command_valid_poweroff_sysrq(self, execute_mock):
688+
execute_mock.side_effect = [('', ''), ('',
689+
'Running in chroot, ignoring request.'),
690+
('', '')]
691+
692+
self.agent_extension._run_shutdown_command('poweroff')
693+
calls = [mock.call('sync'),
694+
mock.call('poweroff', use_standard_locale=True,
695+
check_exit_code=[0]),
696+
mock.call("echo o > /proc/sysrq-trigger", shell=True)]
697+
execute_mock.assert_has_calls(calls)
698+
699+
@mock.patch('ironic_python_agent.utils.execute', autospec=True)
700+
def test_run_shutdown_command_valid_reboot_sysrq(self, execute_mock):
701+
execute_mock.side_effect = [('', ''), ('',
702+
'Running in chroot, ignoring request.'),
703+
('', '')]
704+
705+
self.agent_extension._run_shutdown_command('reboot')
706+
calls = [mock.call('sync'),
707+
mock.call('reboot', use_standard_locale=True,
708+
check_exit_code=[0]),
709+
mock.call("echo b > /proc/sysrq-trigger", shell=True)]
683710
execute_mock.assert_has_calls(calls)
684711

685712
@mock.patch('ironic_python_agent.utils.execute', autospec=True)
@@ -689,7 +716,8 @@ def test_run_image(self, execute_mock):
689716
success_result = self.agent_extension.run_image()
690717
success_result.join()
691718
calls = [mock.call('sync'),
692-
mock.call('reboot', check_exit_code=[0])]
719+
mock.call('reboot', use_standard_locale=True,
720+
check_exit_code=[0])]
693721
execute_mock.assert_has_calls(calls)
694722
self.assertEqual('SUCCEEDED', success_result.command_status)
695723

@@ -711,7 +739,8 @@ def test_power_off(self, execute_mock):
711739
success_result.join()
712740

713741
calls = [mock.call('sync'),
714-
mock.call('poweroff', check_exit_code=[0])]
742+
mock.call('poweroff', use_standard_locale=True,
743+
check_exit_code=[0])]
715744
execute_mock.assert_has_calls(calls)
716745
self.assertEqual('SUCCEEDED', success_result.command_status)
717746

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- Fixes a bug in the CoreOS IPA images (where IPA runs in a chroot), where
4+
IPA could not power off or reboot properly. In this case, it will now use
5+
SYSRQ commands to forcefully reboot or power off.

0 commit comments

Comments
 (0)