Ejemplo n.º 1
0
 def deserialize(self, resp, object_str):
     if 'application/json' in resp['content-type']:
         return json.loads(object_str)
     elif 'text/dns' in resp['content-type']:
         return models.ZoneFile.from_text(object_str.decode("utf-8"))
     else:
         raise lib_exc.InvalidContentType()
Ejemplo n.º 2
0
 def register_image(self, image_id, testcase):
     try:
         return self.sahara_client.images.get(image_id)
     except saharaclient_base.APIException:
         print("Image not registered in sahara. Registering and run tests")
         if testcase.get('image_username') is not None:
             self.sahara_client.images.update_image(
                 image_id, testcase.get('image_username'),
                 "Registered by scenario tests")
             self.sahara_client.images.update_tags(
                 image_id, [testcase["plugin_name"],
                            testcase["plugin_version"]])
         else:
             raise exc.InvalidContentType(
                 "Registering of image failed. Please, specify "
                 "'image_username'. For details see README in scenario "
                 "tests.")
     return self.sahara_client.images.get(image_id)
Ejemplo n.º 3
0
 def test_list_share_servers_with_host_filter(self):
     # Get list of share servers and remember 'host' name
     servers = self.shares_v2_client.list_share_servers()
     # Remember name of server that was used by this test suite
     # to be sure it will be still existing.
     for server in servers:
         if server["share_network_name"] in self.sn_name_and_id:
             if not server["host"]:
                 msg = ("Server '%s' has wrong value for host - "
                        "'%s'.") % (server["id"], server["host"])
                 raise lib_exc.InvalidContentType(message=msg)
             host = server["host"]
             break
     else:
         msg = ("Appropriate server was not found. Its share_network_data"
                ": '%s'. List of servers: '%s'.") % (self.sn_name_and_id,
                                                     six.text_type(servers))
         raise lib_exc.NotFound(message=msg)
     search_opts = {"host": host}
     servers = self.shares_v2_client.list_share_servers(search_opts)
     self.assertGreater(len(servers), 0)
     for server in servers:
         self.assertEqual(server["host"], host)
Ejemplo n.º 4
0
 def test_list_share_servers_with_status_filter(self):
     # Get list of share servers
     servers = self.shares_client.list_share_servers()
     # Remember status of server that was used by this test suite
     # to be sure it will be still existing.
     status = ""
     for server in servers:
         if server["share_network_name"] in self.sn_name_and_id:
             if not server["status"]:
                 msg = ("Server '%s' has wrong value for status - "
                        "'%s'.") % (server["id"], server["host"])
                 raise lib_exc.InvalidContentType(message=msg)
             status = server["status"]
             break
     if not status:
         msg = ("Appropriate server was not found. Its share_network_data"
                ": '%s'. List of servers: '%s'.") % (self.sn_name_and_id,
                                                     str(servers))
         raise lib_exc.NotFound(message=msg)
     search_opts = {"status": status}
     servers = self.shares_client.list_share_servers(search_opts)
     self.assertTrue(len(servers) > 0)
     for server in servers:
         self.assertEqual(server["status"], status)
Ejemplo n.º 5
0
    def _error_checker(self, method, url, headers, body, resp, resp_body):

        # NOTE(mtreinish): Check for httplib response from glance_http. The
        # object can't be used here because importing httplib breaks httplib2.
        # If another object from a class not imported were passed here as
        # resp this could possibly fail
        if str(type(resp)) == "<type 'instance'>":
            ctype = resp.getheader('content-type')
        else:
            try:
                ctype = resp['content-type']
            # NOTE(mtreinish): Keystone delete user responses doesn't have a
            # content-type header. (They don't have a body) So just pretend it
            # is set.
            except KeyError:
                ctype = 'application/json'

        # It is not an error response
        if resp.status < 400:
            return

        JSON_ENC = ['application/json', 'application/json; charset=utf-8']
        # NOTE(mtreinish): This is for compatibility with Glance and swift
        # APIs. These are the return content types that Glance api v1
        # (and occasionally swift) are using.
        TXT_ENC = [
            'text/plain', 'text/html', 'text/html; charset=utf-8',
            'text/plain; charset=utf-8'
        ]

        if ctype.lower() in JSON_ENC:
            parse_resp = True
        elif ctype.lower() in TXT_ENC:
            parse_resp = False
        else:
            raise exceptions.UnexpectedContentType(str(resp.status), resp=resp)

        if resp.status == 401:
            if parse_resp:
                resp_body = self._parse_resp(resp_body)
            raise exceptions.Unauthorized(resp_body, resp=resp)

        if resp.status == 403:
            if parse_resp:
                resp_body = self._parse_resp(resp_body)
            raise exceptions.Forbidden(resp_body, resp=resp)

        if resp.status == 404:
            if parse_resp:
                resp_body = self._parse_resp(resp_body)
            raise exceptions.NotFound(resp_body, resp=resp)

        if resp.status == 400:
            if parse_resp:
                resp_body = self._parse_resp(resp_body)
            raise exceptions.BadRequest(resp_body, resp=resp)

        if resp.status == 410:
            if parse_resp:
                resp_body = self._parse_resp(resp_body)
            raise exceptions.Gone(resp_body, resp=resp)

        if resp.status == 409:
            if parse_resp:
                resp_body = self._parse_resp(resp_body)
            raise exceptions.Conflict(resp_body, resp=resp)

        if resp.status == 413:
            if parse_resp:
                resp_body = self._parse_resp(resp_body)
            if self.is_absolute_limit(resp, resp_body):
                raise exceptions.OverLimit(resp_body, resp=resp)
            else:
                raise exceptions.RateLimitExceeded(resp_body, resp=resp)

        if resp.status == 415:
            if parse_resp:
                resp_body = self._parse_resp(resp_body)
            raise exceptions.InvalidContentType(resp_body, resp=resp)

        if resp.status == 422:
            if parse_resp:
                resp_body = self._parse_resp(resp_body)
            raise exceptions.UnprocessableEntity(resp_body, resp=resp)

        if resp.status in (500, 501):
            message = resp_body
            if parse_resp:
                try:
                    resp_body = self._parse_resp(resp_body)
                except ValueError:
                    # If response body is a non-json string message.
                    # Use resp_body as is and raise InvalidResponseBody
                    # exception.
                    raise exceptions.InvalidHTTPResponseBody(message)
                else:
                    if isinstance(resp_body, dict):
                        # I'm seeing both computeFault
                        # and cloudServersFault come back.
                        # Will file a bug to fix, but leave as is for now.
                        if 'cloudServersFault' in resp_body:
                            message = resp_body['cloudServersFault']['message']
                        elif 'computeFault' in resp_body:
                            message = resp_body['computeFault']['message']
                        elif 'error' in resp_body:
                            message = resp_body['error']['message']
                        elif 'message' in resp_body:
                            message = resp_body['message']
                    else:
                        message = resp_body

            if resp.status == 501:
                raise exceptions.NotImplemented(resp_body,
                                                resp=resp,
                                                message=message)
            else:
                raise exceptions.ServerFault(resp_body,
                                             resp=resp,
                                             message=message)

        if resp.status >= 400:
            raise exceptions.UnexpectedResponseCode(str(resp.status),
                                                    resp=resp)