def test_verified_keystone_unreachable(self, mock_keystone_create_client): mock_keystone_create_client.return_value = fakes.FakeKeystoneClient() mock_keystone_create_client.side_effect = ( keystone_exceptions.AuthorizationFailure ) self.assertRaises(exceptions.HostUnreachableException, self.clients.verified_keystone)
def test_verified_keystone_user_not_admin(self, mock_keystone_create_client): # naming rule for mocks sucks mock_keystone = mock_keystone_create_client mock_keystone.return_value = fakes.FakeKeystoneClient() mock_keystone.return_value.auth_ref.role_names = ["notadmin"] self.assertRaises(exceptions.InvalidAdminException, self.clients.verified_keystone)
def test_list_tenants(self): fake_keystone = fakes.FakeKeystoneClient() fake_keystone.tenants.list = mock.MagicMock() fake_clients = fakes.FakeClients() fake_clients._keystone = fake_keystone scenario = utils.KeystoneScenario(admin_clients=fake_clients) scenario._list_tenants() fake_keystone.tenants.list.assert_called_once_with() self._test_atomic_action_timer(scenario.atomic_actions(), 'keystone.list_tenants')
def test_get_service(self): service = mock.MagicMock() fake_keystone = fakes.FakeKeystoneClient() fake_keystone.services.get = mock.MagicMock(return_value=service) fake_clients = fakes.FakeClients() fake_clients._keystone = fake_keystone scenario = utils.KeystoneScenario(admin_clients=fake_clients) scenario._get_service(service_id=service.id) fake_keystone.services.get.assert_called_once_with(service.id) self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.get_service")
def test_get_user(self): user = mock.MagicMock() fake_keystone = fakes.FakeKeystoneClient() fake_keystone.users.get = mock.MagicMock(return_value=user) fake_clients = fakes.FakeClients() fake_clients._keystone = fake_keystone scenario = utils.KeystoneScenario(admin_clients=fake_clients) scenario._get_user(user_id=user.id) fake_keystone.users.get.assert_called_once_with(user.id) self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.get_user")
def test_get_tenant(self): tenant = mock.MagicMock() fake_keystone = fakes.FakeKeystoneClient() fake_keystone.tenants.get = mock.MagicMock(return_value=tenant) fake_clients = fakes.FakeClients() fake_clients._keystone = fake_keystone scenario = utils.KeystoneScenario(admin_clients=fake_clients) scenario._get_tenant(tenant_id=tenant.id) fake_keystone.tenants.get.assert_called_once_with(tenant.id) self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.get_tenant")
def setUp(self): super(OSClientsTestCase, self).setUp() self.endpoint = endpoint.Endpoint("http://auth_url", "use", "pass", "tenant") self.clients = osclients.Clients(self.endpoint) self.fake_keystone = fakes.FakeKeystoneClient() self.fake_keystone.auth_token = mock.MagicMock() self.service_catalog = self.fake_keystone.service_catalog self.service_catalog.url_for = mock.MagicMock() keystone_patcher = mock.patch("rally.osclients.create_keystone_client") self.mock_create_keystone_client = keystone_patcher.start() self.addCleanup(keystone_patcher.stop) self.mock_create_keystone_client.return_value = self.fake_keystone
def test_update_user_password(self): password = "******" user = mock.MagicMock() fake_keystone = fakes.FakeKeystoneClient() fake_keystone.users.update_password = mock.MagicMock() fake_clients = fakes.FakeClients() fake_clients._keystone = fake_keystone scenario = utils.KeystoneScenario(admin_clients=fake_clients) scenario._update_user_password(password=password, user_id=user.id) fake_keystone.users.update_password.assert_called_once_with( user.id, password) self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.update_user_password")
def setUp(self): super(OSClientsTestCase, self).setUp() self.credential = objects.Credential("http://auth_url/v2.0", "user", "pass", "tenant") self.clients = osclients.Clients(self.credential, {}) self.fake_keystone = fakes.FakeKeystoneClient() keystone_patcher = mock.patch("rally.osclients.Keystone.create_client", return_value=self.fake_keystone) self.mock_create_keystone_client = keystone_patcher.start() self.auth_ref_patcher = mock.patch("rally.osclients.Keystone.auth_ref") self.auth_ref = self.auth_ref_patcher.start() self.service_catalog = self.auth_ref.service_catalog self.service_catalog.url_for = mock.MagicMock()
def test_tenant_create(self, mock_gen_name): name = "abc" mock_gen_name.return_value = name tenant = {} fake_keystone = fakes.FakeKeystoneClient() fake_keystone.tenants.create = mock.MagicMock(return_value=tenant) fake_clients = fakes.FakeClients() fake_clients._keystone = fake_keystone scenario = utils.KeystoneScenario(admin_clients=fake_clients) result = scenario._tenant_create() self.assertEqual(tenant, result) fake_keystone.tenants.create.assert_called_once_with(name) self._test_atomic_action_timer(scenario.atomic_actions(), 'keystone.create_tenant')
def test_user_create(self, mock_gen_name, mock_uuid4): user = {} fake_keystone = fakes.FakeKeystoneClient() fake_keystone.users.create = mock.MagicMock(return_value=user) fake_clients = fakes.FakeClients() fake_clients._keystone = fake_keystone scenario = utils.KeystoneScenario(admin_clients=fake_clients) result = scenario._user_create() self.assertEqual(user, result) fake_keystone.users.create.assert_called_once_with( mock_gen_name.return_value, password=mock_uuid4.return_value, email=mock_gen_name.return_value + "@rally.me") mock_uuid4.assert_called_with() self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.create_user")
def test_tenant_create_with_users(self, mock_gen_name): name = "abc" mock_gen_name.return_value = name tenant = mock.MagicMock() fake_keystone = fakes.FakeKeystoneClient() fake_keystone.users.create = mock.MagicMock() fake_clients = fakes.FakeClients() fake_clients._keystone = fake_keystone scenario = utils.KeystoneScenario(admin_clients=fake_clients) scenario._users_create(tenant, users_per_tenant=1, name_length=10) fake_keystone.users.create.assert_called_once_with( name, password=name, email=name + "@rally.me", tenant_id=tenant.id) self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.create_users")
def test_update_tenant(self): tenant = mock.MagicMock() description = tenant.name + "_description_updated_test" name = tenant.name + "test_updated_test" fake_keystone = fakes.FakeKeystoneClient() fake_keystone.tenants.update = mock.MagicMock() fake_clients = fakes.FakeClients() fake_clients._keystone = fake_keystone scenario = utils.KeystoneScenario(admin_clients=fake_clients) scenario._update_tenant(tenant=tenant, name=name, description=description) fake_keystone.tenants.update.assert_called_once_with( tenant.id, name, description) self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.update_tenant")
def test_service_create(self, mock_gen_name): name = "abc" mock_gen_name.return_value = name service_type = name + "service_type" description = name + "_description" service = {} fake_keystone = fakes.FakeKeystoneClient() fake_keystone.services.create = mock.MagicMock(return_value=service) fake_clients = fakes.FakeClients() fake_clients._keystone = fake_keystone scenario = utils.KeystoneScenario(admin_clients=fake_clients) result = scenario._service_create(name=name, service_type=service_type, description=description) self.assertEqual(service, result) fake_keystone.services.create.assert_called_once_with( name, service_type, description) self._test_atomic_action_timer(scenario.atomic_actions(), "keystone.create_service")
def test_verified_keystone_unauthorized(self, mock_keystone): mock_keystone.return_value = fakes.FakeKeystoneClient() mock_keystone.side_effect = keystone_exceptions.Unauthorized self.assertRaises(exceptions.InvalidEndpointsException, self.clients.verified_keystone)
def test_verified_keystone_user_not_admin(self, mock_clients_keystone): mock_clients_keystone.return_value = fakes.FakeKeystoneClient() mock_clients_keystone.return_value.auth_ref.role_names = ["notadmin"] self.assertRaises(exceptions.InvalidAdminException, self.clients.verified_keystone)