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

Added a setting to disable test of routing rules | refs #33094

parent 2dbf88d2
No related branches found
No related tags found
No related merge requests found
......@@ -134,15 +134,18 @@ MEDIAIMPORT_PASSWD=''
# -- Tester config --
# separate values with commas
TESTER_IGNORED_TESTS=''
# separate values with commas
TESTER_MS_INSTANCES=''
# maximum number of instances to test
# TESTER_MAX_INSTANCES is ignored if TESTER_MS_INSTANCES is set
TESTER_MAX_INSTANCES=''
# separate values with commas
TESTER_IGNORED_TESTS=''
# ignore routing rules in VOD/live/cache tests (enable this if the server cannot reach cache servers)
TESTER_IGNORE_ROUTING_RULES='0'
# ignore these dns names
TESTER_DNS_RESOLUTION_IGNORED=''
# ignore these nginx vhosts
TESTER_DNS_RESOLUTION_IGNORED=''
TESTER_VHOST_RESOLUTION_IGNORED=''
# encode report attachment to base64
TESTER_BASE64_ATTACH='0'
......
......@@ -122,16 +122,17 @@ class Tester():
if not conf:
print("No configuration loaded.")
sys.exit(1)
# Check for email value
# Check RAID status
if not raid_idle():
print("A RAID check or operation is in progress, aborting tests")
sys.exit(1)
# Get tests to run
tests = self.discover_tests(args.basic_tests, msuser=args.msuser, no_update=args.no_update)
if not tests:
print("No test to run.")
sys.exit(1)
if raid_idle():
exit_code = self.run_tests(tests, send_email=args.send_email, send_email_if_fail=args.send_email_if_fail)
else:
print("A RAID check or operation is in progress, aborting tests")
exit_code = 1
# Run tests
exit_code = self.run_tests(tests, send_email=args.send_email, send_email_if_fail=args.send_email_if_fail)
sys.exit(exit_code)
def parse_file_header(self, path):
......@@ -173,30 +174,39 @@ class Tester():
def discover_tests(self, basic_only=False, msuser=None, no_update=False):
ignored_tests = get_conf("TESTER_IGNORED_TESTS", "").split(",")
ignored_tests.append("__init__.py")
if basic_only:
tests = self.discover_basic_tests(ignored_tests)
elif msuser:
tests = self.discover_mediaserver_tests(msuser, no_update, ignored_tests)
else:
tests = self.discover_basic_tests(ignored_tests)
tests.extend(self.discover_mediaserver_tests(msuser, no_update, ignored_tests))
criticalities_map = {"Low": 1, "Normal": 2, "High": 3}
tests.sort(key=lambda i: (-criticalities_map.get(i[1], 0), i[0]))
return tests
def discover_basic_tests(self, ignored_tests=None):
# Get standard tests
path = os.path.join(self.root_dir, "scripts")
if not os.path.isdir(path):
print('The tests dir is missing ("%s").' % path)
return
names = os.listdir(path)
test_dir = os.path.join(self.root_dir, "scripts")
if not os.path.isdir(test_dir):
print('The tests dir is missing ("%s").' % test_dir)
return list()
names = os.listdir(test_dir)
names.sort()
if not names:
print('The tests dir is empty ("%s").' % path)
return
criticalities_map = {"Low": 1, "Normal": 2, "High": 3}
print('The tests dir is empty ("%s").' % test_dir)
return list()
tests = list()
for name in names:
if name in ignored_tests:
if ignored_tests and name in ignored_tests:
continue
test_path = os.path.join(path, name)
test_path = os.path.join(test_dir, name)
if os.path.isfile(test_path):
criticality, description = self.parse_file_header(test_path)
tests.append((name, criticality, description, [test_path]))
if basic_only:
tests.sort(key=lambda i: (-criticalities_map.get(i[1], 0), i[0]))
return tests
elif msuser:
tests = list()
tests.append((name, criticality, description, [test_path], None))
return tests
def discover_mediaserver_tests(self, msuser=None, no_update=False, ignored_tests=None):
# Get MS instances
ms_users = list()
for user in os.listdir("/home"):
......@@ -204,91 +214,96 @@ class Tester():
not msuser or user == msuser
):
ms_users.append(user)
# Get MediaServer tests
if ms_users:
ms_users.sort()
cleaned_list = list()
instances_to_test = get_conf("TESTER_MS_INSTANCES", "").split(",")
if instances_to_test:
for val in instances_to_test:
val = val.strip()
if not val:
continue
if val in ms_users:
cleaned_list.append(val)
else:
print(
'An inexisting instance has been requested for tests: "%s".'
% val
)
if cleaned_list:
ms_users = cleaned_list
else:
try:
max_instances = int(get_conf("TESTER_MAX_INSTANCES") or 2)
except Exception as e:
print("TESTER_MAX_INSTANCES has an invalid value: %s" % e)
max_instances = 2
if len(ms_users) > max_instances:
ms_users = ms_users[:max_instances]
print("Instances that will be tested: %s." % ", ".join(ms_users))
# Clone testing suite
ms_path = os.path.join(path, "ms-testing-suite")
if not os.path.exists(ms_path):
print('Cloning ms-testing-suite in "%s".' % ms_path)
subprocess.run(
[
"git",
"clone",
"--recursive",
"https://mirismanager.ubicast.eu/git/mediaserver/ms-testing-suite.git",
ms_path,
]
)
if os.path.exists(ms_path) and not no_update:
print('Updating ms-testing-suite in "%s".' % ms_path)
os.chdir(ms_path)
branch = get_conf("ENVSETUP_BRANCH") or "stable"
if branch:
subprocess.run(["git", "checkout", branch])
subprocess.run(["git", "fetch", "--recurse-submodules", "--all"])
subprocess.run(["git", "reset", "--hard", "origin/{}".format(branch)])
subprocess.run(["git", "pull", "--recurse-submodules"])
subprocess.run(["git", "submodule", "update", "--init", "--recursive"])
os.chdir(self.root_dir)
# Add tests to list
print("Add MediaServer tests if available.")
wowza_dir = "/usr/local/WowzaStreamingEngine"
etc_lives_conf = "/etc/mediaserver/lives.json"
local_lives_conf = "/home/%s/msinstance/conf/lives.json"
old_etc_lives_conf = "/etc/mediaserver/lives_conf.py"
old_local_lives_conf = "/home/%s/msinstance/conf/lives_conf.py"
for user in ms_users:
ms_tests = ["ms_vod_tester.py", "test_caches.py"]
# Check if live tests should be started
if (
os.path.exists(wowza_dir)
or os.path.exists(etc_lives_conf)
or os.path.exists(local_lives_conf % user)
or os.path.exists(old_etc_lives_conf)
or os.path.exists(old_local_lives_conf % user)
):
ms_tests.append("test_wowza_secure.py")
ms_tests.append("ms_live_tester.py")
for name in ms_tests:
if name in ignored_tests:
continue
test_path = os.path.join(ms_path, name)
criticality, description = self.parse_file_header(test_path)
tests.append(
(
"%s (%s)" % (name, user),
criticality,
description,
[test_path, user],
)
if not ms_users:
return list()
ms_users.sort()
cleaned_list = list()
instances_to_test = get_conf("TESTER_MS_INSTANCES", "").split(",")
if instances_to_test:
for val in instances_to_test:
val = val.strip()
if not val:
continue
if val in ms_users:
cleaned_list.append(val)
else:
print(
'An inexisting instance has been requested for tests: "%s".'
% val
)
tests.sort(key=lambda i: (-criticalities_map.get(i[1], 0), i[0]))
if cleaned_list:
ms_users = cleaned_list
else:
try:
max_instances = int(get_conf("TESTER_MAX_INSTANCES") or 2)
except Exception as e:
print("TESTER_MAX_INSTANCES has an invalid value: %s" % e)
max_instances = 2
if len(ms_users) > max_instances:
ms_users = ms_users[:max_instances]
print("Instances that will be tested: %s." % ", ".join(ms_users))
# Clone testing suite
ms_path = os.path.join(self.root_dir, "scripts", "ms-testing-suite")
if not os.path.exists(ms_path):
print('Cloning ms-testing-suite in "%s".' % ms_path)
subprocess.run(
[
"git",
"clone",
"--recursive",
"https://mirismanager.ubicast.eu/git/mediaserver/ms-testing-suite.git",
ms_path,
]
)
if not os.path.exists(ms_path):
print('The ms-testing-suite dir "%s" does not exist, no MediaServer test will be run.' % ms_path)
return list()
# Update testing suite if allowed
if not no_update:
print('Updating ms-testing-suite in "%s".' % ms_path)
os.chdir(ms_path)
branch = get_conf("ENVSETUP_BRANCH") or "stable"
if branch:
subprocess.run(["git", "checkout", branch])
subprocess.run(["git", "fetch", "--recurse-submodules", "--all"])
subprocess.run(["git", "reset", "--hard", "origin/{}".format(branch)])
subprocess.run(["git", "pull", "--recurse-submodules"])
subprocess.run(["git", "submodule", "update", "--init", "--recursive"])
os.chdir(self.root_dir)
# Build tests list
print("Add MediaServer tests if available.")
wowza_dir = "/usr/local/WowzaStreamingEngine"
etc_lives_conf = "/etc/mediaserver/lives.json"
local_lives_conf = "/home/%s/msinstance/conf/lives.json"
old_etc_lives_conf = "/etc/mediaserver/lives_conf.py"
old_local_lives_conf = "/home/%s/msinstance/conf/lives_conf.py"
tests = list()
for user in ms_users:
ms_tests = ["ms_vod_tester.py", "test_caches.py"]
# Check if live tests should be started
if (
os.path.exists(wowza_dir)
or os.path.exists(etc_lives_conf)
or os.path.exists(local_lives_conf % user)
or os.path.exists(old_etc_lives_conf)
or os.path.exists(old_local_lives_conf % user)
):
ms_tests.append("test_wowza_secure.py")
ms_tests.append("ms_live_tester.py")
ignore_rules = get_conf("TESTER_IGNORE_ROUTING_RULES", "0")
for name in ms_tests:
if ignored_tests and name in ignored_tests:
continue
test_path = os.path.join(ms_path, name)
if os.path.exists(test_path):
criticality, description = self.parse_file_header(test_path)
tests.append((
"%s (%s)" % (name, user),
criticality,
description,
[test_path, user],
{"IGNORE_ROUTING_RULES": ignore_rules},
))
return tests
def run_tests(self, tests, send_email=False, send_email_if_fail=False): # noqa: C901
......@@ -299,7 +314,7 @@ class Tester():
report_rows = [("Test", "Criticality", "Result", "Duration", "Description")]
report_rows_length = [len(t) for t in report_rows[0]]
out_of_support = False
for name, criticality, description, command in tests:
for name, criticality, description, command, env in tests:
print('\033[1;95m-- Test "%s" --\033[0;0m' % name)
start_date = datetime.datetime.utcnow()
print("Test start: %s UTC." % start_date.strftime("%Y-%m-%d %H:%M:%S"))
......@@ -307,11 +322,17 @@ class Tester():
count = 0
while count < 3:
if count > 0:
time.sleep(5 * count * count)
wait_time = 5 * count * count
print('Waiting %s s...' % wait_time)
time.sleep(wait_time)
count += 1
print("Attempt: %s" % str(count))
test_env = dict(os.environ)
if env:
test_env.update(env)
p = subprocess.run(
command,
env=test_env,
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
......
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