def testVerifyOnePlatformFlagsTimeoutGAOk(self): parser = argparse.ArgumentParser() flags.AddTimeoutFlag(parser) args = parser.parse_args(['--timeout', '15m'], parser_extensions.Namespace(timeout=None)) flags.VerifyOnePlatformFlags(args, calliope_base.ReleaseTrack.GA, flags.Product.RUN)
def testVerifyOnePlatformFlagsTimeoutGA(self): parser = argparse.ArgumentParser() flags.AddTimeoutFlag(parser) args = parser.parse_args(['--timeout', '1h'], parser_extensions.Namespace(timeout=None)) with self.assertRaises(exceptions.ConfigurationError): flags.VerifyOnePlatformFlags(args, calliope_base.ReleaseTrack.GA, flags.Product.RUN)
def testGetNestedFields(self, param_arr, mask_path, expected_string): args = parser_extensions.Namespace(_specified_args={ 'nodes': '--nodes', 'description': '--description' }) self._MakeSpec(param_arr) mask_string = update.GetMaskString(args, self.spec, mask_path) self.assertEqual(expected_string, mask_string)
def testGetLabels(self, param_arr, mask_path, expected_string): args = parser_extensions.Namespace(_specified_args={ 'update-labels': '--update-labels', 'set-labels': '--update-labels' }) self._MakeSpec(param_arr) mask_string = update.GetMaskString(args, self.spec, mask_path) self.assertEqual(expected_string, mask_string)
def testGetNegativeBooleanArgs(self, param_arr, mask_path, expected_string): args = parser_extensions.Namespace( _specified_args={ 'enable-feature': '--no-enable-feature', }) self._MakeSpec(param_arr) mask_string = update.GetMaskString(args, self.spec, mask_path) self.assertEqual(expected_string, mask_string)
def SetUp(self): self.args = parser_extensions.Namespace() # Set up mock deepest_parser for args.CONCEPTS deepest_parser = mock.Mock() deepest_parser._calliope_command.ai.concept_handler.return_value = mock.Mock( ) self.args._SetParser(deepest_parser) # Set up actual parser self.parser = argparse.ArgumentParser() flags.AddPlatformArg(self.parser) self.args._parsers.append(self.parser) properties.VALUES.run.platform.Set(None)
def testGetArgGroup(self): arg1 = mock.MagicMock(arg_name='arg1', api_field='updateRequest.field1') arg2 = mock.MagicMock(arg_name='arg2', api_field='updateRequest.field2') arg3 = mock.MagicMock(arg_name='arg3', api_field='updateRequest.field3') group1 = mock.MagicMock(spec=yaml_command_schema.ArgumentGroup, arguments=[arg2, arg3]) self.spec.arguments.params = [arg1, group1] args = parser_extensions.Namespace(_specified_args={ 'arg1': '--arg1', 'arg2': '--arg2', 'arg3': '--arg3' }) mask_string = update.GetMaskString(args, self.spec, 'fieldMask') self.assertEqual('field1,field2,field3', mask_string)
def _get_completions(self, comp_words, cword_prefix, cword_prequote, first_colon_pos): active_parsers = self._patch_argument_parser() parsed_args = parser_extensions.Namespace() self.completing = True try: self._parser.parse_known_args(comp_words[1:], namespace=parsed_args) except BaseException: # pylint: disable=broad-except pass self.completing = False completions = self.collect_completions( active_parsers, parsed_args, cword_prefix, lambda *_: None) completions = self.filter_completions(completions) return self.quote_completions(completions, cword_prequote, first_colon_pos)
def SetUp(self): self.args = parser_extensions.Namespace( update_env_vars=None, set_env_vars=None, remove_env_vars=None, clear_env_vars=None, concurrency=None, add_cloudsql_instances=None, remove_cloudsql_instances=None, clear_cloudsql_instances=None, set_cloudsql_instances=None, cpu=None, clear_labels=None, update_labels=None, remove_labels=None, update_secrets=None, set_secrets=None, remove_secrets=None, clear_secrets=None, update_config_maps=None, set_config_maps=None, remove_config_maps=None, clear_config_maps=None, update_tags=None, set_tags=None, remove_tags=None, clear_tags=None, to_latest=None, to_revisions=None, ingress=None) self.service = service.Service.New(self.mock_serverless_client, self.namespace.namespacesId) self.service.name = 'myservice' self.metadata = self.service.metadata self.StartObjectPatch( name_generator, 'GenerateName', side_effect=lambda **kwargs: '{}-genr8d'.format(kwargs['prefix']))
def testVerifyOnePlatformFlagsEgressSettings(self): args = parser_extensions.Namespace(vpc_egress='private-ranges-only') flags.VerifyOnePlatformFlags(args, self.track, flags.Product.RUN)
def testVerifyOnePlatformFlagsNoTraffic(self): args = parser_extensions.Namespace(no_traffic=None) args.no_traffic = True flags.VerifyOnePlatformFlags(args, self.track, flags.Product.RUN)
def testVerifyOnePlatformFlagsEventsIsAlphaOnly(self): # The "gcloud events" subcommand is alpha only for --platform=managed args = parser_extensions.Namespace() flags.VerifyOnePlatformFlags(args, self.track, flags.Product.EVENTS)
def testVerifyOnePlatformFlagsMinInstance(self): args = parser_extensions.Namespace(min_instances=None) args.min_instances = 3 flags.VerifyOnePlatformFlags(args, self.track, flags.Product.RUN)
def testVerifyKubernetesFlagsEgressSettings(self): args = parser_extensions.Namespace(vpc_egress='private-ranges-only') with self.assertRaises(exceptions.ConfigurationError): flags.VerifyKubernetesFlags(args, self.track, flags.Product.RUN)
def testVerifyKubernetesFlagsCluster(self): args = parser_extensions.Namespace(cluster=None) with self.assertRaises(exceptions.ConfigurationError): args.cluster = 'cluster-1' flags.VerifyKubernetesFlags(args, self.track, flags.Product.RUN)
def testVerifyKubernetesFlagsAllowUnauthenticated(self): args = parser_extensions.Namespace(allow_unauthenticated=None) with self.assertRaises(exceptions.ConfigurationError): args.allow_unauthenticated = True flags.VerifyKubernetesFlags(args, self.track, flags.Product.RUN)
def SetUp(self): properties.VALUES.run.region.Set('serverless-config-region') self.args = parser_extensions.Namespace()
def testVerifyKubernetesFlagsRegion(self): args = parser_extensions.Namespace(region=None) with self.assertRaises(exceptions.ConfigurationError): args.region = 'us-central1' flags.VerifyKubernetesFlags(args, calliope_base.ReleaseTrack.GA, flags.Product.RUN)
def testVerifyKubernetesFlagsConnectivityAndIngress(self): args = parser_extensions.Namespace(connectivity=None, ingress=None) with self.assertRaises(exceptions.ConfigurationError): args.connectivity = 'internal' args.ingress = 'internal' flags.VerifyKubernetesFlags(args, self.track, flags.Product.RUN)
def testVerifyGKEFlagsRegion(self): args = parser_extensions.Namespace(region=None) with self.assertRaises(exceptions.ConfigurationError): args.region = 'us-central1' flags.VerifyGKEFlags(args, self.track, flags.Product.RUN)
def testVerifyKubernetesFlagsLocation(self): args = parser_extensions.Namespace(cluster_location=None) with self.assertRaises(exceptions.ConfigurationError): args.cluster_location = 'us-central1-a' flags.VerifyKubernetesFlags(args, self.track, flags.Product.RUN)
def testVerifyGKEFlagsClearSecrets(self): args = parser_extensions.Namespace(clear_secrets=None) args.clear_secrets = True flags.VerifyGKEFlags(args, self.track, flags.Product.RUN)
def testVerifyOnePlatformFlagsEventsIsAlphaOnly(self): # The "gcloud events" subcommand is alpha only for --platform=managed args = parser_extensions.Namespace() with self.assertRaises(exceptions.ConfigurationError): flags.VerifyOnePlatformFlags(args, self.track, flags.Product.EVENTS)
def testVerifyOnePlatformFlagsCpu(self): args = parser_extensions.Namespace(cpu=None) args.cpu = 2 flags.VerifyOnePlatformFlags(args, self.track, flags.Product.RUN)
def testVerifyOnePlatformFlagsTimeout(self): parser = argparse.ArgumentParser() flags.AddTimeoutFlag(parser) args = parser.parse_args(['--timeout', '1h'], parser_extensions.Namespace(timeout=None)) flags.VerifyOnePlatformFlags(args, self.track, flags.Product.RUN)
def testVerifyOnePlatformFlagsKubeconfig(self): args = parser_extensions.Namespace(kubeconfig=None) with self.assertRaises(exceptions.ConfigurationError): args.kubeconfig = '~/.kube/config' flags.VerifyOnePlatformFlags(args, self.track, flags.Product.RUN)
def SetUp(self): self.args = parser_extensions.Namespace()
def testVerifyOnePlatformFlagsContext(self): args = parser_extensions.Namespace(context=None) with self.assertRaises(exceptions.ConfigurationError): args.context = 'some-context' flags.VerifyOnePlatformFlags(args, self.track, flags.Product.RUN)
def _PopulateCloudTasksArgs(queue, cur_queue_state, ct_expected_args): """Builds dummy command line args to pass on to Cloud Tasks API. Most of Cloud Tasks functions use args passed in during CLI invocation. To reuse those functions without extensive rework on their implementation, we recreate the args in the format that those functions expect. Args: queue: third_party.appengine.api.queueinfo.QueueEntry, The QueueEntry instance generated from the parsed YAML file. cur_queue_state: apis.cloudtasks.<ver>.cloudtasks_<ver>_messages.Queue, The Queue instance fetched from the backend if it exists, None otherwise. ct_expected_args: A list of expected args that we need to initialize before forwarding to Cloud Tasks APIs. Returns: argparse.Namespace, A dummy args namespace built to pass on forwards to Cloud Tasks API. """ cloud_task_args = parser_extensions.Namespace() for task_flag in ct_expected_args: setattr(cloud_task_args, task_flag, None) used_default_value_for_min_backoff = False for old_arg, new_arg in constants.APP_TO_TASKS_ATTRIBUTES_MAPPING.items(): # e.g. old_arg, new_arg = 'retry_parameters.max_doublings', 'max_doublings' old_arg_list = old_arg.split('.') value = queue for old_arg_sub in old_arg_list: if not hasattr(value, old_arg_sub): value = None break value = getattr(value, old_arg_sub) # Max attempts is a special case because 0 is actually stored as 1. if value or (value is not None and new_arg in ('max_attempts',)): # Some values need to be converted to a format that CT APIs accept if old_arg in CONVERSION_FUNCTIONS: value = CONVERSION_FUNCTIONS[old_arg](value) if ( not cur_queue_state or new_arg in ('name', 'type', 'min_backoff', 'max_backoff') or _DoesAttributeNeedToBeUpdated(cur_queue_state, new_arg, value) ): # Attributes specified here are forwarded to CT APIs. We always forward # 'name' and 'type' attributes and we forward any other attributes if # they have changed from before or if this is a brand new queue. _SetSpecifiedArg(cloud_task_args, new_arg, value) else: # Set default values for some of the attributes if no value is present if queue.mode == constants.PULL_QUEUE: default_values = constants.PULL_QUEUES_APP_DEPLOY_DEFAULT_VALUES else: default_values = constants.PUSH_QUEUES_APP_DEPLOY_DEFAULT_VALUES if new_arg in default_values: if new_arg == 'min_backoff': used_default_value_for_min_backoff = True value = default_values[new_arg] if ( not cur_queue_state or new_arg in ('min_backoff', 'max_backoff') or _DoesAttributeNeedToBeUpdated(cur_queue_state, new_arg, value) ): _SetSpecifiedArg(cloud_task_args, new_arg, value) setattr(cloud_task_args, new_arg, value) _PostProcessMinMaxBackoff( cloud_task_args, used_default_value_for_min_backoff, cur_queue_state) _PostProcessRoutingOverride(cloud_task_args, cur_queue_state) return cloud_task_args
def testVerifyOnePlatformFlagsMinInstance(self): args = parser_extensions.Namespace(min_instances=None) with self.assertRaises(exceptions.ConfigurationError): args.min_instances = 3 flags.VerifyOnePlatformFlags(args, self.track, flags.Product.RUN)