diff --git a/ceilometer/dispatcher/gnocchi.py b/ceilometer/dispatcher/gnocchi.py index a3b59f9ef8..44b1f64ec5 100644 --- a/ceilometer/dispatcher/gnocchi.py +++ b/ceilometer/dispatcher/gnocchi.py @@ -125,13 +125,13 @@ class ResourcesDefinition(object): def event_match(self, event_type): for e in self._ensure_list(self.cfg.get('event_create', [])): - if fnmatch.match(event_type, e): + if fnmatch.fnmatch(event_type, e): return EVENT_CREATE for e in self._ensure_list(self.cfg.get('event_delete', [])): - if fnmatch.match(event_type, e): + if fnmatch.fnmatch(event_type, e): return EVENT_DELETE for e in self._ensure_list(self.cfg.get('event_update', [])): - if fnmatch.match(event_type, e): + if fnmatch.fnmatch(event_type, e): return EVENT_UPDATE def sample_attributes(self, sample): diff --git a/ceilometer/tests/unit/dispatcher/test_gnocchi.py b/ceilometer/tests/unit/dispatcher/test_gnocchi.py index 4d81bc40b2..15af7efda4 100644 --- a/ceilometer/tests/unit/dispatcher/test_gnocchi.py +++ b/ceilometer/tests/unit/dispatcher/test_gnocchi.py @@ -25,6 +25,7 @@ from oslo_utils import fileutils from oslotest import mockpatch import requests import six +from stevedore import extension import testscenarios from ceilometer.dispatcher import gnocchi @@ -103,6 +104,26 @@ class DispatcherTest(base.BaseTestCase): self.assertIn('instance', names) self.assertIn('volume', names) + def test_match(self): + resource = { + 'metrics': + ['image', 'image.size', 'image.download', 'image.serve'], + 'attributes': + {'container_format': 'resource_metadata.container_format', + 'disk_format': 'resource_metadata.disk_format', + 'name': 'resource_metadata.name'}, + 'event_delete': 'image.delete', + 'event_attributes': {'id': 'resource_id'}, + 'resource_type': 'image'} + plugin_manager = extension.ExtensionManager( + namespace='ceilometer.event.trait.trait_plugin') + rd = gnocchi.ResourcesDefinition( + resource, self.conf.conf.dispatcher_gnocchi.archive_policy, + plugin_manager) + operation = rd.event_match("image.delete") + self.assertEqual('delete', operation) + self.assertEqual(True, rd.metric_match('image')) + @mock.patch('ceilometer.dispatcher.gnocchi.LOG') def test_broken_config_load(self, mylog): contents = [("---\n"