summaryrefslogtreecommitdiff
path: root/ceilometer
diff options
context:
space:
mode:
Diffstat (limited to 'ceilometer')
-rw-r--r--ceilometer/compute/discovery.py5
-rw-r--r--ceilometer/compute/pollsters/__init__.py2
-rw-r--r--ceilometer/tests/unit/compute/test_discovery.py28
3 files changed, 32 insertions, 3 deletions
diff --git a/ceilometer/compute/discovery.py b/ceilometer/compute/discovery.py
index 3b13d96b..f3133059 100644
--- a/ceilometer/compute/discovery.py
+++ b/ceilometer/compute/discovery.py
@@ -128,9 +128,10 @@ class InstanceDiscovery(plugin_base.DiscoveryBase):
@cachetools.cachedmethod(operator.attrgetter('_flavor_cache'))
def get_flavor_id(self, name):
try:
- return self.nova_cli.nova_client.flavors.find(name=name).id
+ return self.nova_cli.nova_client.flavors.find(
+ name=name, is_public=None).id
except exceptions.NotFound:
- return None
+ return name
@libvirt_utils.retry_on_disconnect
def discover_libvirt_polling(self, manager, param=None):
diff --git a/ceilometer/compute/pollsters/__init__.py b/ceilometer/compute/pollsters/__init__.py
index 2c32f23c..000a0222 100644
--- a/ceilometer/compute/pollsters/__init__.py
+++ b/ceilometer/compute/pollsters/__init__.py
@@ -96,7 +96,7 @@ class GenericComputePollster(plugin_base.PollsterBase):
instance, duration)
polled_time = now()
# Ensure we don't cache an iterator
- if isinstance(result, collections.Iterable):
+ if isinstance(result, collections.abc.Iterable):
result = list(result)
else:
result = [result]
diff --git a/ceilometer/tests/unit/compute/test_discovery.py b/ceilometer/tests/unit/compute/test_discovery.py
index e5c1c964..0e1eccad 100644
--- a/ceilometer/tests/unit/compute/test_discovery.py
+++ b/ceilometer/tests/unit/compute/test_discovery.py
@@ -17,6 +17,8 @@ from unittest import mock
import fixtures
import testtools
+from novaclient import exceptions
+
try:
import libvirt
except ImportError:
@@ -297,3 +299,29 @@ class TestDiscovery(base.BaseTestCase):
dsc = discovery.InstanceDiscovery(self.CONF)
resources = dsc.discover(mock.MagicMock())
self.assertEqual(0, len(resources))
+
+ def test_get_flavor_id(self):
+ self.CONF.set_override("instance_discovery_method",
+ "libvirt_metadata",
+ group="compute")
+ self.client.nova_client = mock.MagicMock()
+ self.client.nova_client.flavors = mock.MagicMock()
+ fake_flavor = mock.MagicMock()
+ fake_flavor.id = 'fake_id'
+
+ self.client.nova_client.flavors.find = mock.MagicMock(
+ return_value=fake_flavor)
+ dsc = discovery.InstanceDiscovery(self.CONF)
+
+ flavor_name = 'fake_name'
+
+ ret_flavor_id = dsc.get_flavor_id(flavor_name)
+ self.assertEqual('fake_id', ret_flavor_id)
+
+ # test raise NotFound exception
+ self.client.nova_client.flavors.find = mock.MagicMock(
+ side_effect=exceptions.NotFound(404))
+ dsc = discovery.InstanceDiscovery(self.CONF)
+
+ ret_flavor_id = dsc.get_flavor_id(flavor_name)
+ self.assertEqual(flavor_name, ret_flavor_id)