Ejemplo n.º 1
0
    def test_endpoint_type(self):
        resources = copy.deepcopy(KS_TOKEN_RESULT)
        endpoints = resources['access']['serviceCatalog'][0]['endpoints'][0]
        endpoints['internalURL'] = 'internal'
        endpoints['adminURL'] = 'admin'
        endpoints['publicURL'] = 'public'

        # Test default behavior is to choose public.
        self.client = client.HTTPClient(username=USERNAME,
                                        tenant_name=TENANT_NAME,
                                        password=PASSWORD,
                                        auth_url=AUTH_URL,
                                        region_name=REGION)

        self.client._extract_service_catalog(resources)
        self.assertEqual(self.client.endpoint_url, 'public')

        # Test admin url
        self.client = client.HTTPClient(username=USERNAME,
                                        tenant_name=TENANT_NAME,
                                        password=PASSWORD,
                                        auth_url=AUTH_URL,
                                        region_name=REGION,
                                        endpoint_type='adminURL')

        self.client._extract_service_catalog(resources)
        self.assertEqual(self.client.endpoint_url, 'admin')

        # Test public url
        self.client = client.HTTPClient(username=USERNAME,
                                        tenant_name=TENANT_NAME,
                                        password=PASSWORD,
                                        auth_url=AUTH_URL,
                                        region_name=REGION,
                                        endpoint_type='publicURL')

        self.client._extract_service_catalog(resources)
        self.assertEqual(self.client.endpoint_url, 'public')

        # Test internal url
        self.client = client.HTTPClient(username=USERNAME,
                                        tenant_name=TENANT_NAME,
                                        password=PASSWORD,
                                        auth_url=AUTH_URL,
                                        region_name=REGION,
                                        endpoint_type='internalURL')

        self.client._extract_service_catalog(resources)
        self.assertEqual(self.client.endpoint_url, 'internal')

        # Test url that isn't found in the service catalog
        self.client = client.HTTPClient(username=USERNAME,
                                        tenant_name=TENANT_NAME,
                                        password=PASSWORD,
                                        auth_url=AUTH_URL,
                                        region_name=REGION,
                                        endpoint_type='privateURL')

        self.assertRaises(exceptions.EndpointTypeNotFound,
                          self.client._extract_service_catalog, resources)
Ejemplo n.º 2
0
 def setUp(self):
     """Prepare the test environment."""
     super(CLITestAuthKeystoneWithId, self).setUp()
     self.client = client.HTTPClient(username=USERNAME,
                                     tenant_id=TENANT_ID,
                                     password=PASSWORD,
                                     auth_url=AUTH_URL,
                                     region_name=REGION)
Ejemplo n.º 3
0
 def __init__(self, **kwargs):
     """Initialize a new client for the Neutron v2.0 API."""
     super(Client, self).__init__()
     self.httpclient = client.HTTPClient(**kwargs)
     self.version = '2.0'
     self.format = 'json'
     self.action_prefix = "/v%s" % (self.version)
     self.retries = 0
     self.retry_interval = 1
Ejemplo n.º 4
0
 def setUp(self):
     """Prepare the test environment."""
     super(CLITestAuthKeystone, self).setUp()
     self.mox = mox.Mox()
     self.client = client.HTTPClient(username=USERNAME,
                                     tenant_name=TENANT_NAME,
                                     password=PASSWORD,
                                     auth_url=AUTH_URL,
                                     region_name=REGION)
     self.addCleanup(self.mox.VerifyAll)
     self.addCleanup(self.mox.UnsetStubs)
Ejemplo n.º 5
0
    def setUp(self):
        """Prepare the test environment."""
        super(CLITestAuthNoAuth, self).setUp()

        self.requests = self.useFixture(mock_fixture.Fixture())

        self.client = client.HTTPClient(username=USERNAME,
                                        tenant_name=TENANT_NAME,
                                        password=PASSWORD,
                                        endpoint_url=ENDPOINT_URL,
                                        auth_strategy=NOAUTH,
                                        region_name=REGION)
Ejemplo n.º 6
0
 def setUp(self):
     """Prepare the test environment."""
     super(CLITestAuthNoAuth, self).setUp()
     self.mox = mox.Mox()
     self.client = client.HTTPClient(username=USERNAME,
                                     tenant_name=TENANT_NAME,
                                     password=PASSWORD,
                                     endpoint_url=ENDPOINT_URL,
                                     auth_strategy=NOAUTH,
                                     region_name=REGION)
     self.addCleanup(self.mox.VerifyAll)
     self.addCleanup(self.mox.UnsetStubs)
Ejemplo n.º 7
0
def setup(keystone_url=keystone_url_10_2,
          admin="admin",
          password="******",
          project="admin"):
    loader = loading.get_plugin_loader('password')
    auth = loader.load_from_options(auth_url=keystone_url,
                                    username=admin,
                                    password=password,
                                    project_name=project)
    sess = session.Session(auth=auth, verify=False)
    nova = nvclient.Client(version="2.1", session=sess)
    neutron = nuclient.HTTPClient(session=sess)
    return nova
 def initialize(self):
     if not self._url:
         httpclient = client.HTTPClient(username=self._username,
                                        tenant_name=self._tenant_name,
                                        tenant_id=self._tenant_id,
                                        password=self._password,
                                        region_name=self._region_name,
                                        auth_url=self._auth_url,
                                        endpoint_type=self._endpoint_type,
                                        insecure=self._insecure)
         httpclient.authenticate()
         # Populate other password flow attributes
         self._token = httpclient.auth_token
         self._url = httpclient.endpoint_url
Ejemplo n.º 9
0
def _get_auth_token():
    try:
        httpclient = client.HTTPClient(
            username=CONF.neutron_admin_username,
            tenant_name=CONF.neutron_admin_tenant_name,
            password=CONF.neutron_admin_password,
            auth_url=CONF.neutron_admin_auth_url,
            timeout=CONF.neutron_url_timeout,
            auth_strategy=CONF.neutron_auth_strategy)
        httpclient.authenticate()
    except Exception:
        with excutils.save_and_reraise_exception():
            LOG.exception(_("_get_auth_token() failed"))
    return httpclient.auth_token
Ejemplo n.º 10
0
 def test_reused_token_get_auth_info(self):
     """Test that Client.get_auth_info() works even if client was
        instantiated with predefined token.
     """
     client_ = client.HTTPClient(username=USERNAME,
                                 tenant_name=TENANT_NAME,
                                 token=TOKEN,
                                 password=PASSWORD,
                                 auth_url=AUTH_URL,
                                 region_name=REGION)
     expected = {'auth_token': TOKEN,
                 'auth_tenant_id': None,
                 'auth_user_id': None,
                 'endpoint_url': self.client.endpoint_url}
     self.assertEqual(client_.get_auth_info(), expected)
Ejemplo n.º 11
0
    def test_get_endpoint_url_other(self):
        self.client = client.HTTPClient(
            username=USERNAME, tenant_name=TENANT_NAME, password=PASSWORD,
            auth_url=AUTH_URL, region_name=REGION, endpoint_type='otherURL')

        token_id = uuid.uuid4().hex
        self.client.auth_token = token_id

        self.requests.get(AUTH_URL + '/tokens/%s/endpoints' % token_id,
                          json=ENDPOINTS_RESULT)

        self.assertRaises(exceptions.EndpointTypeNotFound,
                          self.client.do_request,
                          '/resource',
                          'GET')
Ejemplo n.º 12
0
def _get_auth_token(logger):
    httpclient = q_client.HTTPClient(
        username=CONF.neutron_admin_username,
        tenant_name=CONF.neutron_admin_tenant_name,
        password=CONF.neutron_admin_password,
        auth_url=CONF.neutron_admin_auth_url,
        timeout=CONF.neutron_url_timeout,
        auth_strategy=CONF.neutron_auth_strategy)
    try:
        httpclient.authenticate()
    except (q_exc.Unauthorized, q_exc.Forbidden, q_exc.EndpointNotFound) as e:
        logger.error("authentication failure: %s", e)
        return None
    # logger.debug("_get_auth_token: token=%s", httpclient.auth_token)
    return httpclient.auth_token
