def install_npm_dependencies(work_dir, project, logger, reactor): _verify_npm(reactor) exec_command( 'npm', ['install'], f'Failed to install package.json - required for integration tests', f'package_json_npm_install.log', project, reactor, logger, report=False, working_dir=work_dir)
def install_cypress(logger: Logger, project: Project, reactor: Reactor, work_dir): _verify_npm(reactor) logger.info(f"Ensuring cypress is installed") exec_command('npm', ['install', "cypress"], f'Failed to install cypress - required for integration tests', f'{"cypress"}_npm_install.log', project, reactor, logger, report=False, working_dir=work_dir)
def _run_cypress_tests_in_directory(work_dir, logger, project, reactor: Reactor): target_url = project.get_mandatory_property(INTEGRATION_TARGET_URL) environment = project.get_mandatory_property(ENVIRONMENT) if not os.path.exists(work_dir): logger.info("Skipping cypress run: no tests") return False logger.info( f"Found {len(os.listdir(work_dir))} files in cypress test directory") # Validate NPM install and Install cypress package_json = os.path.join(work_dir, "package.json") if os.path.exists(package_json): logger.info("Found package.json installing dependencies") tool_utility.install_npm_dependencies(work_dir, project=project, logger=logger, reactor=reactor) else: install_cypress(logger=logger, project=project, reactor=reactor, work_dir=work_dir) executable = os.path.join(work_dir, "node_modules/cypress/bin/cypress") results_file, run_name = get_test_report_file(project=project, test_dir=work_dir, tool="cypress") # Run the actual tests against the baseURL provided by ${integration_target} args = [ "run", "--config", f"baseUrl={target_url}", "--reporter-options", f"mochaFile={results_file}" ] config_file_path = f'{environment}-config.json' if os.path.exists(os.path.join(work_dir, config_file_path)): args.append("--config-file") args.append(config_file_path) logger.info(f"Running cypress on host: {target_url}") exec_utility.exec_command( command_name=executable, args=args, failure_message="Failed to execute cypress tests", log_file_name='cypress_run.log', project=project, reactor=reactor, logger=logger, working_dir=work_dir, report=False) # workaround but cypress output are relative to location of cypress.json so we need to collapse if os.path.exists(f"{work_dir}/target"): shutil.copytree(f"{work_dir}/target", "./target", dirs_exist_ok=True) return True
def create_bucket(self, logger, project, reactor): app_group, app_name, bucket, environment, role = get_project_metadata( logger, project) S3ArtifactManager.verify_aws_cli(reactor) res = self.does_bucket_exist(logger, project, reactor) if res: return exec_utility.exec_command(command_name='aws', args=[ 's3api', 'create-bucket', '--acl', 'private', '--bucket', bucket ], failure_message=f"Failed to create bucket", log_file_name='s3-create-bucket', project=project, reactor=reactor, logger=logger, report=False)
def _s3_transfer(source, destination, project, reactor, logger, recursive=True): logger.info(f"Proceeding to transfer {source} to {destination}") S3ArtifactManager.verify_aws_cli(reactor) # aws s3 cp myDir s3://mybucket/ --recursive args = ['s3', 'cp', source, destination] if recursive: args.append("--recursive") exec_utility.exec_command( command_name='aws', args=args, failure_message= f"Failed to transfer integration artifacts to {destination}", log_file_name='s3-artifact-transfer', project=project, reactor=reactor, logger=logger, report=False)
def does_bucket_exist(self, logger, project, reactor): app_group, app_name, bucket, environment, role = get_project_metadata( logger, project) return exec_utility.exec_command( command_name='aws', args=['s3api', 'head-bucket', '--bucket', bucket], failure_message=f"Failed to find bucket", log_file_name='s3-head-bucket', project=project, reactor=reactor, logger=logger, raise_exception=False, report=False)