Swift pollster silently return no counter if keystone endpoint is not present
Fixes bug 1131359 Change-Id: I861d9e75fb6e77eabe7e8e519875676faf7ddf3a
This commit is contained in:
parent
4abb407152
commit
6e4a7f7150
@ -24,6 +24,7 @@ import abc
|
|||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
from swiftclient import client as swift
|
from swiftclient import client as swift
|
||||||
|
from keystoneclient import exceptions
|
||||||
|
|
||||||
from ceilometer import counter
|
from ceilometer import counter
|
||||||
from ceilometer.openstack.common import log
|
from ceilometer.openstack.common import log
|
||||||
@ -101,9 +102,14 @@ class SwiftPollster(_Base):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def iter_accounts(ksclient):
|
def iter_accounts(ksclient):
|
||||||
endpoint = ksclient.service_catalog.url_for(
|
try:
|
||||||
service_type='object-store',
|
endpoint = ksclient.service_catalog.url_for(
|
||||||
endpoint_type='adminURL')
|
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)
|
base_url = '%s/v1/%s' % (endpoint, cfg.CONF.reseller_prefix)
|
||||||
for t in ksclient.tenants.list():
|
for t in ksclient.tenants.list():
|
||||||
yield (t.id, swift.head_account('%s%s' % (base_url, t.id),
|
yield (t.id, swift.head_account('%s%s' % (base_url, t.id),
|
||||||
|
@ -23,6 +23,8 @@ from ceilometer.central import manager
|
|||||||
from ceilometer.objectstore import swift
|
from ceilometer.objectstore import swift
|
||||||
from ceilometer.tests import base
|
from ceilometer.tests import base
|
||||||
|
|
||||||
|
from keystoneclient import exceptions
|
||||||
|
|
||||||
ACCOUNTS = [('tenant-000', {'x-account-object-count': 12,
|
ACCOUNTS = [('tenant-000', {'x-account-object-count': 12,
|
||||||
'x-account-bytes-used': 321321321,
|
'x-account-bytes-used': 321321321,
|
||||||
'x-account-container-count': 7,
|
'x-account-container-count': 7,
|
||||||
@ -37,11 +39,15 @@ class TestManager(manager.AgentManager):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(TestManager, self).__init__()
|
super(TestManager, self).__init__()
|
||||||
self.keystone = None
|
self.keystone = mock.MagicMock()
|
||||||
|
|
||||||
|
|
||||||
class TestSwiftPollster(base.TestCase):
|
class TestSwiftPollster(base.TestCase):
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def fake_ks_service_catalog_url_for(*args, **kwargs):
|
||||||
|
raise exceptions.EndpointNotFound("Fake keystone exception")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fake_iter_accounts(self, ksclient):
|
def fake_iter_accounts(self, ksclient):
|
||||||
for i in ACCOUNTS:
|
for i in ACCOUNTS:
|
||||||
@ -52,14 +58,22 @@ class TestSwiftPollster(base.TestCase):
|
|||||||
super(TestSwiftPollster, self).setUp()
|
super(TestSwiftPollster, self).setUp()
|
||||||
self.pollster = swift.SwiftPollster()
|
self.pollster = swift.SwiftPollster()
|
||||||
self.manager = TestManager()
|
self.manager = TestManager()
|
||||||
self.stubs.Set(swift.SwiftPollster, 'iter_accounts',
|
|
||||||
self.fake_iter_accounts)
|
|
||||||
|
|
||||||
def test_objectstore_metering(self):
|
def test_objectstore_metering(self):
|
||||||
|
self.stubs.Set(swift.SwiftPollster, 'iter_accounts',
|
||||||
|
self.fake_iter_accounts)
|
||||||
counters = list(self.pollster.get_counters(self.manager))
|
counters = list(self.pollster.get_counters(self.manager))
|
||||||
self.assertEqual(len(counters), 6)
|
self.assertEqual(len(counters), 6)
|
||||||
|
|
||||||
def test_objectstore_get_counter_names(self):
|
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))
|
counters = list(self.pollster.get_counters(self.manager))
|
||||||
self.assertEqual(set([c.name for c in counters]),
|
self.assertEqual(set([c.name for c in counters]),
|
||||||
set(self.pollster.get_counter_names()))
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user