From cc62161b5696ae00148d75cc1ebb41581279bc79 Mon Sep 17 00:00:00 2001 From: Nathan Cutler Date: Sat, 11 Feb 2017 19:28:03 +0100 Subject: [PATCH] task/clock: add chrony support Signed-off-by: Nathan Cutler Signed-off-by: Kyr Shatskyy --- teuthology/nuke/actions.py | 13 ++++++-- teuthology/task/clock.py | 66 ++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/teuthology/nuke/actions.py b/teuthology/nuke/actions.py index d994ca95c0..b9583e8180 100644 --- a/teuthology/nuke/actions.py +++ b/teuthology/nuke/actions.py @@ -396,13 +396,20 @@ def synch_clocks(remotes): for remote in remotes: remote.run( args=[ - 'sudo', 'service', 'ntp', 'stop', + 'sudo', 'systemctl', 'stop', 'ntp.service', run.Raw('||'), + 'sudo', 'systemctl', 'stop', 'ntpd.service', run.Raw('||'), + 'sudo', 'systemctl', 'stop', 'chronyd.service', run.Raw('&&'), - 'sudo', 'ntpdate-debian', + 'sudo', 'ntpdate-debian', run.Raw('||'), + 'sudo', 'ntp', '-gq', run.Raw('||'), + 'sudo', 'ntpd', '-gq', run.Raw('||'), + 'sudo', 'chronyc', 'sources', run.Raw('&&'), 'sudo', 'hwclock', '--systohc', '--utc', run.Raw('&&'), - 'sudo', 'service', 'ntp', 'start', + 'sudo', 'systemctl', 'start', 'ntp.service', run.Raw('||'), + 'sudo', 'systemctl', 'start', 'ntpd.service', run.Raw('||'), + 'sudo', 'systemctl', 'start', 'chronyd.service', run.Raw('||'), 'true', # ignore errors; we may be racing with ntpd startup ], diff --git a/teuthology/task/clock.py b/teuthology/task/clock.py index 53a349c866..69474e9734 100644 --- a/teuthology/task/clock.py +++ b/teuthology/task/clock.py @@ -3,9 +3,8 @@ Clock synchronizer """ import logging import contextlib -import os -from ..orchestra import run +from teuthology.orchestra import run log = logging.getLogger(__name__) @@ -32,32 +31,25 @@ def task(ctx, config): log.info('Syncing clocks and checking initial clock skew...') for rem in ctx.cluster.remotes.iterkeys(): - ntpconf = rem.get_file('/etc/ntp.conf') - servers = [ - l.strip().split()[1] for l in open(ntpconf, 'r').readlines() - if l.startswith('server') - ] - os.remove(ntpconf) - # CentOS calls it ntpd, Xenial/Trusty are ntp. Thanks guys. - args = [ - 'sudo', 'service', 'ntp', 'stop', - run.Raw('||'), - 'sudo', 'service', 'ntpd', 'stop', - run.Raw(';'), - 'sudo', - 'ntpdate', - ] - args.extend(servers) - args.extend([ - run.Raw(';'), - 'sudo', 'service', 'ntp', 'start', - run.Raw('||'), - 'sudo', 'service', 'ntpd', 'start', - run.Raw(';'), - 'PATH=/usr/bin:/usr/sbin', - 'ntpq', '-p', - ]) - rem.run(args=args) + rem.run( + args = [ + 'sudo', 'systemctl', 'stop', 'ntp.service', run.Raw('||'), + 'sudo', 'systemctl', 'stop', 'ntpd.service', run.Raw('||'), + 'sudo', 'systemctl', 'stop', 'chronyd.service', + run.Raw(';'), + 'sudo', 'ntpd', '-gq', run.Raw('||'), + 'sudo', 'chronyc', 'makestep', + run.Raw(';'), + 'sudo', 'systemctl', 'start', 'ntp.service', run.Raw('||'), + 'sudo', 'systemctl', 'start', 'ntpd.service', run.Raw('||'), + 'sudo', 'systemctl', 'start', 'chronyd.service', + run.Raw(';'), + 'PATH=/usr/bin:/usr/sbin', 'ntpq', '-p', run.Raw('||'), + 'PATH=/usr/bin:/usr/sbin', 'chronyc', 'sources', + run.Raw('||'), + 'true' + ], + ) try: yield @@ -67,8 +59,10 @@ def task(ctx, config): for rem in ctx.cluster.remotes.iterkeys(): rem.run( args=[ - 'PATH=/usr/bin:/usr/sbin', - 'ntpq', '-p', + 'PATH=/usr/bin:/usr/sbin', 'ntpq', '-p', run.Raw('||'), + 'PATH=/usr/bin:/usr/sbin', 'chronyc', 'sources', + run.Raw('||'), + 'true' ], ) @@ -85,8 +79,10 @@ def check(ctx, config): for rem in ctx.cluster.remotes.iterkeys(): rem.run( args=[ - 'PATH=/usr/bin:/usr/sbin', - 'ntpq', '-p', + 'PATH=/usr/bin:/usr/sbin', 'ntpq', '-p', run.Raw('||'), + 'PATH=/usr/bin:/usr/sbin', 'chronyc', 'sources', + run.Raw('||'), + 'true' ], ) @@ -98,7 +94,9 @@ def check(ctx, config): for rem in ctx.cluster.remotes.iterkeys(): rem.run( args=[ - 'PATH=/usr/bin:/usr/sbin', - 'ntpq', '-p', + 'PATH=/usr/bin:/usr/sbin', 'ntpq', '-p', run.Raw('||'), + 'PATH=/usr/bin:/usr/sbin', 'chronyc', 'sources', + run.Raw('||'), + 'true' ], ) -- 2.39.5