From 55531557692ed00029f6c2cb5251dc4a6972de82 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florent=20Thi=C3=A9ry?= <florent.thiery@ubicast.eu>
Date: Wed, 22 Feb 2017 18:41:24 +0100
Subject: [PATCH] check if ip is the right one, fix typo, check if resolvers
 are configured, refs #20581

---
 tests/test_dns_records.py | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/tests/test_dns_records.py b/tests/test_dns_records.py
index 06d4552a..a8cb6a9f 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)
-- 
GitLab