Skip to content
Snippets Groups Projects
Commit b1e34ed1 authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Handle multiple servers in ntp test.

parent 42333296
No related branches found
No related tags found
No related merge requests found
...@@ -12,17 +12,17 @@ import imp ...@@ -12,17 +12,17 @@ import imp
# Check that ntpd is synced # Check that ntpd is synced
if os.path.isfile('/usr/bin/ntpq'): if os.path.isfile('/usr/bin/ntpq'):
cmd = "LANG=C ntpq -pd" cmd = 'LANG=C ntpq -pd'
expected = "remote" expected = 'remote'
ntpconf = '/etc/ntp.conf' ntpconf = '/etc/ntp.conf'
ntpconf_expected = 'server ' ntpconf_expected = 'server '
else: else:
cmd = "LANG=C timedatectl" cmd = 'LANG=C timedatectl'
expected = 'NTP synchronized' expected = 'NTP synchronized'
ntpconf = '/etc/systemd/timesyncd.conf' ntpconf = '/etc/systemd/timesyncd.conf'
ntpconf_expected = 'NTP=' ntpconf_expected = 'NTP='
print("Running %s" % cmd) print('Running %s' % cmd)
status = subprocess.getoutput(cmd) status = subprocess.getoutput(cmd)
if expected not in status: if expected not in status:
print('NTP not working: %s' % status) print('NTP not working: %s' % status)
...@@ -36,19 +36,21 @@ print('Checking NTP server conforms to conf') ...@@ -36,19 +36,21 @@ print('Checking NTP server conforms to conf')
if os.path.isfile('../utils.py'): if os.path.isfile('../utils.py'):
es_utils = imp.load_source('es_utils', '../utils.py') es_utils = imp.load_source('es_utils', '../utils.py')
conf = es_utils.load_conf() conf = es_utils.load_conf()
NTP_SERVER = conf.get('NTP_SERVER') or 'ntp.ubuntu.com' expected_servers = (conf.get('NTP_SERVER') or 'ntp.ubuntu.com').split(',')
with open(ntpconf, 'r') as f: with open(ntpconf, 'r') as f:
d = f.read() d = f.read()
servers = list() servers = list()
for l in d.split('\n'): for l in d.split('\n'):
if l.startswith(ntpconf_expected): if l.startswith(ntpconf_expected):
servers.append(l.split(ntpconf_expected)[1]) servers.append(l[len(ntpconf_expected):])
if not '%s%s' % (ntpconf_expected, NTP_SERVER) in d: for expected_server in expected_servers:
print('Expected NTP server %s not found in %s, found %s instead' % (NTP_SERVER, ntpconf, servers)) if expected_server not in servers:
sys.exit(1) print('Expected NTP server %s not found in %s, found %s instead.' % (expected_server, ntpconf, servers))
else: sys.exit(1)
print('Expected NTP server %s found in configuration (total servers: %s)' % (NTP_SERVER, len(servers))) else:
print('Expected NTP server %s found in configuration (total servers: %s).' % (expected_server, len(servers)))
print('NTP OK')
else: else:
print('Could not find envsetup conf file or not running from expected location') print('Could not find envsetup conf file or not running from expected location.')
sys.exit(1) sys.exit(1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment