Add sync() command to the standby module

This patch is adding a new command called sync to the standby module of
IPA. The new command runs synchronously and it's responsible for
flushing file system buffers to the disks.

The initial intention for this command is to use it as part of the fix
for the bug #1512492 where some hardware/firmwares do have problems to
come back online after a soft ACPI power off, therefore we need to call
sync() to make sure all file system buffers have been synced and then
issue a hard power off (e.g via the BMC).

Partial-Bug: #1512492
Change-Id: I5cd1d1b821426e995dc584452494b93ab23917e0
This commit is contained in:
Lucas Alvares Gomes 2016-03-14 11:50:13 +00:00
parent dcd1c8f19b
commit 4b802c47b5
3 changed files with 32 additions and 0 deletions

View File

@ -308,3 +308,17 @@ class StandbyExtension(base.BaseAgentExtension):
def power_off(self):
LOG.info('Powering off system')
self._run_shutdown_script('-h')
@base.sync_command('sync')
def sync(self):
"""Flush file system buffers forcing changed blocks to disk.
:raises: CommandExecutionError if flushing file system buffers fails.
"""
LOG.debug('Flushing file system buffers')
try:
utils.execute('sync')
except processutils.ProcessExecutionError as e:
error_msg = 'Flushing file system buffers failed. Error: %s' % e
LOG.error(error_msg)
raise errors.CommandExecutionError(error_msg)

View File

@ -555,6 +555,19 @@ class TestStandbyExtension(test_base.BaseTestCase):
execute_mock.assert_called_once_with(*command, check_exit_code=[0])
self.assertEqual('FAILED', failed_result.command_status)
@mock.patch('ironic_python_agent.utils.execute', autospec=True)
def test_sync(self, execute_mock):
result = self.agent_extension.sync()
execute_mock.assert_called_once_with('sync')
self.assertEqual('SUCCEEDED', result.command_status)
@mock.patch('ironic_python_agent.utils.execute', autospec=True)
def test_sync_error(self, execute_mock):
execute_mock.side_effect = processutils.ProcessExecutionError
self.assertRaises(
errors.CommandExecutionError, self.agent_extension.sync)
execute_mock.assert_called_once_with('sync')
@mock.patch('ironic_python_agent.extensions.standby._write_image',
autospec=True)
@mock.patch('ironic_python_agent.extensions.standby._download_image',

View File

@ -0,0 +1,5 @@
---
features:
- Add a new sync() command to the standby extension. When invoked,
the new command is responsible for flushing the file system buffers
to the disk.