summaryrefslogtreecommitdiff
path: root/ironic_python_agent/utils.py
diff options
context:
space:
mode:
authorArne Wiebalck <Arne.Wiebalck@cern.ch>2021-07-15 18:09:30 +0200
committerArne Wiebalck <Arne.Wiebalck@cern.ch>2021-07-16 10:28:31 +0200
commit5531d5cee744f90ff24231a9ef467282b254adc2 (patch)
treefb8945c438ed9eb183028b16e7a7386fbf8376c1 /ironic_python_agent/utils.py
parentcacdd9bab3e46ee5717c34c4facc27c14158bd70 (diff)
downloadironic-python-agent-5531d5cee744f90ff24231a9ef467282b254adc2.tar.gz
Force immediate NTP time sync with chronyd at IPA startup
In order to make sure we have the correct time early, e.g. by the time we create a TLS certificate, this patch proposes to force an immediate NTP update when using chronyd. While the previous approach uses the passed NTP server as well, the update may happen only after chronyd has performed measurements (which may be too late). Story: #2009058 Task: #42843 Change-Id: I6edafe8edeb8549f324959e7a1ec175c3049a515
Diffstat (limited to 'ironic_python_agent/utils.py')
-rw-r--r--ironic_python_agent/utils.py20
1 files changed, 5 insertions, 15 deletions
diff --git a/ironic_python_agent/utils.py b/ironic_python_agent/utils.py
index b5d0533a..2fc60ff1 100644
--- a/ironic_python_agent/utils.py
+++ b/ironic_python_agent/utils.py
@@ -835,21 +835,11 @@ def sync_clock(ignore_errors=False):
raise errors.CommandExecutionError(msg)
elif method == 'chronyd':
try:
- # 0 should be if chronyd started
- # 1 if already running
- execute('chronyd', check_exit_code=[0, 1])
- # NOTE(TheJulia): Once started, chronyd forks and stays in the
- # background as a server service, it will continue to keep the
- # clock in sync.
- try:
- execute('chronyc', 'add', 'server', CONF.ntp_server)
- except processutils.ProcessExecutionError as e:
- if 'Source already present' not in str(e):
- msg = 'Error occured adding ntp server: %s' % e
- LOG.error(msg)
- raise errors.CommandExecutionError(msg)
- # Force the clock to sync now.
- execute('chronyc', 'makestep')
+ # stop chronyd, ignore if it ran before or not
+ execute('chronyc', 'shutdown', check_exit_code=[0, 1])
+ # force a time sync now
+ query = "server " + CONF.ntp_server + " iburst"
+ execute("chronyd -q \'%s\'" % query, shell=True)
LOG.debug('Set software clock using chrony')
except (processutils.ProcessExecutionError,
errors.CommandExecutionError) as e: