def create_user(ctx, db_username, db_password, project_name): """Create an Atlas User with admin privileges. Modifies user permissions, if the user already exists.""" project = ctx.obj.groups.byName[project_name].get().data user = cmd.ensure_admin_user( client=ctx.obj, project_id=project.id, username=db_username, password=db_password) pprint(user)
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())