def _get_admin_clients(self, endpoint_type): """Returns a tuple with instances of the following admin clients (in this order): identity network """ os = clients.ServiceClients(self.default_admin_creds, self.identity_uri) params = {'endpoint_type': endpoint_type} if self.identity_version == 'v2': return (os.identity_v2.IdentityClient(**params), os.identity_v2.TenantsClient(**params), os.identity_v2.UsersClient(**params), os.identity_v2.RolesClient(**params), None, os.network.NetworksClient(), os.network.RoutersClient(), os.network.SubnetsClient(), os.network.PortsClient(), os.network.SecurityGroupsClient()) else: # We use a dedicated client manager for identity client in case we # need a different token scope for them. scope = 'domain' if self.identity_admin_domain_scope else 'project' identity_os = clients.ServiceClients(self.default_admin_creds, self.identity_uri, scope=scope) return (identity_os.identity_v3.IdentityClient(**params), identity_os.identity_v3.ProjectsClient(**params), identity_os.identity_v3.UsersClient(**params), identity_os.identity_v3.RolesClient(**params), identity_os.identity_v3.DomainsClient(**params), os.network.NetworksClient(), os.network.RoutersClient(), os.network.SubnetsClient(), os.network.PortsClient(), os.network.SecurityGroupsClient())
def test___init___creds_uri_none(self): creds = fake_credentials.FakeKeystoneV2Credentials() msg = ("Invalid Credentials\nDetails: ServiceClients requires a " "non-empty") with testtools.ExpectedException(exceptions.InvalidCredentials, value_re=msg): clients.ServiceClients(creds, None)
def test___init___plugin_service_clients_cannot_load(self): creds = fake_credentials.FakeKeystoneV3Credentials() uri = 'fake_uri' fake_service_clients = { 'service1': [{ 'name': 'client1', 'service_version': 'client1.v1', 'module_path': 'I cannot load this', 'client_names': ['SomeClient1'] }], 'service2': [{ 'name': 'client2', 'service_version': 'client2.v1', 'module_path': 'This neither', 'client_names': ['SomeClient1'] }] } msg = "(?=.*{0})(?=.*{1})".format(*[ x[1][0]['module_path'] for x in six.iteritems(fake_service_clients) ]) self.useFixture( fixtures.MockPatchObject(clients.ClientsRegistry(), 'get_service_clients', return_value=fake_service_clients)) with testtools.ExpectedException(testtools.MultipleExceptions, value_re=msg): clients.ServiceClients(creds, identity_uri=uri)
def setUp(self): super(TestValidationResources, self).setUp() self.useFixture(registry_fixture.RegistryFixture()) self.mock_sg_compute = self.useFixture( fixtures.MockPatch(SG_CLIENT % ('compute', 'create_security_group'), autospec=True, return_value=FAKE_SECURITY_GROUP)) self.mock_sg_network = self.useFixture( fixtures.MockPatch(SG_CLIENT % ('network', 'create_security_group'), autospec=True, return_value=FAKE_SECURITY_GROUP)) self.mock_sgr_compute = self.useFixture( fixtures.MockPatch(SGR_CLIENT % 'compute', autospec=True)) self.mock_sgr_network = self.useFixture( fixtures.MockPatch(SGR_CLIENT % 'network', autospec=True)) self.mock_kp = self.useFixture( fixtures.MockPatch(KP_CLIENT % 'create_keypair', autospec=True, return_value=FAKE_KEYPAIR)) self.mock_fip_compute = self.useFixture( fixtures.MockPatch(FIP_CLIENT % ('compute', 'create_floating_ip'), autospec=True, return_value=FAKE_FIP_NOVA_NET)) self.mock_fip_network = self.useFixture( fixtures.MockPatch(FIP_CLIENT % ('network', 'create_floatingip'), autospec=True, return_value=FAKE_FIP_NEUTRON)) self.os = clients.ServiceClients( fake_credentials.FakeKeystoneV3Credentials(), 'fake_uri')
def setUp(self): super(TestClearValidationResourcesFixture, self).setUp() self.useFixture(registry_fixture.RegistryFixture()) self.mock_sg_compute = self.useFixture( fixtures.MockPatch(SG_CLIENT % ('compute', 'delete_security_group'), autospec=True)) self.mock_sg_network = self.useFixture( fixtures.MockPatch(SG_CLIENT % ('network', 'delete_security_group'), autospec=True)) self.mock_sg_wait_compute = self.useFixture( fixtures.MockPatch(SG_CLIENT % ('compute', 'wait_for_resource_deletion'), autospec=True)) self.mock_sg_wait_network = self.useFixture( fixtures.MockPatch(SG_CLIENT % ('network', 'wait_for_resource_deletion'), autospec=True)) self.mock_kp = self.useFixture( fixtures.MockPatch(KP_CLIENT % 'delete_keypair', autospec=True)) self.mock_fip_compute = self.useFixture( fixtures.MockPatch(FIP_CLIENT % ('compute', 'delete_floating_ip'), autospec=True)) self.mock_fip_network = self.useFixture( fixtures.MockPatch(FIP_CLIENT % ('network', 'delete_floatingip'), autospec=True)) self.os = clients.ServiceClients( fake_credentials.FakeKeystoneV3Credentials(), 'fake_uri')
def test___init___creds_v3_uri(self): # Verify that no API request is made, since no mock # is required to run the test successfully creds = fake_credentials.FakeKeystoneV3Credentials() uri = 'fake_uri' _manager = clients.ServiceClients(creds, identity_uri=uri) self.assertIsInstance(_manager.auth_provider, auth.KeystoneV3AuthProvider)
def test___init___creds_uri_params_unknown_services(self): creds = fake_credentials.FakeKeystoneV2Credentials() fake_params = {'fake_param1': 'fake_value1'} params = { 'unknown_service1': fake_params, 'unknown_service2': fake_params } uri = 'fake_uri' msg = "(?=.*{0})(?=.*{1})".format(*list(params.keys())) with testtools.ExpectedException(exceptions.UnknownServiceClient, value_re=msg): clients.ServiceClients(creds, identity_uri=uri, client_parameters=params)
def test___init___creds_uri_params(self): creds = fake_credentials.FakeKeystoneV2Credentials() expeted_params = { 'fake_param1': 'fake_value1', 'fake_param2': 'fake_value2' } params = {'fake_service1': expeted_params} uri = 'fake_uri' _manager = clients.ServiceClients(creds, identity_uri=uri, client_parameters=params) self.assertIn('fake_service1', _manager.parameters) for _key in expeted_params: self.assertIn(_key, _manager.parameters['fake_service1'].keys()) self.assertEqual(expeted_params[_key], _manager.parameters['fake_service1'].get(_key))
def test___init___plugin_service_clients_name_conflict(self): creds = fake_credentials.FakeKeystoneV3Credentials() uri = 'fake_uri' fake_service_clients = { 'serviceA': [{ 'name': 'client1', 'service_version': 'client1.v1', 'module_path': 'fake_path_1', 'client_names': ['SomeClient1'] }], 'serviceB': [{ 'name': 'client1', 'service_version': 'client1.v2', 'module_path': 'fake_path_2', 'client_names': ['SomeClient2'] }], 'serviceC': [{ 'name': 'client1', 'service_version': 'client1.v1', 'module_path': 'fake_path_2', 'client_names': ['SomeClient1'] }], 'serviceD': [{ 'name': 'client1', 'service_version': 'client1.v2', 'module_path': 'fake_path_2', 'client_names': ['SomeClient2'] }] } msg = "(?=.*{0})(?=.*{1})".format( * [x[1][0]['service_version'] for x in fake_service_clients.items()]) self.useFixture( fixtures.MockPatchObject(clients.ClientsRegistry(), 'get_service_clients', return_value=fake_service_clients)) with testtools.ExpectedException(testtools.MultipleExceptions, value_re=msg): clients.ServiceClients(creds, identity_uri=uri)
def _wrap_creds_with_network(self, hash): creds_dict = self.hash_dict['creds'][hash] # Make sure a domain scope if defined for users in case of V3 # Make sure a tenant is available in case of V2 creds_dict = self._extend_credentials(creds_dict) # This just builds a Credentials object, it does not validate # nor fill with missing fields. credential = auth.get_credentials( auth_url=None, fill_in=False, identity_version=self.identity_version, **creds_dict) net_creds = cred_provider.TestResources(credential) net_clients = clients.ServiceClients(credentials=credential, identity_uri=self.identity_uri) networks_client = net_clients.network.NetworksClient() net_name = self.hash_dict['networks'].get(hash, None) try: network = fixed_network.get_network_from_name( net_name, networks_client) except lib_exc.InvalidTestResource: network = {} net_creds.set_resources(network=network) return net_creds
def _get_manager(self, init_region='fake_region'): # Get a manager to invoke _setup_parameters on creds = fake_credentials.FakeKeystoneV2Credentials() return clients.ServiceClients(creds, identity_uri='fake_uri', region=init_region)
def test___init___invalid_creds_uri(self): creds = fake_credentials.FakeKeystoneV2Credentials() delattr(creds, 'username') uri = 'fake_uri' with testtools.ExpectedException(exceptions.InvalidCredentials): clients.ServiceClients(creds, identity_uri=uri)
def test___init___base_creds_uri(self): creds = fake_credentials.FakeCredentials() uri = 'fake_uri' with testtools.ExpectedException(exceptions.InvalidCredentials): clients.ServiceClients(creds, identity_uri=uri)