-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrun_unit_tests.py
115 lines (88 loc) · 4.2 KB
/
run_unit_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# grown-up modules
import compose.cli.command
import docker
import logging
import os
# local modules
from irods_testing_environment import archive
from irods_testing_environment import context
from irods_testing_environment import irods_config
from irods_testing_environment import services
from irods_testing_environment import test_utils
if __name__ == "__main__":
import argparse
import textwrap
import cli
from irods_testing_environment import logs
parser = argparse.ArgumentParser(description='Run iRODS tests in a consistent environment.')
cli.add_common_args(parser)
cli.add_compose_args(parser)
cli.add_database_config_args(parser)
cli.add_irods_package_args(parser)
cli.add_irods_test_args(parser)
args = parser.parse_args()
if not args.package_version and not args.install_packages:
print('--irods-package-version is required when using --use-static-image')
exit(1)
if args.package_directory and args.package_version:
print('--irods-package-directory and --irods-package-version are incompatible')
exit(1)
project_directory = os.path.abspath(args.project_directory or os.getcwd())
if not args.install_packages:
os.environ['dockerfile'] = 'release.Dockerfile'
if args.package_version:
os.environ['irods_package_version'] = args.package_version
ctx = context.context(docker.from_env(use_ssh_client=True),
compose.cli.command.get_project(
project_dir=project_directory,
project_name=args.project_name))
if args.output_directory:
dirname = args.output_directory
else:
import tempfile
dirname = tempfile.mkdtemp(prefix=ctx.compose_project.name)
job_name = test_utils.job_name(ctx.compose_project.name, args.job_name)
output_directory = test_utils.make_output_directory(dirname, job_name)
logs.configure(args.verbosity, os.path.join(output_directory, 'script_output.log'))
rc = 0
containers = None
try:
if args.do_setup:
# Bring up the services
logging.debug('bringing up project [{}]'.format(ctx.compose_project.name))
consumer_count = 0
services.create_topologies(ctx,
zone_count=args.executor_count,
externals_directory=args.irods_externals_package_directory,
package_directory=args.package_directory,
package_version=args.package_version,
odbc_driver=args.odbc_driver,
consumer_count=consumer_count,
install_packages=args.install_packages)
# Configure the containers for running iRODS automated tests
logging.info('configuring iRODS containers for testing')
irods_config.configure_irods_testing(ctx.docker_client, ctx.compose_project)
# Get the container on which the command is to be executed
containers = [
ctx.docker_client.containers.get(
context.container_name(ctx.compose_project.name,
context.irods_catalog_provider_service(),
service_instance=i + 1)
)
for i in range(args.executor_count)
]
rc = test_utils.run_unit_tests(containers, args.tests, args.fail_fast)
except Exception as e:
logging.critical(e)
raise
finally:
if containers:
# Just grab the version and sha from the first container since they are all running the same thing.
cli.log_irods_version_and_commit_id(containers[0])
if args.save_logs:
logging.warning('collecting logs [{}]'.format(output_directory))
# collect the usual logs (unit test reports appear in /var/lib/irods/log for now)
logs.collect_logs(ctx.docker_client, ctx.irods_containers(), output_directory)
if args.cleanup_containers:
ctx.compose_project.down(include_volumes=True, remove_image_type=False)
exit(rc)