From af9177fbca9300bee2f7ed8a23984ace33fb57c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florent=20Thi=C3=A9ry?= <florent.thiery@ubicast.eu> Date: Wed, 1 Feb 2017 10:48:30 +0100 Subject: [PATCH] rewrite ntp test fixes #20257 --- tests/test_ntp.py | 38 ++++++++++++++++++++++++++++++++++++++ tests/test_ntp.sh | 14 -------------- 2 files changed, 38 insertions(+), 14 deletions(-) create mode 100755 tests/test_ntp.py delete mode 100755 tests/test_ntp.sh diff --git a/tests/test_ntp.py b/tests/test_ntp.py new file mode 100755 index 00000000..f473be11 --- /dev/null +++ b/tests/test_ntp.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright 2017, Florent Thiery +import os +import sys +import subprocess +import shlex +import imp + +# Check that ntpd is synced +print('Running ntpq -pd') +ntpd_status = subprocess.getoutput('LANG=C ntpq -pd') +if not 'remote' in ntpd_status: + print('NTP not working, ntpq -p output:\n%s' % ntpd_status) + sys.exit(1) +else: + print('System is NTP synchronized') + +print('Checking NTP server conforms to conf') +if os.path.isfile('../utils.py'): + es_utils = imp.load_source('es_utils', '../utils.py') + conf = es_utils.load_conf() + NTP_SERVER = conf.get('NTP_SERVER1') + + with open('/etc/ntp.conf', 'r') as f: + d = f.read() + servers = list() + for l in d.split('\n'): + if l.startswith('server '): + servers.append(l.split('server ')[1]) + if not 'server %s' % NTP_SERVER in d: + print('Expected NTP server %s not found in /etc/ntp.conf, found %s instead' % (NTP_SERVER, servers)) + sys.exit(1) + else: + print('Expected NTP server found in configuration') +else: + print('Could not find envsetup conf file or not running from expected location') + sys.exit(1) diff --git a/tests/test_ntp.sh b/tests/test_ntp.sh deleted file mode 100755 index 3c91634b..00000000 --- a/tests/test_ntp.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -# Check that the time synchronization server is reachable. -set -e - -source /root/envsetup/conf.sh - -NTP_SERVER="$NTP_SERVER1" -if [ "${NTP_SERVER}" = "" ]; then - NTP_SERVER="ntp.ubuntu.com" -fi -echo "Testing NTP server: ${NTP_SERVER}" -service ntp stop -ntpdate -d ${NTP_SERVER} >/dev/null -service ntp restart -- GitLab