Merge "Add sync() command to the standby module"

This commit is contained in:
Jenkins 2016-03-21 09:51:44 +00:00 committed by Gerrit Code Review
commit 4f1caf11e9
3 changed files with 32 additions and 0 deletions
ironic_python_agent
extensions
tests/unit/extensions
releasenotes/notes

@ -374,3 +374,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)

@ -760,6 +760,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',

@ -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.