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() self._test_atomic_action_timer(scenario.atomic_actions(), 'keystone.list_tenants')
def test_keystone(self): with mock.patch("rally.osclients.keystone") as mock_keystone: fake_keystone = fakes.FakeKeystoneClient() mock_keystone.Client = mock.MagicMock(return_value=fake_keystone) self.assertTrue("keystone" not in self.clients.cache) client = self.clients.keystone() self.assertEqual(client, fake_keystone) endpoint = { "timeout": cfg.CONF.openstack_client_http_timeout, "insecure": False, "cacert": None } kwargs = dict(self.endpoint.to_dict().items() + endpoint.items()) mock_keystone.Client.assert_called_once_with(**kwargs) self.assertEqual(self.clients.cache["keystone"], fake_keystone)
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_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): name = "abc" mock_gen_name.return_value = name 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( name, name, name + "@rally.me") 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, name, name + "@rally.me", tenant_id=tenant.id) self._test_atomic_action_timer(scenario.atomic_actions(), 'keystone.create_users')
def test_glance(self): with mock.patch("rally.osclients.glance") as mock_glance: fake_glance = fakes.FakeGlanceClient() mock_glance.Client = mock.MagicMock(return_value=fake_glance) kc = fakes.FakeKeystoneClient() self.clients.keystone = mock.MagicMock(return_value=kc) self.assertTrue("glance" not in self.clients.cache) client = self.clients.glance() self.assertEqual(client, fake_glance) endpoint = kc.service_catalog.get_endpoints()["image"][0] kw = { "endpoint": endpoint["publicURL"], "token": kc.auth_token, "timeout": cfg.CONF.openstack_client_http_timeout, "insecure": False, "cacert": None, "region_name": None } mock_glance.Client.assert_called_once_with("1", **kw) self.assertEqual(self.clients.cache["glance"], fake_glance)
def test_ceilometer(self): with mock.patch("rally.osclients.ceilometer") as mock_ceilometer: fake_ceilometer = fakes.FakeCeilometerClient() mock_ceilometer.Client = mock.MagicMock( return_value=fake_ceilometer) kc = fakes.FakeKeystoneClient() self.clients.keystone = mock.MagicMock(return_value=kc) self.assertTrue("ceilometer" not in self.clients.cache) kc.auth_token = mock.MagicMock() client = self.clients.ceilometer() self.assertEqual(client, fake_ceilometer) endpoint = kc.service_catalog.get_endpoints()["metering"][0] kw = { "endpoint": endpoint["publicURL"], "token": kc.auth_token, "timeout": cfg.CONF.openstack_client_http_timeout, "insecure": False, "cacert": None, "region_name": None } mock_ceilometer.Client.assert_called_once_with("2", **kw) self.assertEqual(self.clients.cache["ceilometer"], fake_ceilometer)
def test_verified_keystone_unreachable(self, mock_keystone): mock_keystone.return_value = fakes.FakeKeystoneClient() mock_keystone.side_effect = keystone_exceptions.AuthorizationFailure self.assertRaises(exceptions.HostUnreachableException, self.clients.verified_keystone)
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_keystone): mock_keystone.return_value = fakes.FakeKeystoneClient() mock_keystone.return_value.auth_ref["user"]["roles"] = \ [{"name": "notadmin"}] self.assertRaises(exceptions.InvalidAdminException, self.clients.verified_keystone)
def test_verified_keystone_user_not_admin(self, mock_keystone): mock_keystone.return_value = fakes.FakeKeystoneClient() mock_keystone.return_value.auth_ref.role_names = ["notadmin"] self.assertRaises(exceptions.InvalidAdminException, self.clients.verified_keystone)