From 797a63b345328a9f3e89202a1242aff94c6f5a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Albert?= Date: Wed, 13 May 2015 19:23:42 +0200 Subject: [PATCH] Fixed tenant fetcher using Keystone objects Change-Id: I3b84ff7850156bbfad86634719cb880a64ab6d29 --- cloudkitty/orchestrator.py | 4 ++-- cloudkitty/tenant_fetcher/keystone.py | 2 +- cloudkitty/tests/test_keystone_fetcher.py | 11 ++++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cloudkitty/orchestrator.py b/cloudkitty/orchestrator.py index 51aa14b2..046e9e23 100644 --- a/cloudkitty/orchestrator.py +++ b/cloudkitty/orchestrator.py @@ -297,12 +297,12 @@ class Orchestrator(object): self._load_tenant_list() while len(self._tenants): for tenant in self._tenants: - if not self._check_state(tenant.id): + if not self._check_state(tenant): self._tenants.remove(tenant) else: worker = Worker(self.collector, self.storage, - tenant.id) + tenant) worker.run() # FIXME(sheeprine): We may cause a drift here eventlet.sleep(CONF.collect.period) diff --git a/cloudkitty/tenant_fetcher/keystone.py b/cloudkitty/tenant_fetcher/keystone.py index 50b9dc88..16405f1c 100644 --- a/cloudkitty/tenant_fetcher/keystone.py +++ b/cloudkitty/tenant_fetcher/keystone.py @@ -69,4 +69,4 @@ class KeystoneFetcher(tenant_fetcher.BaseFetcher): tenant) if 'rating' not in [role.name for role in roles]: tenant_list.remove(tenant) - return tenant_list + return [tenant.id for tenant in tenant_list] diff --git a/cloudkitty/tests/test_keystone_fetcher.py b/cloudkitty/tests/test_keystone_fetcher.py index 2b38996e..015af7c6 100644 --- a/cloudkitty/tests/test_keystone_fetcher.py +++ b/cloudkitty/tests/test_keystone_fetcher.py @@ -28,6 +28,11 @@ class FakeRole(object): self.name = name +class FakeTenant(object): + def __init__(self, id): + self.id = id + + class FakeKeystoneClient(object): user_id = 'd89e3fee-2b92-4387-b564-63901d62e591' @@ -38,8 +43,8 @@ class FakeKeystoneClient(object): class FakeTenants(object): @classmethod def list(cls): - return ['f266f30b11f246b589fd266f85eeec39', - '4dfb25b0947c4f5481daf7b948c14187'] + return [FakeTenant('f266f30b11f246b589fd266f85eeec39'), + FakeTenant('4dfb25b0947c4f5481daf7b948c14187')] class FakeRoles(object): roles_mapping = { @@ -50,7 +55,7 @@ class FakeKeystoneClient(object): @classmethod def roles_for_user(cls, user_id, tenant, **kwargs): - return cls.roles_mapping[user_id][tenant] + return cls.roles_mapping[user_id][tenant.id] roles = FakeRoles() tenants = FakeTenants()