Ejemplo n.º 1
0
 def _get_admin_clients(self):
     """
     Returns a tuple with instances of the following admin clients (in this
     order):
         identity
         network
     """
     os = clients.Manager(self.default_admin_creds)
     if self.identity_version == 'v2':
         return os.identity_client, os.network_client
     else:
         return os.identity_v3_client, os.network_client
Ejemplo n.º 2
0
 def _wrap_creds_with_network(self, hash):
     creds_dict = self.hash_dict['creds'][hash]
     credential = cred_provider.get_credentials(
         identity_version=self.identity_version, **creds_dict)
     net_creds = cred_provider.TestResources(credential)
     net_clients = clients.Manager(credentials=credential)
     compute_network_client = net_clients.networks_client
     net_name = self.hash_dict['networks'].get(hash, None)
     try:
         network = fixed_network.get_network_from_name(
             net_name, compute_network_client)
     except exceptions.InvalidConfiguration:
         network = {}
     net_creds.set_resources(network=network)
     return net_creds
Ejemplo n.º 3
0
    def get_tenant_network(cls):
        """Get the network to be used in testing

        :returns: network dict including 'id' and 'name'
        """
        # Make sure isolated_creds exists and get a network client
        networks_client = cls.get_client_manager().networks_client
        cred_provider = cls._get_credentials_provider()
        # In case of nova network, isolated tenants are not able to list the
        # network configured in fixed_network_name, even if the can use it
        # for their servers, so using an admin network client to validate
        # the network name
        if (not CONF.service_available.neutron
                and credentials.is_admin_available()):
            admin_creds = cred_provider.get_admin_creds()
            networks_client = clients.Manager(admin_creds).networks_client
        return fixed_network.get_tenant_network(cred_provider, networks_client)
Ejemplo n.º 4
0
    def get_client_manager(cls,
                           credential_type=None,
                           roles=None,
                           force_new=None):
        """Returns an OpenStack client manager

        Returns an OpenStack client manager based on either credential_type
        or a list of roles. If neither is specified, it defaults to
        credential_type 'primary'
        :param credential_type: string - primary, alt or admin
        :param roles: list of roles

        :returns: the created client manager
        :raises skipException: if the requested credentials are not available
        """
        if all([roles, credential_type]):
            msg = "Cannot get credentials by type and roles at the same time"
            raise ValueError(msg)
        if not any([roles, credential_type]):
            credential_type = 'primary'
        cred_provider = cls._get_credentials_provider()
        if roles:
            for role in roles:
                if not cred_provider.is_role_available(role):
                    skip_msg = (
                        "%s skipped because the configured credential provider"
                        " is not able to provide credentials with the %s role "
                        "assigned." % (cls.__name__, role))
                    raise cls.skipException(skip_msg)
            params = dict(roles=roles)
            if force_new is not None:
                params.update(force_new=force_new)
            creds = cred_provider.get_creds_by_roles(**params)
        else:
            credentials_method = 'get_%s_creds' % credential_type
            if hasattr(cred_provider, credentials_method):
                creds = getattr(cred_provider, credentials_method)()
            else:
                raise exceptions.InvalidCredentials(
                    "Invalid credentials type %s" % credential_type)
        return clients.Manager(credentials=creds, service=cls._service)
Ejemplo n.º 5
0
    def execute(self, description):
        """
        Execute a http call on an api that are expected to
        result in client errors. First it uses invalid resources that are part
        of the url, and then invalid data for queries and http request bodies.

        :param description: A json file or dictionary with the following
        entries:
            name (required) name for the api
            http-method (required) one of HEAD,GET,PUT,POST,PATCH,DELETE
            url (required) the url to be appended to the catalog url with '%s'
                for each resource mentioned
            resources: (optional) A list of resource names such as "server",
                "flavor", etc. with an element for each '%s' in the url. This
                method will call self.get_resource for each element when
                constructing the positive test case template so negative
                subclasses are expected to return valid resource ids when
                appropriate.
            json-schema (optional) A valid json schema that will be used to
                create invalid data for the api calls. For "GET" and "HEAD",
                the data is used to generate query strings appended to the url,
                otherwise for the body of the http call.

        """
        LOG.info("Executing %s" % description["name"])
        LOG.debug(description)
        generator = importutils.import_class(CONF.negative.test_generator)()
        schema = description.get("json-schema", None)
        method = description["http-method"]
        url = description["url"]
        expected_result = None
        if "default_result_code" in description:
            expected_result = description["default_result_code"]

        resources = [
            self.get_resource(r) for r in description.get("resources", [])
        ]

        if hasattr(self, "resource"):
            # Note(mkoderer): The resources list already contains an invalid
            # entry (see get_resource).
            # We just send a valid json-schema with it
            valid_schema = None
            if schema:
                valid_schema = \
                    valid.ValidTestGenerator().generate_valid(schema)
            new_url, body = self._http_arguments(valid_schema, url, method)
        elif hasattr(self, "_negtest_name"):
            schema_under_test = \
                valid.ValidTestGenerator().generate_valid(schema)
            local_expected_result = \
                generator.generate_payload(self, schema_under_test)
            if local_expected_result is not None:
                expected_result = local_expected_result
            new_url, body = \
                self._http_arguments(schema_under_test, url, method)
        else:
            raise Exception("testscenarios are not active. Please make sure "
                            "that your test runner supports the load_tests "
                            "mechanism")

        if "admin_client" in description and description["admin_client"]:
            if not credentials.is_admin_available():
                msg = ("Missing Identity Admin API credentials in"
                       "configuration.")
                raise self.skipException(msg)
            creds = self.credentials_provider.get_admin_creds()
            os_adm = clients.Manager(credentials=creds)
            client = os_adm.negative_client
        else:
            client = self.client
        resp, resp_body = client.send_request(method,
                                              new_url,
                                              resources,
                                              body=body)
        self._check_negative_response(expected_result, resp.status, resp_body)