Change fnmatch.match method to fnmatch.fnmatch

oslo_db.utils.fnmatch has no fnmatch.match now,
only has fnmatch.fnmatch method

Closes-Bug: #1622876
Change-Id: I1d2e2e8e0d294951338f3ef9c560a64738452434
This commit is contained in:
fengchaoyang 2016-09-13 15:39:12 +08:00
parent 4b2f942c70
commit 2c5a419f3b
2 changed files with 24 additions and 3 deletions

View File

@ -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):

View File

@ -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"