From 0d37f1f21ae2707920128b1c3516dde1dab0b38c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu>
Date: Fri, 6 Oct 2017 13:52:36 +0200
Subject: [PATCH] Changed timeout in nginx vhost test (refs #22843).

---
 tests/test_nginx_vhosts.py | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/tests/test_nginx_vhosts.py b/tests/test_nginx_vhosts.py
index bc759981..69be6eb4 100755
--- a/tests/test_nginx_vhosts.py
+++ b/tests/test_nginx_vhosts.py
@@ -10,6 +10,11 @@ import re
 import requests
 import socket
 import sys
+try:
+    from requests.packages.urllib3.exceptions import InsecureRequestWarning
+    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
+except ImportError:
+    requests.packages.urllib3.disable_warnings()
 
 '''
 This script checks for all enabled vhosts in Nginx conf that:
@@ -70,7 +75,7 @@ for name in os.listdir(nginx_dir):
         url = '%s://%s' % ('https' if https else 'http', domain)
         sys.stdout.write('Testing url "%s":\n' % url)
         if name.startswith('mediaserver') and url not in celerity_conf:
-            sys.stdout.write('Url "%s" not found in celerity conf; it should also be set in the MediaWorker.\n' % url)
+            sys.stdout.write('\033[93mWarning:\033[0m Url "%s" not found in celerity conf; it should also be set in the MediaWorker.\n' % url)
             warnings += 1
         # test domain IP
         ip_error = None
@@ -94,37 +99,47 @@ for name in os.listdir(nginx_dir):
                 sys.stdout.write('\033[94mIgnored (%s)\033[0m' % ip_warning)
                 ip_warning = None
             else:
-                sys.stdout.write('\033[91mWarning (%s)\033[0m' % ip_warning)
+                sys.stdout.write('\033[93mWarning (%s)\033[0m' % ip_warning)
         else:
             sys.stdout.write('\033[92mOK (127.0.0.1)\033[0m')
         # test url
         sys.stdout.write(', status: ')
         req_error = False
         try:
-            req = requests.get(url, verify=False, proxies={'http': '', 'https': ''}, timeout=10)
+            req = requests.get(url, verify=False, proxies={'http': '', 'https': ''}, timeout=30)
+            req_time = int(1000 * req.elapsed.total_seconds())
         except Exception as e:
             code = str(e)
+            req_time = 0
         else:
             code = req.status_code
         if code not in (200, 403):
-            sys.stdout.write('\033[91mKO (%s)\033[0m' % code)
+            sys.stdout.write('\033[91mKO (%s, %sms)\033[0m' % (code, req_time))
             req_error = True
         else:
-            sys.stdout.write('\033[92mOK (%s)\033[0m' % code)
+            if req_time > 10000:
+                sys.stdout.write('\033[93mOK (%s, %sms)\033[0m' % (code, req_time))
+                warnings += 1
+            else:
+                sys.stdout.write('\033[92mOK (%s, %sms)\033[0m' % (code, req_time))
             if 'mediaserver' in name and wowza_dir:
                 # test /streaming url
                 sys.stdout.write(', streaming: ')
                 try:
-                    req = requests.get(url + '/streaming/', verify=False, proxies={'http': '', 'https': ''}, timeout=10)
+                    req = requests.get(url + '/streaming/', verify=False, proxies={'http': '', 'https': ''}, timeout=30)
+                    req_time = int(1000 * req.elapsed.total_seconds())
                 except Exception as e:
                     code = str(e)
+                    req_time = 0
                 else:
                     code = req.status_code
                 if code != 200:
-                    sys.stdout.write('\033[91mKO (%s)\033[0m' % code)
+                    sys.stdout.write('\033[91mKO (%s, %sms)\033[0m' % (code, req_time))
                     req_error = True
+                elif req_time > 10000:
+                    sys.stdout.write('\033[93mOK (%s, %sms)\033[0m' % (code, req_time))
                 else:
-                    sys.stdout.write('\033[92mOK (%s)\033[0m' % code)
+                    sys.stdout.write('\033[92mOK (%s, %sms)\033[0m' % (code, req_time))
         sys.stdout.write('.\n')
 
         if ip_warning:
-- 
GitLab