def setup(self): # FIXME(andreykurilin): move all checks to validate method. # do not use admin, if we have users... user = random.choice(self.context.get("users", [self.context["admin"]])) clients = osclients.Clients(user["endpoint"]) services = clients.services() for client_name, conf in six.iteritems(self.config): if "service_type" in conf and conf["service_type"] not in services: raise exceptions.ValidationError( _("There is no service with '%s' type in your environment." ) % conf["service_type"]) elif "service_name" in conf: if conf["service_name"] not in services.values(): raise exceptions.ValidationError( _("There is no '%s' service in your environment") % conf["service_name"]) service_types = [ key for key in services if services[key] == conf["service_name"] ] if len(service_types) > 1: # NOTE(andreykurilin): does it possible?? raise exceptions.ValidationError( _("There are several services with name '%s'. Try to " "specify service_type property instead.") % conf["service_name"]) self.context["config"]["api_versions"][client_name][ "service_type"] = service_types[0]
def validate_args(self, args): """Validate given arguments to be used for running verification. :param args: A dict of arguments with values """ # NOTE(andreykurilin): By default we do not use jsonschema here. # So it cannot be extended by inheritors => requires duplication. if "pattern" in args: if not isinstance(args["pattern"], six.string_types): raise exceptions.ValidationError( "'pattern' argument should be a string.") if "concurrency" in args: if (not isinstance(args["concurrency"], int) or args["concurrency"] < 0): raise exceptions.ValidationError( "'concurrency' argument should be a positive integer or " "zero.") if "load_list" in args: if not isinstance(args["load_list"], list): raise exceptions.ValidationError( "'load_list' argument should be a list of tests.") if "skip_list" in args: if not isinstance(args["skip_list"], dict): raise exceptions.ValidationError( "'skip_list' argument should be a dict of tests " "where keys are test names and values are reasons.") if "xfail_list" in args: if not isinstance(args["xfail_list"], dict): raise exceptions.ValidationError( "'xfail_list' argument should be a dict of tests " "where keys are test names and values are reasons.")
def setup(self): # FIXME(andreykurilin): move all checks to validate method. # use admin only when `service_name` is presented admin_clients = osclients.Clients( self.context.get("admin", {}).get("credential")) clients = osclients.Clients( random.choice(self.context["users"])["credential"]) services = clients.keystone().service_catalog.get_endpoints() services_from_admin = None for client_name, conf in six.iteritems(self.config): if "service_type" in conf and conf["service_type"] not in services: raise exceptions.ValidationError( _("There is no service with '%s' type in your environment." ) % conf["service_type"]) elif "service_name" in conf: if not self.context.get("admin", {}).get("credential"): raise exceptions.BenchmarkSetupFailure( _("Setting 'service_name' is allowed only for 'admin' " "user.")) if not services_from_admin: services_from_admin = dict([ (s.name, s.type) for s in admin_clients.keystone().services.list() ]) if conf["service_name"] not in services_from_admin: raise exceptions.ValidationError( _("There is no '%s' service in your environment") % conf["service_name"]) self.context["config"]["api_versions"][client_name][ "service_type"] = services_from_admin[conf["service_name"]]
def validate_version(cls, version): supported_versions = cls.get_supported_versions() if supported_versions: if str(version) not in supported_versions: raise exceptions.ValidationError( "'%(vers)s' is not supported. Should be one of " "'%(supported)s'" % {"vers": version, "supported": supported_versions}) else: raise exceptions.RallyException("Setting version is not supported") try: float(version) except ValueError: raise exceptions.ValidationError( "'%s' is invalid. Should be numeric value." % version)
def _validate_config_semantic(self, config): LOG.info("Check health of the environment '%s'." % self.env.uuid) failed = [] for p, res in self.env.check_health().items(): LOG.info("Platform %s (available: %s): %s" % (p, res["available"], res["message"])) if not res["available"]: failed.append(p) if logging.is_debug(): LOG.error(res["traceback"]) if failed: raise exceptions.ValidationError( "One or several platforms are not available: %s. Check logs " "for more details." % ", ".join(failed)) validation_ctx = self.env.get_validation_context() env_data = self.env.data env_data["platforms"] = dict( (p["platform_name"], p["platform_data"]) for p in env_data["platforms"].values()) ctx_obj = {"task": self.task, "config": validation_ctx, "env": env_data} with context.ContextManager(ctx_obj): for subtask in config.subtasks: for workload in subtask["workloads"]: self._validate_workload( workload, vcontext=ctx_obj, vtype="semantic")
def get_creds_from_env_vars(): required_env_vars = ["OS_AUTH_URL", "OS_USERNAME", "OS_PASSWORD"] missing_env_vars = [v for v in required_env_vars if v not in os.environ] if missing_env_vars: msg = ("The following environment variables are " "required but not set: %s" % " ".join(missing_env_vars)) raise exceptions.ValidationError(message=msg) creds = { "auth_url": os.environ["OS_AUTH_URL"], "admin": { "username": os.environ["OS_USERNAME"], "password": os.environ["OS_PASSWORD"], "tenant_name": get_project_name_from_env(), "user_domain_name": os.environ.get("OS_USER_DOMAIN_NAME", ""), "project_domain_name": os.environ.get("OS_PROJECT_DOMAIN_NAME", ""), }, "endpoint_type": get_endpoint_type_from_env(), "endpoint": os.environ.get("OS_ENDPOINT"), "region_name": os.environ.get("OS_REGION_NAME", ""), "https_cacert": os.environ.get("OS_CACERT", ""), "https_insecure": strutils.bool_from_string( os.environ.get("OS_INSECURE")) } return creds
def get_project_name_from_env(): tenant_name = os.environ.get("OS_PROJECT_NAME", os.environ.get("OS_TENANT_NAME")) if tenant_name is None: raise exceptions.ValidationError("Either the OS_PROJECT_NAME or " "OS_TENANT_NAME environment variable " "is required, but neither is set.") return tenant_name
def validate_args(self, args): """Validate given arguments.""" super(TempestManager, self).validate_args(args) if args.get("pattern"): pattern = args["pattern"].split("=", 1) if len(pattern) == 1: pass # it is just a regex elif pattern[0] == "set": if pattern[1] not in AVAILABLE_SETS: raise exceptions.ValidationError( "Test set '%s' not found in available " "Tempest test sets. Available sets are '%s'." % (pattern[1], "', '".join(AVAILABLE_SETS))) else: raise exceptions.ValidationError( "'pattern' argument should be a regexp or set name " "(format: 'tempest.api.identity.v3', 'set=smoke').")
def validate(cls, config): """Validates runner's part of task config.""" super(ConstantScenarioRunner, cls).validate(config) if config.get("concurrency", 1) > config.get("times", 1): raise exceptions.ValidationError( "Parameter 'concurrency' means a number of parallel executions" "of iterations. Parameter 'times' means total number of " "iteration executions. It is redundant (and restricted) to " "have number of parallel iterations bigger then total number " "of iterations.")
def setup(self): # FIXME(andreykurilin): move all checks to validate method. # use admin only when `service_name` is presented admin_clients = osclients.Clients( self.context.get("admin", {}).get("credential")) clients = osclients.Clients(random.choice( self.context["users"])["credential"]) services = clients.keystone.service_catalog.get_endpoints() services_from_admin = None for client_name, conf in self.config.items(): if "service_type" in conf and conf["service_type"] not in services: raise exceptions.ValidationError( "There is no service with '%s' type in your environment." % conf["service_type"]) elif "service_name" in conf: if not self.context.get("admin", {}).get("credential"): raise exceptions.ContextSetupFailure( ctx_name=self.get_name(), msg="Setting 'service_name' is admin only operation.") if not services_from_admin: services_from_admin = dict( [(s.name, s.type) for s in admin_clients.keystone().services.list()]) if conf["service_name"] not in services_from_admin: raise exceptions.ValidationError( "There is no '%s' service in your environment" % conf["service_name"]) # TODO(boris-42): Use separate key ["openstack"]["versions"] self.context["config"]["api_versions@openstack"][client_name][ "service_type"] = services_from_admin[conf["service_name"]] admin_cred = self.context.get("admin", {}).get("credential") if admin_cred: admin_cred["api_info"].update( self.context["config"]["api_versions@openstack"] ) for user in self.context["users"]: user["credential"]["api_info"].update( self.context["config"]["api_versions@openstack"] )
def __init__(self, deployment): self.credential = deployment.get_credentials_for("openstack")["admin"] if not self.credential: raise exceptions.ValidationError( "Failed to configure 'tempest' for '%s' environment since " "admin credentials for OpenStack platform is missed there." % deployment["name"] ) self.clients = self.credential.clients() self.available_services = self.clients.services().values() self.conf = configparser.ConfigParser()
def validate(cls, config): super(OpenStackAPIVersions, cls).validate(config) for client in config: client_cls = osclients.OSClient.get(client) if ("service_type" in config[client] and "service_name" in config[client]): raise exceptions.ValidationError(_LE( "Setting both 'service_type' and 'service_name' properties" " is restricted.")) try: if ("service_type" in config[client] or "service_name" in config[client]): client_cls.is_service_type_configurable() if "version" in config[client]: client_cls.validate_version(config[client]["version"]) except exceptions.RallyException as e: raise exceptions.ValidationError( _LE("Invalid settings for '%(client)s': %(error)s") % { "client": client, "error": e.format_message()})
def __init__(self, env): openstack_platform = env.data["platforms"]["openstack"] self.credential = credential.OpenStackCredential( permission=consts.EndpointPermission.ADMIN, **openstack_platform["platform_data"]["admin"]) if not self.credential: raise exceptions.ValidationError( f"Failed to configure 'tempest' for '{env} since " "admin credentials for OpenStack platform is missed there." ) self.clients = self.credential.clients() self.available_services = self.clients.services().values() self.conf = configparser.ConfigParser(allow_no_value=True)
def get_creds_from_env_vars(): required_env_vars = ["OS_AUTH_URL", "OS_USERNAME", "OS_PASSWORD"] missing_env_vars = [v for v in required_env_vars if v not in os.environ] if missing_env_vars: msg = ("The following environment variables are " "required but not set: %s" % " ".join(missing_env_vars)) raise exceptions.ValidationError(message=msg) creds = { "auth_url": os.environ["OS_AUTH_URL"], "admin": { "username": os.environ["OS_USERNAME"], "password": os.environ["OS_PASSWORD"], "tenant_name": get_project_name_from_env() }, "endpoint_type": get_endpoint_type_from_env(), "endpoint": os.environ.get("OS_ENDPOINT"), "region_name": os.environ.get("OS_REGION_NAME", ""), "https_cacert": os.environ.get("OS_CACERT", ""), "https_insecure": strutils.bool_from_string(os.environ.get("OS_INSECURE")), "profiler_hmac_key": os.environ.get("OSPROFILER_HMAC_KEY"), "profiler_conn_str": os.environ.get("OSPROFILER_CONN_STR") } user_domain_name = os.environ.get("OS_USER_DOMAIN_NAME") project_domain_name = os.environ.get("OS_PROJECT_DOMAIN_NAME") identity_api_version = os.environ.get( "OS_IDENTITY_API_VERSION", os.environ.get("IDENTITY_API_VERSION")) if (identity_api_version == "3" or (identity_api_version is None and (user_domain_name or project_domain_name))): # it is Keystone v3 and it has another config scheme creds["admin"]["project_name"] = creds["admin"].pop("tenant_name") creds["admin"]["user_domain_name"] = user_domain_name or "Default" project_domain_name = project_domain_name or "Default" creds["admin"]["project_domain_name"] = project_domain_name return creds
def validate(self): super(FuelEngine, self).validate() if "compute" not in self.config["nodes"]: if "cinder+compute" not in self.config["nodes"]: raise exceptions.ValidationError( _("At least one compute is required."))
def validate(self): super(FuelEngine, self).validate() if 'compute' not in self.config['nodes']: if 'cinder+compute' not in self.config['nodes']: raise exceptions.ValidationError( _('At least one compute is required.'))