From 294b54fd076ac23dd7bca24b670045156de31103 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu>
Date: Wed, 15 Mar 2017 11:33:37 +0100
Subject: [PATCH] Added a conf to ignore domain resolution check (refs #20802).

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

diff --git a/tests/test_nginx_vhosts.py b/tests/test_nginx_vhosts.py
index f916eab2..e6a4f491 100755
--- a/tests/test_nginx_vhosts.py
+++ b/tests/test_nginx_vhosts.py
@@ -4,6 +4,7 @@
 Criticality: High
 Tests that all webserver services (vhosts) are available and reachable.
 '''
+import imp
 import os
 import re
 import requests
@@ -31,23 +32,31 @@ if not os.path.exists(wowza_dir):
 else:
     print('Info: Wowza is installed, /streaming/ will be tested on mediaserver vhosts.')
 
+# get envsetup conf
+conf = dict()
+os.chdir(os.path.dirname(__file__))
+if os.path.isfile('../utils.py'):
+    es_utils = imp.load_source('es_utils', '../utils.py')
+    conf = es_utils.load_conf()
+
 # get enabled vhosts
+resolution_ignored = conf.get('TESTER_VHOST_RESOLUTION_IGNORED', '').split(',')
 requests.packages.urllib3.disable_warnings()
 found = False
 errors = 0
 for name in os.listdir(nginx_dir):
     path = os.path.join(nginx_dir, name)
     with open(path, 'r') as fo:
-        conf = fo.read()
-    conf = conf.replace('\t', ' ')
-    matching = re.search(r'.*server_name\ +([0-9a-zA-Z\.\-\_\ ]+);.*', conf)
+        vhost = fo.read()
+    vhost = vhost.replace('\t', ' ')
+    matching = re.search(r'.*server_name\ +([0-9a-zA-Z\.\-\_\ ]+);.*', vhost)
     if not matching:
         print('The server_name was not found in: "%s".' % path)
         errors += 1
         continue
     domains = matching.groups()[0].strip().split(' ')
-    https = re.search(r'listen +\w* +ssl;', conf) is not None \
-        or re.search(r'ssl +on;', conf) is not None
+    https = re.search(r'listen +\w* +ssl;', vhost) is not None \
+        or re.search(r'ssl +on;', vhost) is not None
     for domain in domains:
         if domain == 'localhost':
             continue  # status vhost
@@ -65,7 +74,11 @@ for name in os.listdir(nginx_dir):
                 ip_error = 'domain is resolved with %s instead of 127.0.0.1' % ip
         sys.stdout.write('  IP: ')
         if ip_error:
-            sys.stdout.write('\033[91mKO (%s)\033[0m' % ip_error)
+            if domain in resolution_ignored:
+                sys.stdout.write('\033[94mIgnored (%s)\033[0m' % ip_error)
+                ip_error = None
+            else:
+                sys.stdout.write('\033[91mKO (%s)\033[0m' % ip_error)
         else:
             sys.stdout.write('\033[92mOK (127.0.0.1)\033[0m')
         # test url
-- 
GitLab