diff --git a/tests/test_nginx_vhosts.py b/tests/test_nginx_vhosts.py index e413f8c9ce89f6b5552fab2371170edd35746d76..46009f46ecd7c2232b0cb2591f854094d09613df 100755 --- a/tests/test_nginx_vhosts.py +++ b/tests/test_nginx_vhosts.py @@ -52,47 +52,57 @@ for name in os.listdir(nginx_dir): continue # status vhost found = True url = '%s://%s' % ('https' if https else 'http', domain) - sys.stdout.write('Testing url "%s": ' % url) + sys.stdout.write('Testing url "%s":\n' % url) + # test domain IP + ip_error = None try: ip = socket.gethostbyname(domain) except Exception as e: - sys.stdout.write('\033[91mKO (domain is not resolved: %s)\033[0m' % e) - errors += 1 + ip_error = 'domain is not resolved: %s' % e else: if ip != '127.0.0.1': - sys.stdout.write('\033[91mKO (domain is not resolved with 127.0.0.1)\033[0m') - errors += 1 - else: + 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) + 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) + except Exception as e: + code = str(e) + else: + code = req.status_code + if code not in (200, 403): + sys.stdout.write('\033[91mKO (%s)\033[0m' % code) + req_error = True + else: + sys.stdout.write('\033[92mOK (%s)\033[0m' % code) + if 'mediaserver' in name and wowza_dir: + # test /streaming url + sys.stdout.write(', streaming: ') try: - req = requests.get(url, verify=False, proxies={'http': '', 'https': ''}, timeout=10) + req = requests.get(url + '/streaming/', verify=False, proxies={'http': '', 'https': ''}, timeout=10) except Exception as e: code = str(e) else: code = req.status_code - if code not in (200, 403): + if code != 200: sys.stdout.write('\033[91mKO (%s)\033[0m' % code) - errors += 1 + req_error = True + elif 'Wowza Streaming Engine' not in req.text: + sys.stdout.write('\033[91mKO (%s, %s)\033[0m' % (code, req.text.replace('\n', ' ')[:200])) + req_error = True else: sys.stdout.write('\033[92mOK (%s)\033[0m' % code) - 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) - except Exception as e: - code = str(e) - else: - code = req.status_code - if code != 200: - sys.stdout.write('\033[91mKO (%s)\033[0m' % code) - errors += 1 - elif 'Wowza Streaming Engine' not in req.text: - sys.stdout.write('\033[91mKO (%s, %s)\033[0m' % (code, req.text.replace('\n', ' ')[:200])) - errors += 1 - else: - sys.stdout.write('\033[92mOK (%s)\033[0m' % code) sys.stdout.write('.\n') + if ip_error or req_error: + errors += 1 + if errors: print('%s vhost(s) did not correctly responded.' % errors) sys.exit(1)