Skip to content
Snippets Groups Projects
Commit 65ca2aec authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Moved tests execution in a dedicated file (refs #20133).

parent 2b041440
No related branches found
No related tags found
No related merge requests found
......@@ -26,10 +26,6 @@ echo "NGINX" >> /root/deployment.results
grep server_name /etc/nginx/sites-enabled/* | uniq >> /root/deployment.results
echo "" >> /root/deployment.results
echo "RTMP" >> /root/deployment.results
cat /etc/hca/rtmp.ini | grep -v '#' >> /root/deployment.results
echo "" >> /root/deployment.results
echo "SERVICES" >> /root/deployment.results
echo "mediaserver $(service mediaserver status | grep Active)" >> /root/deployment.results
echo "WowzaStreamingEngine $(service WowzaStreamingEngine status | grep Active)" >> /root/deployment.results
......
......@@ -13,12 +13,20 @@ from utils import log
class EnvSetup():
USAGE = '''%s [-d] [-h] [<action id>]
-d: debug mode (can be started with non root users).
-h: show this message.
action id: specify which action should be started (non interactive).''' % __file__
PY_SETUP_NAME = '0_setup.py'
BASH_SETUP_NAME = '0_setup.sh'
def __init__(self, *args):
self.display_header()
args = list(args)
# Check if help is required
if '-h' in args:
log('USAGE: ' + self.USAGE)
sys.exit(0)
# Check current dir
root_dir = utils.get_dir(__file__)
if root_dir != '':
......@@ -87,7 +95,6 @@ class EnvSetup():
else:
log(' \033[1;94m%s\033[0m' % (action['label']))
log('')
log(' t: Run tests')
log(' c: Configuration status')
log(' e: Exit\n')
log('Info:')
......@@ -106,37 +113,7 @@ class EnvSetup():
log('Exit')
sys.exit(0)
exit_code = 0
if target == 't':
# Run tests
path = os.path.join(self.root_dir, 'tests')
if not os.path.isdir(path):
exit_code = 1
log('The tests dir is missing (%s).' % path)
else:
os.chdir(path)
names = os.listdir(path)
names.sort()
results = list()
for name in names:
log('\033[1;95m-- Test "%s" --\033[0;0m' % name)
test_path = os.path.join(path, name)
try:
code = utils.exec_cmd(test_path)
if code != 0:
raise Exception('Command exited with code %s.' % code)
except Exception as e:
exit_code = 1
log(e)
results.append((False, test_path))
else:
results.append((True, test_path))
log('\nTests results:')
for success, test_path in results:
if success:
log(' %s: \033[92msuccess\033[0m' % test_path)
else:
log(' %s: \033[91mfailure\033[0m' % test_path)
elif target == 'c':
if target == 'c':
# Display current configuration
log('Configuration status:')
override = utils.get_conf('_override')
......
tester.py 0 → 100755
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Script to start tests and to manage their results
'''
import os
import sys
import utils
from utils import log
class Tester():
USAGE = '''%s [-e] [-d] [-h]
-e: send email with report.
-d: debug mode (can be started with non root users).
-h: show this message.''' % __file__
def __init__(self, *args):
log('\033[96m-------------------------------\033[0m')
log('\033[96m- UbiCast applications tester -\033[0m')
log('\033[96m-------------------------------\033[0m')
args = list(args)
# Check if help is required
if '-h' in args:
log('USAGE: ' + self.USAGE)
sys.exit(0)
# Check current dir
root_dir = utils.get_dir(__file__)
if root_dir != '':
os.chdir(root_dir)
self.root_dir = root_dir
# Add to python path
if root_dir not in sys.path:
sys.path.append(root_dir)
# Check that this script is run by root
debug = '-d' in args
if debug:
args.remove('-d')
code, out = utils.exec_cmd(['whoami'], get_out=True)
if out != 'root' and not debug:
log('This script should be run as root user.')
sys.exit(1)
# Load conf
conf = utils.load_conf()
if not conf:
log('No configuration loaded.')
sys.exit(1)
# Check for email value
email = '-e' in args
if email:
args.remove('-i')
exit_code = self.run_tests(email)
sys.exit(exit_code)
def get_file_description(self, path):
with open(path, 'r') as fo:
content = fo.read()
description = ''
if path.endswith('.py'):
start = content.find('\'\'\'')
if start > 0:
start += 3
end = content.find('\'\'\'', start)
if end > 0:
description = content[start:end].strip()
else:
for line in content.split('\n'):
if line.startswith('#!'):
continue
elif line.startswith('#'):
description += line + '\n'
else:
break
return description.strip()
def run_tests(self, email=False):
path = os.path.join(self.root_dir, 'tests')
if not os.path.isdir(path):
log('The tests dir is missing ("%s").' % path)
return 1
os.chdir(path)
names = os.listdir(path)
names.sort()
if not names:
log('The tests dir is empty ("%s").' % path)
return 1
results = list()
exit_code = 0
# Run all tests
for name in names:
log('\033[1;95m-- Test "%s" --\033[0;0m' % name)
test_path = os.path.join(path, name)
# Get test description
description = self.get_file_description(test_path)
# Run test
try:
code = utils.exec_cmd(test_path)
if code != 0:
raise Exception('Command exited with code %s.' % code)
except Exception as e:
exit_code = 1
log(e)
results.append((False, test_path, description))
else:
results.append((True, test_path, description))
log('\nTests results:')
html_report = '<table>'
html_report += '\n<tr><th>Test</th><th>Result</th><th>Description</th></tr>'
for success, test_path, description in results:
file_name = os.path.basename(test_path)
if success:
html_result = '<span style="color: green;">success</span>'
term_result = '\033[92msuccess\033[0m'
else:
html_result = '<span style="color: red;">failure</span>'
term_result = '\033[91mfailure\033[0m'
log(' %s: %s' % (file_name, term_result))
html_report += '\n<tr><td>%s</td><td>%s</td><td>%s</td></tr>' % (file_name, html_result, description)
html_report += '\n</table>'
return exit_code
if __name__ == '__main__':
Tester(*sys.argv[1:])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment