Esempio n. 1
0
def _load_session_client(session=None,
                         endpoint_override=None,
                         username=None,
                         project_id=None,
                         project_name=None,
                         auth_url=None,
                         password=None,
                         auth_type=None,
                         insecure=None,
                         user_domain_id=None,
                         user_domain_name=None,
                         project_domain_id=None,
                         project_domain_name=None,
                         auth_token=None,
                         timeout=None,
                         service_type=None,
                         service_name=None,
                         interface=None,
                         region_name=None,
                         api_version=None,
                         **kwargs):
    if not session:
        session = _load_session(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,
                                **kwargs)

    if not endpoint_override:
        service_type = _load_service_type(session,
                                          service_type=service_type,
                                          service_name=service_name,
                                          interface=interface,
                                          region_name=region_name,
                                          **kwargs)

    return httpclient.SessionClient(
        service_type=service_type,
        service_name=service_name,
        interface=interface,
        region_name=region_name,
        session=session,
        endpoint_override=endpoint_override,
        api_version=api_version,
    )
Esempio n. 2
0
 def test_exception(self):
     fake_response = utils.FakeSessionResponse(
         {}, content="", status_code=504)
     fake_session = mock.MagicMock()
     fake_session.request.side_effect = [fake_response]
     client = http.SessionClient(
         api_version='/v1',
         session=fake_session, endpoint_override='http://cyborg')
     self.assertRaises(exc.GatewayTimeout,
                       client.json_request,
                       'GET', '/v1/accelerators')
Esempio n. 3
0
    def test_bypass_url(self):
        fake_response = utils.FakeSessionResponse(
            {}, content="", status_code=201)
        fake_session = mock.MagicMock()
        fake_session.request.side_effect = [fake_response]

        client = http.SessionClient(
            api_version='/v1',
            session=fake_session, endpoint_override='http://cyborg')

        client.json_request('GET', '/v1/accelerators')
        self.assertEqual(
            fake_session.request.call_args[1]['endpoint_override'],
            'http://cyborg'
        )
Esempio n. 4
0
    def test_server_exception_empty_body(self):
        error_body = _get_error_body()

        fake_session = utils.FakeSession({'Content-Type': 'application/json'},
                                         error_body,
                                         500)

        client = http.SessionClient(
            api_version='/v1',
            session=fake_session)

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

        self.assertEqual('Internal Server Error (HTTP 500)', str(error))
Esempio n. 5
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_session = utils.FakeSession({'Content-Type': 'application/json'},
                                         error_body,
                                         500)

        client = http.SessionClient(
            api_version='/v1',
            session=fake_session)

        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)})