Add power_off command in standby extension
This commit adds a new command power_off to standby extension which runs shutdown -h now on the system. This commit also adds mappings for /proc and /sys in cloud-config.yml for the agent service spawned. Partial-Bug: #1451310 Change-Id: I2a5f984af26bbbe03002bb8c367c8c6af8d91434
This commit is contained in:
parent
0a416af0c8
commit
be36ed6903
@ -58,6 +58,8 @@ coreos:
|
||||
--machine=ironic_python_agent \
|
||||
--bind=/dev:/dev \
|
||||
--bind=/dev/pts:/dev/pts \
|
||||
--bind=/proc:/proc \
|
||||
--bind=/sys:/sys \
|
||||
--bind=/usr/share/oem:/mnt \
|
||||
--user=root \
|
||||
--keep-unit \
|
||||
|
@ -238,13 +238,21 @@ class StandbyExtension(base.BaseAgentExtension):
|
||||
return 'image ({0}) written to device {1}'.format(image_info['id'],
|
||||
device)
|
||||
|
||||
@base.async_command('run_image')
|
||||
def run_image(self):
|
||||
script = _path_to_script('shell/reboot.sh')
|
||||
LOG.info('Rebooting system')
|
||||
command = ['/bin/bash', script]
|
||||
def _run_shutdown_script(self, parameter):
|
||||
script = _path_to_script('shell/shutdown.sh')
|
||||
command = ['/bin/bash', script, parameter]
|
||||
# this should never return if successful
|
||||
try:
|
||||
stdout, stderr = utils.execute(*command, check_exit_code=[0])
|
||||
except processutils.ProcessExecutionError as e:
|
||||
raise errors.SystemRebootError(e.exit_code, e.stdout, e.stderr)
|
||||
|
||||
@base.async_command('run_image')
|
||||
def run_image(self):
|
||||
LOG.info('Rebooting system')
|
||||
self._run_shutdown_script('-r')
|
||||
|
||||
@base.async_command('power_off')
|
||||
def power_off(self):
|
||||
LOG.info('Powering off system')
|
||||
self._run_shutdown_script('-h')
|
||||
|
@ -22,4 +22,8 @@ set -e
|
||||
echo "1" > /proc/sys/kernel/sysrq
|
||||
|
||||
echo "s" > /proc/sysrq-trigger
|
||||
echo "b" > /proc/sysrq-trigger
|
||||
if [[ $1 = '-h' ]]; then
|
||||
echo "o" > /proc/sysrq-trigger
|
||||
elif [[ $1 = '-r' ]]; then
|
||||
echo "b" > /proc/sysrq-trigger
|
||||
fi
|
@ -451,8 +451,8 @@ class TestStandbyExtension(test_base.BaseTestCase):
|
||||
|
||||
@mock.patch('ironic_python_agent.utils.execute', autospec=True)
|
||||
def test_run_image(self, execute_mock):
|
||||
script = standby._path_to_script('shell/reboot.sh')
|
||||
command = ['/bin/bash', script]
|
||||
script = standby._path_to_script('shell/shutdown.sh')
|
||||
command = ['/bin/bash', script, '-r']
|
||||
execute_mock.return_value = ('', '')
|
||||
|
||||
success_result = self.agent_extension.run_image()
|
||||
@ -474,3 +474,25 @@ class TestStandbyExtension(test_base.BaseTestCase):
|
||||
def test_path_to_script(self):
|
||||
script = standby._path_to_script('shell/reboot.sh')
|
||||
self.assertTrue(script.endswith('extensions/../shell/reboot.sh'))
|
||||
|
||||
@mock.patch('ironic_python_agent.utils.execute', autospec=True)
|
||||
def test_power_off(self, execute_mock):
|
||||
script = standby._path_to_script('shell/shutdown.sh')
|
||||
command = ['/bin/bash', script, '-h']
|
||||
execute_mock.return_value = ('', '')
|
||||
|
||||
success_result = self.agent_extension.power_off()
|
||||
success_result.join()
|
||||
|
||||
execute_mock.assert_called_once_with(*command, check_exit_code=[0])
|
||||
self.assertEqual('SUCCEEDED', success_result.command_status)
|
||||
|
||||
execute_mock.reset_mock()
|
||||
execute_mock.return_value = ('', '')
|
||||
execute_mock.side_effect = processutils.ProcessExecutionError
|
||||
|
||||
failed_result = self.agent_extension.power_off()
|
||||
failed_result.join()
|
||||
|
||||
execute_mock.assert_called_once_with(*command, check_exit_code=[0])
|
||||
self.assertEqual('FAILED', failed_result.command_status)
|
||||
|
Loading…
Reference in New Issue
Block a user