|
| 1 | +# grown-up modules |
| 2 | +import compose.cli.command |
| 3 | +import docker |
| 4 | +import logging |
| 5 | +import os |
| 6 | + |
| 7 | +# local modules |
| 8 | +from irods_testing_environment import archive |
| 9 | +from irods_testing_environment import context |
| 10 | +from irods_testing_environment import irods_config |
| 11 | +from irods_testing_environment import services |
| 12 | +from irods_testing_environment import test_utils |
| 13 | + |
| 14 | +if __name__ == "__main__": |
| 15 | + import argparse |
| 16 | + import textwrap |
| 17 | + import time |
| 18 | + |
| 19 | + import cli |
| 20 | + from irods_testing_environment import logs |
| 21 | + |
| 22 | + parser = argparse.ArgumentParser(description='Run iRODS tests in a consistent environment.') |
| 23 | + |
| 24 | + cli.add_common_args(parser) |
| 25 | + cli.add_compose_args(parser) |
| 26 | + cli.add_database_config_args(parser) |
| 27 | + cli.add_irods_package_args(parser) |
| 28 | + cli.add_irods_test_args(parser) |
| 29 | + |
| 30 | + args = parser.parse_args() |
| 31 | + |
| 32 | + if args.package_directory and args.package_version: |
| 33 | + print('--package-directory and --package-version are incompatible') |
| 34 | + exit(1) |
| 35 | + |
| 36 | + project_directory = os.path.abspath(args.project_directory or os.getcwd()) |
| 37 | + |
| 38 | + ctx = context.context(docker.from_env(), |
| 39 | + compose.cli.command.get_project( |
| 40 | + project_dir=project_directory, |
| 41 | + project_name=args.project_name)) |
| 42 | + |
| 43 | + if args.output_directory: |
| 44 | + dirname = args.output_directory |
| 45 | + else: |
| 46 | + import tempfile |
| 47 | + dirname = tempfile.mkdtemp(prefix=ctx.compose_project.name) |
| 48 | + |
| 49 | + job_name = test_utils.job_name(ctx.compose_project.name, args.job_name) |
| 50 | + |
| 51 | + output_directory = test_utils.make_output_directory(dirname, job_name) |
| 52 | + |
| 53 | + logs.configure(args.verbosity, os.path.join(output_directory, 'script_output.log')) |
| 54 | + |
| 55 | + rc = 0 |
| 56 | + last_command_to_fail = None |
| 57 | + |
| 58 | + try: |
| 59 | + if args.do_setup: |
| 60 | + # Bring up the services |
| 61 | + logging.debug('bringing up project [{}]'.format(ctx.compose_project.name)) |
| 62 | + consumer_count = 0 |
| 63 | + services.create_topologies(ctx, |
| 64 | + zone_count=args.executor_count, |
| 65 | + externals_directory=args.irods_externals_package_directory, |
| 66 | + package_directory=args.package_directory, |
| 67 | + package_version=args.package_version, |
| 68 | + odbc_driver=args.odbc_driver, |
| 69 | + consumer_count=consumer_count) |
| 70 | + |
| 71 | + # Configure the containers for running iRODS automated tests |
| 72 | + logging.info('configuring iRODS containers for testing') |
| 73 | + irods_config.configure_irods_testing(ctx.docker_client, ctx.compose_project) |
| 74 | + |
| 75 | + # Get the container on which the command is to be executed |
| 76 | + containers = [ |
| 77 | + ctx.docker_client.containers.get( |
| 78 | + context.container_name(ctx.compose_project.name, |
| 79 | + context.irods_catalog_provider_service(), |
| 80 | + service_instance=i + 1) |
| 81 | + ) |
| 82 | + for i in range(args.executor_count) |
| 83 | + ] |
| 84 | + |
| 85 | + start_time = time.time() |
| 86 | + |
| 87 | + rc = test_utils.run_unit_tests(containers, args.tests, args.fail_fast) |
| 88 | + |
| 89 | + end_time = time.time() |
| 90 | + |
| 91 | + logging.error('tests completed; time [{}] seconds, success [{}]'.format(end_time - start_time, rc is 0)) |
| 92 | + |
| 93 | + except Exception as e: |
| 94 | + logging.critical(e) |
| 95 | + |
| 96 | + raise |
| 97 | + |
| 98 | + finally: |
| 99 | + logging.warning('collecting logs [{}]'.format(output_directory)) |
| 100 | + logs.collect_logs(ctx.docker_client, ctx.irods_containers(), output_directory) |
| 101 | + |
| 102 | + ctx.compose_project.down(include_volumes=True, remove_image_type=False) |
| 103 | + |
| 104 | + exit(rc) |
0 commit comments