Kwapi pollster silently return no probre if keystone endpoint is not present
Fixes bug 1105404 Change-Id: Ib2673215ca1075d04283492d9e08540f9f786d08
This commit is contained in:
parent
37bc0a7915
commit
fba1ae00c3
@ -20,6 +20,11 @@ import requests
|
||||
|
||||
from ceilometer import counter
|
||||
from ceilometer.central import plugin
|
||||
from ceilometer.openstack.common import log
|
||||
|
||||
from keystoneclient import exceptions
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class KwapiClient(object):
|
||||
@ -58,7 +63,11 @@ class _Base(plugin.CentralPollster):
|
||||
|
||||
def iter_probes(self, ksclient):
|
||||
"""Iterate over all probes."""
|
||||
client = self.get_kwapi_client(ksclient)
|
||||
try:
|
||||
client = self.get_kwapi_client(ksclient)
|
||||
except exceptions.EndpointNotFound:
|
||||
LOG.debug(_("Kwapi endpoint not found"))
|
||||
return []
|
||||
return client.iter_probes()
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@ from ceilometer.energy import kwapi
|
||||
from ceilometer.central import manager
|
||||
from ceilometer.openstack.common import context
|
||||
|
||||
from keystoneclient import exceptions
|
||||
|
||||
PROBE_DICT = {
|
||||
"probes": {
|
||||
@ -61,14 +62,26 @@ class TestKwapiPollster(base.TestCase):
|
||||
probe_dict['id'] = key
|
||||
yield probe_dict
|
||||
|
||||
@staticmethod
|
||||
def fake_kwapi_get_kwapi_client(self, ksclient):
|
||||
raise exceptions.EndpointNotFound("fake keystone exception")
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
def setUp(self):
|
||||
super(TestKwapiPollster, self).setUp()
|
||||
self.context = context.get_admin_context()
|
||||
self.manager = TestManager()
|
||||
self.stubs.Set(kwapi._Base, 'iter_probes', self.fake_kwapi_iter_probes)
|
||||
|
||||
def test_kwapi_endpoint_not_exist(self):
|
||||
self.stubs.Set(kwapi._Base, 'get_kwapi_client',
|
||||
self.fake_kwapi_get_kwapi_client)
|
||||
|
||||
counters = list(kwapi.KwapiPollster().get_counters(self.manager))
|
||||
self.assertEqual(len(counters), 0)
|
||||
|
||||
def test_kwapi_counter(self):
|
||||
self.stubs.Set(kwapi._Base, 'iter_probes', self.fake_kwapi_iter_probes)
|
||||
|
||||
counters = list(kwapi.KwapiPollster().get_counters(self.manager))
|
||||
self.assertEqual(len(counters), 6)
|
||||
energy_counters = [counter for counter in counters
|
||||
@ -89,6 +102,8 @@ class TestKwapiPollster(base.TestCase):
|
||||
power_counters)))
|
||||
|
||||
def test_kwapi_counter_list(self):
|
||||
self.stubs.Set(kwapi._Base, 'iter_probes', self.fake_kwapi_iter_probes)
|
||||
|
||||
counters = list(kwapi.KwapiPollster().get_counters(self.manager))
|
||||
self.assertEqual(set([c.name for c in counters]),
|
||||
set(kwapi.KwapiPollster().get_counter_names()))
|
||||
|
Loading…
Reference in New Issue
Block a user