Ejemplo n.º 1
0
    def test_401_unauthorized_exception(self):
        error_body = _get_error_body()
        fake_resp = utils.FakeResponse({'content-type': 'text/plain'},
                                       six.StringIO(error_body),
                                       version=1,
                                       status=401)
        client = http.HTTPClient(
            'http://localhost/',
            api_version='/v1')

        client.get_connection = (lambda *a,
                                 **kw: utils.FakeConnection(fake_resp))

        self.assertRaises(exc.Unauthorized, client.json_request,
                          'GET', '/v1/accelerators')
Ejemplo n.º 2
0
    def test_server_exception_empty_body(self):
        error_body = _get_error_body()
        fake_resp = utils.FakeResponse({'content-type': 'application/json'},
                                       six.StringIO(error_body),
                                       version=1,
                                       status=500)
        client = http.HTTPClient(
            'http://localhost/',
            api_version='/v1')
        client.get_connection = (
            lambda *a, **kw: utils.FakeConnection(fake_resp))

        error = self.assertRaises(exc.InternalServerError,
                                  client.json_request,
                                  'GET', '/v1/accelerators')
        self.assertEqual('Internal Server Error (HTTP 500)', str(error))
Ejemplo n.º 3
0
    def test_server_exception_msg_and_traceback(self):
        error_msg = 'another test error'
        error_trace = ("\"Traceback (most recent call last):\\n\\n  "
                       "File \\\"/usr/local/lib/python2.7/...")
        error_body = _get_error_body(error_msg, error_trace)
        fake_resp = utils.FakeResponse({'content-type': 'application/json'},
                                       six.StringIO(error_body),
                                       version=1,
                                       status=500)
        client = http.HTTPClient(
            'http://localhost/',
            api_version='/v1')
        client.get_connection = (
            lambda *a, **kw: utils.FakeConnection(fake_resp))

        error = self.assertRaises(exc.InternalServerError,
                                  client.json_request,
                                  'GET', '/v1/accelerators')

        self.assertEqual(
            '%(error)s (HTTP 500)\n%(trace)s' % {'error': error_msg,
                                                 'trace': error_trace},
            "%(error)s\n%(details)s" % {'error': str(error),
                                        'details': str(error.details)})
Ejemplo n.º 4
0
    def __init__(self,
                 username=None,
                 api_key=None,
                 project_id=None,
                 project_name=None,
                 auth_url=None,
                 cyborg_url=None,
                 endpoint_type=None,
                 endpoint_override=None,
                 service_type=DEFAULT_SERVICE_TYPE,
                 region_name=None,
                 input_auth_token=None,
                 session=None,
                 password=None,
                 auth_type='password',
                 interface=None,
                 service_name=None,
                 insecure=False,
                 user_domain_id=None,
                 user_domain_name=None,
                 project_domain_id=None,
                 project_domain_name=None,
                 auth_token=None,
                 timeout=600,
                 api_version=None,
                 **kwargs):

        # We have to keep the api_key are for backwards compat, but let's
        # remove it from the rest of our code since it's not a keystone
        # concept
        if not password:
            password = api_key
        # Backwards compat for people passing in input_auth_token
        if input_auth_token:
            auth_token = input_auth_token
        # Backwards compat for people passing in endpoint_type
        if endpoint_type:
            interface = endpoint_type

        # osc sometimes give 'None' value
        if not interface:
            interface = 'public'

        if interface.endswith('URL'):
            interface = interface[:-3]

        # fix (yolanda): os-cloud-config is using endpoint_override
        # instead of cyborg_url
        if cyborg_url and not endpoint_override:
            endpoint_override = cyborg_url

        if endpoint_override and auth_token:
            self.http_client = httpclient.HTTPClient(endpoint_override,
                                                     token=auth_token,
                                                     api_version=api_version,
                                                     timeout=timeout,
                                                     insecure=insecure,
                                                     **kwargs)
        else:
            self.http_client = _load_session_client(
                session=session,
                endpoint_override=endpoint_override,
                username=username,
                project_id=project_id,
                project_name=project_name,
                auth_url=auth_url,
                password=password,
                auth_type=auth_type,
                insecure=insecure,
                user_domain_id=user_domain_id,
                user_domain_name=user_domain_name,
                project_domain_id=project_domain_id,
                project_domain_name=project_domain_name,
                auth_token=auth_token,
                timeout=timeout,
                service_type=service_type,
                service_name=service_name,
                interface=interface,
                region_name=region_name,
                api_version=api_version,
                **kwargs)

        self.accelerators = accelerators.AcceleratorManager(self.http_client)
        self.deployables = deployables.DeployableManager(self.http_client)

        profile = kwargs.pop("profile", None)
        if profiler and profile:
            # Initialize the root of the future trace: the created trace ID
            # will be used as the very first parent to which all related
            # traces will be bound to. The given HMAC key must correspond to
            # the one set in cyborg-api cyborg.conf, otherwise the latter
            # will fail to check the request signature and will skip
            # initialization of osprofiler on the server side.
            profiler.init(profile)
Ejemplo n.º 5
0
 def test_url_generation_without_prefix_slash_in_path(self):
     client = http.HTTPClient('http://localhost')
     url = client._make_connection_url('v1/accelerators')
     self.assertEqual('/v1/accelerators', url)
Ejemplo n.º 6
0
 def test_url_generation_trailing_slash_in_base(self):
     client = http.HTTPClient('http://localhost/')
     url = client._make_connection_url('/v1/accelerators')
     self.assertEqual('/v1/accelerators', url)