diff --git a/tests/test_dns_records.py b/tests/test_dns_records.py index 06d4552a9c195f4c928b2a2f7b1d9ce833a452d9..a8cb6a9ffff1483ffa3db2476219bef5a5af0693 100755 --- a/tests/test_dns_records.py +++ b/tests/test_dns_records.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Copyright 2017, Florent Thiery ''' -Checks that DNS records are provided by the customer servers +Checks that DNS records are provided by the customer servers are correctly set ''' import subprocess import os @@ -29,7 +29,7 @@ def get_result(output): if "has address " in line: return line.split("has address ")[1] -def check_dns(hostname): +def check_dns(hostname, expected_ip): all_ok = True for resolver in resolvers: status, output = subprocess.getstatusoutput("host %s %s" % (hostname, resolver)) @@ -37,6 +37,9 @@ def check_dns(hostname): if success: color = GREEN address = get_result(output) + if address != expected_ip: + color = RED + all_ok = False else: color = RED all_ok = False @@ -48,16 +51,32 @@ if os.path.isfile('../utils.py'): all_ok = True es_utils = imp.load_source('es_utils', '../utils.py') conf = es_utils.load_conf() - servers = ( + + ip = conf.get('NETWORK_IP') + + conf_resolvers_keys = ( + 'NETWORK_DNS1', + 'NETWORK_DNS2', + ) + for conf_resolver_key in conf_resolvers_keys: + conf_resolver = conf.get(conf_resolver_key) + if conf_resolver not in resolvers: + print('Resolver %s not configured on the system' % conf_resolver) + all_ok = False + + conf_servers = ( 'MS_SERVER_NAME', 'MONITOR_SERVER_NAME', 'CM_SERVER_NAME', ) - for s in servers: - hostname = conf.get('MS_SERVER_NAME') - ok = check_dns(hostname) + for s in conf_servers: + hostname = conf.get(s) + ok = check_dns(hostname, ip) if not ok: all_ok = False +else: + print('conf.sh not found') + sys.exit(1) if not all_ok: sys.exit(1)