Пример #1
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)
Пример #2
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)
Пример #3
0
 def skip_checks(cls):
     """Class level skip checks. Subclasses verify in here all
     conditions that might prevent the execution of the entire test class.
     Checks implemented here may not make use API calls, and should rely on
     configuration alone.
     In general skip checks that require an API call are discouraged.
     If one is really needed it may be implemented either in the
     resource_setup or at test level.
     """
     if 'admin' in cls.credentials and not credentials.is_admin_available():
         msg = "Missing Identity Admin API credentials in configuration."
         raise cls.skipException(msg)
     if 'alt' in cls.credentials and not credentials.is_alt_available():
         msg = "Missing a 2nd set of API credentials in configuration."
         raise cls.skipException(msg)
     if hasattr(cls, 'identity_version'):
         if cls.identity_version == 'v2':
             if not CONF.identity_feature_enabled.api_v2:
                 raise cls.skipException("Identity api v2 is not enabled")
         elif cls.identity_version == 'v3':
             if not CONF.identity_feature_enabled.api_v3:
                 raise cls.skipException("Identity api v3 is not enabled")
Пример #4
0
 def skip_checks(cls):
     """Class level skip checks. Subclasses verify in here all
     conditions that might prevent the execution of the entire test class.
     Checks implemented here may not make use API calls, and should rely on
     configuration alone.
     In general skip checks that require an API call are discouraged.
     If one is really needed it may be implemented either in the
     resource_setup or at test level.
     """
     if 'admin' in cls.credentials and not credentials.is_admin_available():
         msg = "Missing Identity Admin API credentials in configuration."
         raise cls.skipException(msg)
     if 'alt' in cls.credentials and not credentials.is_alt_available():
         msg = "Missing a 2nd set of API credentials in configuration."
         raise cls.skipException(msg)
     if hasattr(cls, 'identity_version'):
         if cls.identity_version == 'v2':
             if not CONF.identity_feature_enabled.api_v2:
                 raise cls.skipException("Identity api v2 is not enabled")
         elif cls.identity_version == 'v3':
             if not CONF.identity_feature_enabled.api_v3:
                 raise cls.skipException("Identity api v3 is not enabled")
Пример #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)
Пример #6
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)