def get_logs_cmd( ctx, spec_test_file, org_name, project_name, cluster_name_salt, polling_timeout, polling_frequency, ): """ Retrieves logs for the cluster and saves them in logs.tar.gz in the current working directory. """ # Step-1: determine the cluster name for the given test. cluster_name = get_cluster_name( get_test_name_from_spec_file(spec_test_file), cluster_name_salt) organization = cmd.get_one_organization_by_name(client=ctx.obj.client, organization_name=org_name) project = cmd.ensure_project(client=ctx.obj.client, project_name=project_name, organization_id=organization.id) get_logs(admin_client=ctx.obj.admin_client, project=project, cluster_name=cluster_name)
def __init__(self, *, client, admin_client, test_name, cluster_name, specification, configuration): # Initialize. self.client = client self.admin_client = admin_client self.id = test_name self.cluster_name = cluster_name self.spec = specification self.config = configuration self.failed = False self.expect_failure = specification.get('expectFailure', False) # Initialize attribute used for memoization of connection string. self.__connection_string = None # Initialize wrapper class for running workload executor. self.workload_runner = DriverWorkloadSubprocessRunner() # Validate and store organization and project. self.organization = get_one_organization_by_name( client=self.client, organization_name=self.config.organization_name) self.project = ensure_project(client=self.client, project_name=self.config.project_name, organization_id=self.organization.id)
def create_project_if_necessary( ctx, org_name, project_name, ): """Ensure that the given Atlas Project exists.""" org = cmd.get_one_organization_by_name(client=ctx.obj, organization_name=org_name) pprint( cmd.ensure_project(client=ctx.obj, project_name=project_name, organization_id=org.id))
def delete_test_cluster(ctx, spec_test_file, org_name, project_name, cluster_name_salt): """ Deletes the cluster used by the APM test. Deletes the cluster corresponding to the test found in the SPEC_TEST_FILE. This command does not error if a cluster bearing the expected name is not found. """ # Step-1: determine the cluster name for the given test. cluster_name = get_cluster_name(get_test_name_from_spec_file( spec_test_file), cluster_name_salt) # Step-2: delete the cluster. organization = cmd.get_one_organization_by_name( client=ctx.obj, organization_name=org_name) project = cmd.ensure_project( client=ctx.obj, project_name=project_name, organization_id=organization.id) try: ctx.obj.groups[project.id].clusters[cluster_name].delete() except AtlasApiBaseError: pass
def get_logs_cmd( ctx, spec_test_file, org_name, project_name, cluster_name_salt, polling_timeout, polling_frequency, only_on_failure, ): """ Retrieves logs for the cluster and saves them in logs.tar.gz in the current working directory. """ if only_on_failure: if os.path.exists('status'): with open('status') as fp: status = fp.read().strip() if status == 'success': LOGGER.info('Test run status is %s, not retrieving logs' % status) return else: LOGGER.info('Test run status is missing') # Retrieve logs because tests may have timed out # Step-1: determine the cluster name for the given test. cluster_name = get_cluster_name( get_test_name_from_spec_file(spec_test_file), cluster_name_salt) organization = cmd.get_one_organization_by_name(client=ctx.obj.client, organization_name=org_name) project = cmd.ensure_project(client=ctx.obj.client, project_name=project_name, organization_id=organization.id) get_logs(admin_client=ctx.obj.admin_client, project=project, cluster_name=cluster_name)
def __init__(self, *, client, test_locator_token, configuration, xunit_output, persist_clusters, workload_startup_time): self.cases = [] self.client = client self.config = configuration self.xunit_logger = SingleTestXUnitLogger( output_directory=xunit_output) self.persist_clusters = persist_clusters self.workload_startup_time = workload_startup_time for full_path in self.find_spec_tests(test_locator_token): # Step-1: load test specification. with open(full_path, 'r') as spec_file: test_spec = JSONObject.from_dict( yaml.load(spec_file, Loader=yaml.FullLoader)) # Step-2: generate test name. test_name = get_test_name_from_spec_file(full_path) # Step-3: generate unique cluster name. cluster_name = get_cluster_name(test_name, self.config.name_salt) self.cases.append( AtlasTestCase(client=self.client, test_name=test_name, cluster_name=cluster_name, specification=test_spec, configuration=self.config)) # Set up Atlas for tests. # Step-1: ensure validity of the organization. # Note: organizations can only be created by via the web UI. org_name = self.config.organization_name LOGGER.info("Verifying organization {!r}".format(org_name)) org = get_one_organization_by_name(client=self.client, organization_name=org_name) LOGGER.info("Successfully verified organization {!r}".format(org_name)) # Step-2: check that the project exists or else create it. pro_name = self.config.project_name LOGGER.info("Verifying project {!r}".format(pro_name)) project = ensure_project(client=self.client, project_name=pro_name, organization_id=org.id) LOGGER.info("Successfully verified project {!r}".format(pro_name)) # Step-3: create a user under the project. # Note: all test operations will be run as this user. uname = self.config.database_username LOGGER.info("Verifying user {!r}".format(uname)) ensure_admin_user(client=self.client, project_id=project.id, username=uname, password=self.config.database_password) LOGGER.info("Successfully verified user {!r}".format(uname)) # Step-4: populate project IP whitelist to allow access from anywhere. LOGGER.info("Enabling access from anywhere on project " "{!r}".format(pro_name)) ensure_connect_from_anywhere(client=self.client, project_id=project.id) LOGGER.info("Successfully enabled access from anywhere on project " "{!r}".format(pro_name)) # Step-5: log test plan. LOGGER.info(self.get_printable_test_plan())