diff --git a/ceilometer/objectstore/swift.py b/ceilometer/objectstore/swift.py index f2f6a10f2..fbee19ec3 100644 --- a/ceilometer/objectstore/swift.py +++ b/ceilometer/objectstore/swift.py @@ -24,6 +24,7 @@ import abc from oslo.config import cfg from swiftclient import client as swift +from keystoneclient import exceptions from ceilometer import counter from ceilometer.openstack.common import log @@ -101,9 +102,14 @@ class SwiftPollster(_Base): @staticmethod def iter_accounts(ksclient): - endpoint = ksclient.service_catalog.url_for( - service_type='object-store', - endpoint_type='adminURL') + try: + endpoint = ksclient.service_catalog.url_for( + service_type='object-store', + endpoint_type='adminURL') + except exceptions.EndpointNotFound: + LOG.debug(_("Swift endpoint not found")) + return + base_url = '%s/v1/%s' % (endpoint, cfg.CONF.reseller_prefix) for t in ksclient.tenants.list(): yield (t.id, swift.head_account('%s%s' % (base_url, t.id), diff --git a/tests/objectstore/test_swift.py b/tests/objectstore/test_swift.py index 5f9fcf832..3f519b8d0 100644 --- a/tests/objectstore/test_swift.py +++ b/tests/objectstore/test_swift.py @@ -23,6 +23,8 @@ from ceilometer.central import manager from ceilometer.objectstore import swift from ceilometer.tests import base +from keystoneclient import exceptions + ACCOUNTS = [('tenant-000', {'x-account-object-count': 12, 'x-account-bytes-used': 321321321, 'x-account-container-count': 7, @@ -37,11 +39,15 @@ class TestManager(manager.AgentManager): def __init__(self): super(TestManager, self).__init__() - self.keystone = None + self.keystone = mock.MagicMock() class TestSwiftPollster(base.TestCase): + @staticmethod + def fake_ks_service_catalog_url_for(*args, **kwargs): + raise exceptions.EndpointNotFound("Fake keystone exception") + @staticmethod def fake_iter_accounts(self, ksclient): for i in ACCOUNTS: @@ -52,14 +58,22 @@ class TestSwiftPollster(base.TestCase): super(TestSwiftPollster, self).setUp() self.pollster = swift.SwiftPollster() self.manager = TestManager() - self.stubs.Set(swift.SwiftPollster, 'iter_accounts', - self.fake_iter_accounts) def test_objectstore_metering(self): + self.stubs.Set(swift.SwiftPollster, 'iter_accounts', + self.fake_iter_accounts) counters = list(self.pollster.get_counters(self.manager)) self.assertEqual(len(counters), 6) def test_objectstore_get_counter_names(self): + self.stubs.Set(swift.SwiftPollster, 'iter_accounts', + self.fake_iter_accounts) counters = list(self.pollster.get_counters(self.manager)) self.assertEqual(set([c.name for c in counters]), set(self.pollster.get_counter_names())) + + def test_objectstore_endpoint_notfound(self): + self.stubs.Set(self.manager.keystone.service_catalog, 'url_for', + self.fake_ks_service_catalog_url_for) + counters = list(self.pollster.get_counters(self.manager)) + self.assertEqual(len(counters), 0)