diff --git a/ironic_python_agent/extensions/standby.py b/ironic_python_agent/extensions/standby.py index 238a524f8..9dc23fa2a 100644 --- a/ironic_python_agent/extensions/standby.py +++ b/ironic_python_agent/extensions/standby.py @@ -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) diff --git a/ironic_python_agent/tests/unit/extensions/test_standby.py b/ironic_python_agent/tests/unit/extensions/test_standby.py index 75d2ce96e..e83fd1eed 100644 --- a/ironic_python_agent/tests/unit/extensions/test_standby.py +++ b/ironic_python_agent/tests/unit/extensions/test_standby.py @@ -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', diff --git a/releasenotes/notes/new-sync-command-6f5fa55df2fd5903.yaml b/releasenotes/notes/new-sync-command-6f5fa55df2fd5903.yaml new file mode 100644 index 000000000..07b4b36e6 --- /dev/null +++ b/releasenotes/notes/new-sync-command-6f5fa55df2fd5903.yaml @@ -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.