def SetUp(self): self.name_generator = e2e_utils.GetResourceNameGenerator('sdk-e2e') project_name = next(self.name_generator) self.project_id = command_lib_util.IdFromName(project_name) self.project_ref = command_lib_util.ParseProject(self.project_id) create_op = projects_api.Create( self.project_ref, parent=projects_api.ParentNameToResourceId( CLOUD_SDK_TESTING_FOLDER_ID)) log.CreatedResource(self.project_ref, is_async=True) operations.WaitForOperation(create_op) log.debug('Enabling cloudapis.googleapis.com') services_enable_api.EnableService(self.project_ref.Name(), 'cloudapis.googleapis.com') self.Run('services enable cloudbilling') self.Run(('alpha billing accounts projects link {project} ' '--account-id={billing}').format(project=self.project_id, billing=self.BillingId())) self.Run('projects add-iam-policy-binding {project} ' '--member="group:[email protected]" ' '--role="roles/owner"'.format(project=self.project_id)) properties.VALUES.core.disable_prompts.Set(True) # This is set to false by sdk_test_base.SdkBase. properties.VALUES.core.should_prompt_to_enable_api.Set(True) # The api enablement check will prompt, and this will inject a yes into that self.StartPatch( 'googlecloudsdk.core.console.console_io.PromptContinue', return_value=True)
def Run(self, args): """Default Run method implementation.""" flags.CheckParentFlags(args, parent_required=False) project_id = args.id if not project_id and args.name: candidate = command_lib_util.IdFromName(args.name) if candidate and console_io.PromptContinue( 'No project id provided.', 'Use [{}] as project id'.format(candidate), throw_if_unattended=True): project_id = candidate if not project_id: raise exceptions.RequiredArgumentException( 'PROJECT_ID', 'an id must be provided for the new project') project_ref = command_lib_util.ParseProject(project_id) labels = labels_util.ParseCreateArgs( args, projects_util.GetMessages().Project.LabelsValue) try: create_op = projects_api.Create( project_ref, display_name=args.name, parent=projects_api.ParentNameToResourceId( flags.GetParentFromFlags(args)), labels=labels) except apitools_exceptions.HttpConflictError: msg = ( 'Project creation failed. The project ID you specified is ' 'already in use by another project. Please try an alternative ' 'ID.') core_exceptions.reraise(exceptions.HttpException(msg)) log.CreatedResource(project_ref, is_async=True) create_op = operations.WaitForOperation(create_op) # Enable cloudapis.googleapis.com if args.enable_cloud_apis: log.debug('Enabling cloudapis.googleapis.com') services_client = apis.GetClientInstance('servicemanagement', 'v1') enable_operation = services_enable_api.EnableServiceApiCall( project_ref.Name(), 'cloudapis.googleapis.com') enable_operation_ref = resources.REGISTRY.Parse( enable_operation.name, collection='servicemanagement.operations') services_util.WaitForOperation(enable_operation_ref, services_client) if args.set_as_default: project_property = properties.FromString('core/project') properties.PersistProperty(project_property, project_id) log.status.Print( 'Updated property [core/project] to [{0}].'.format(project_id)) return operations.ExtractOperationResponse( create_op, apis.GetMessagesModule('cloudresourcemanager', 'v1').Project)
def RunSubTest(self, name, id_expression): # pylint: disable=arguments-differ val = util.IdFromName(name) self.assertTrue(re.match(id_expression, val), msg="'{}' does not match '{}'".format(id_expression, val))