Ejemplo n.º 13
0
def _get_auth_token():
    try:
        httpclient = client.HTTPClient(
            username=CONF.neutron_admin_username,
            tenant_name=CONF.neutron_admin_tenant_name,
            region_name=CONF.neutron_region_name,
            password=CONF.neutron_admin_password,
            auth_url=CONF.neutron_admin_auth_url,
            timeout=CONF.neutron_url_timeout,
            auth_strategy=CONF.neutron_auth_strategy,
            insecure=CONF.neutron_api_insecure)
        httpclient.authenticate()
        return httpclient.auth_token
    except exceptions.NeutronClientException as e:
        with excutils.save_and_reraise_exception():
            LOG.error(_('Neutron client authentication failed: %s'), e)
Ejemplo n.º 14
0
    def test_use_given_endpoint_url(self):
        self.client = client.HTTPClient(
            username=USERNAME, tenant_name=TENANT_NAME, password=PASSWORD,
            auth_url=AUTH_URL, region_name=REGION,
            endpoint_url=ENDPOINT_OVERRIDE)
        self.assertEqual(ENDPOINT_OVERRIDE, self.client.endpoint_url)

        token_id = uuid.uuid4().hex
        self.client.auth_token = token_id

        self.requests.get(ENDPOINT_OVERRIDE + '/resource')

        self.client.do_request('/resource', 'GET')

        self.assertEqual(ENDPOINT_OVERRIDE, self.client.endpoint_url)
        self.assertEqual(token_id,
                         self.requests.last_request.headers['X-Auth-Token'])
Ejemplo n.º 15
0
    def test_get_endpoint_url_other(self):
        self.client = client.HTTPClient(
            username=USERNAME, tenant_name=TENANT_NAME, password=PASSWORD,
            auth_url=AUTH_URL, region_name=REGION, endpoint_type='otherURL')
        self.mox.StubOutWithMock(self.client, "request")

        self.client.auth_token = TOKEN
        res200 = get_response(200)

        self.client.request(
            mox.StrContains(AUTH_URL + '/tokens/%s/endpoints' % TOKEN), 'GET',
            headers=mox.IsA(dict)
        ).AndReturn((res200, json.dumps(ENDPOINTS_RESULT)))
        self.mox.ReplayAll()
        self.assertRaises(exceptions.EndpointTypeNotFound,
                          self.client.do_request,
                          '/resource',
                          'GET')
Ejemplo n.º 16
0
    def test_use_given_endpoint_url(self):
        self.client = client.HTTPClient(
            username=USERNAME, tenant_name=TENANT_NAME, password=PASSWORD,
            auth_url=AUTH_URL, region_name=REGION,
            endpoint_url=ENDPOINT_OVERRIDE)
        self.assertEqual(self.client.endpoint_url, ENDPOINT_OVERRIDE)

        self.mox.StubOutWithMock(self.client, "request")

        self.client.auth_token = TOKEN
        res200 = get_response(200)

        self.client.request(
            mox.StrContains(ENDPOINT_OVERRIDE + '/resource'), 'GET',
            headers=mox.ContainsKeyValue('X-Auth-Token', TOKEN)
        ).AndReturn((res200, ''))
        self.mox.ReplayAll()
        self.client.do_request('/resource', 'GET')
        self.assertEqual(self.client.endpoint_url, ENDPOINT_OVERRIDE)
Ejemplo n.º 17
0
 def initialize(self):
     return client.HTTPClient(token=AUTH_TOKEN, endpoint_url=END_URL)
Ejemplo n.º 18
0
 def initialize(self):
     self.req_id = "req-%s" % uuidutils.generate_uuid()
     return client.HTTPClient(token=AUTH_TOKEN,
                              endpoint_url=END_URL,
                              global_request_id=self.req_id)