summaryrefslogtreecommitdiff
path: root/ironic_python_agent/extensions
diff options
context:
space:
mode:
authorJulia Kreger <juliaashleykreger@gmail.com>2020-02-14 13:45:12 -0800
committerJulia Kreger <juliaashleykreger@gmail.com>2020-03-07 09:16:19 -0800
commitcee4bfc4bc2b038ca5c092aa73b1f9f670b58f66 (patch)
tree654228ecd4c566e6088c441257bc6a7ad1793d22 /ironic_python_agent/extensions
parent48ef7c918898b7ce679d500270018b831a81ae03 (diff)
downloadironic-python-agent-cee4bfc4bc2b038ca5c092aa73b1f9f670b58f66.tar.gz
Add NTP time sync
Attempt to sync the clock and save it to the hardware clock. This feature supports use of chrony or ntpdate. Sem-Ver: feature Change-Id: I178d7614429d582e742d9cba6d0fa3ae099775e3 Story: 1619054 Task: 11591
Diffstat (limited to 'ironic_python_agent/extensions')
-rw-r--r--ironic_python_agent/extensions/standby.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/ironic_python_agent/extensions/standby.py b/ironic_python_agent/extensions/standby.py
index 7b911ead..ac1ded1f 100644
--- a/ironic_python_agent/extensions/standby.py
+++ b/ironic_python_agent/extensions/standby.py
@@ -617,6 +617,11 @@ class StandbyExtension(base.BaseAgentExtension):
:raises: SystemRebootError if the command errors out with an
unsuccessful exit code.
"""
+ # TODO(TheJulia): When we have deploy/clean steps, we should remove
+ # this upon shutdown. The clock sync deploy step can run before
+ # completing other operations.
+ self._sync_clock(ignore_errors=True)
+
if command not in ('reboot', 'poweroff'):
msg = (('Expected the command "poweroff" or "reboot" '
'but received "%s".') % command)
@@ -663,3 +668,28 @@ class StandbyExtension(base.BaseAgentExtension):
error_msg = 'Flushing file system buffers failed. Error: %s' % e
LOG.error(error_msg)
raise errors.CommandExecutionError(error_msg)
+
+ # TODO(TheJulia): Once we have deploy/clean steps, this should
+ # become a step, which we ideally have enabled by default.
+ def _sync_clock(self, ignore_errors=False):
+ """Sync the clock to a configured NTP server.
+
+ :param ignore_errors: Boolean option to indicate if the
+ errors should be fatal. This option
+ does not override the fail_if_clock_not_set
+ configuration option.
+ :raises: ClockSyncError if a failure is encountered and
+ errors are not ignored.
+ """
+ try:
+ utils.sync_clock(ignore_errors=ignore_errors)
+ # Sync the system hardware clock from the software clock,
+ # as they are independent and the HW clock can still drift
+ # with long running ramdisks.
+ utils.execute('hwclock', '-v', '--systohc')
+ except (processutils.ProcessExecutionError,
+ errors.CommandExecutionError) as e:
+ msg = 'Failed to sync hardware clock: %s' % e
+ LOG.error(msg)
+ if CONF.fail_if_clock_not_set or not ignore_errors:
+ raise errors.ClockSyncError(msg)