Handle malformed resource definitions gracefully
Change-Id: Ibfe49741ad5df82a57cc1c344a471be4d23fdffb Closes-bug: #1542189
This commit is contained in:
parent
7a69e46c14
commit
02b1e1399b
@ -245,9 +245,16 @@ class GnocchiDispatcher(dispatcher.MeterDispatcherBase):
|
||||
namespace='ceilometer.event.trait_plugin')
|
||||
data = declarative.load_definitions(
|
||||
{}, conf.dispatcher_gnocchi.resources_definition_file)
|
||||
return [ResourcesDefinition(r, conf.dispatcher_gnocchi.archive_policy,
|
||||
plugin_manager)
|
||||
for r in data.get('resources', [])]
|
||||
resource_defs = []
|
||||
for resource in data.get('resources', []):
|
||||
try:
|
||||
resource_defs.append(ResourcesDefinition(
|
||||
resource,
|
||||
conf.dispatcher_gnocchi.archive_policy, plugin_manager))
|
||||
except Exception as exc:
|
||||
LOG.error(_LE("Failed to load resource due to error %s") %
|
||||
exc)
|
||||
return resource_defs
|
||||
|
||||
@property
|
||||
def gnocchi_project_id(self):
|
||||
|
@ -27,7 +27,6 @@ import requests
|
||||
import six
|
||||
import testscenarios
|
||||
|
||||
from ceilometer import declarative
|
||||
from ceilometer.dispatcher import gnocchi
|
||||
from ceilometer import service as ceilometer_service
|
||||
from ceilometer.tests import base
|
||||
@ -96,7 +95,8 @@ class DispatcherTest(base.BaseTestCase):
|
||||
self.assertIn('instance', names)
|
||||
self.assertIn('volume', names)
|
||||
|
||||
def test_broken_config_load(self):
|
||||
@mock.patch('ceilometer.dispatcher.gnocchi.LOG')
|
||||
def test_broken_config_load(self, mylog):
|
||||
contents = [("---\n"
|
||||
"resources:\n"
|
||||
" - resource_type: foobar\n"),
|
||||
@ -123,8 +123,9 @@ class DispatcherTest(base.BaseTestCase):
|
||||
self.conf.config(filter_service_activity=False,
|
||||
resources_definition_file=temp,
|
||||
group='dispatcher_gnocchi')
|
||||
self.assertRaises(declarative.DefinitionException,
|
||||
gnocchi.GnocchiDispatcher, self.conf.conf)
|
||||
d = gnocchi.GnocchiDispatcher(self.conf.conf)
|
||||
self.assertTrue(mylog.error.called)
|
||||
self.assertEqual(0, len(d.resources_definition))
|
||||
|
||||
@mock.patch('ceilometer.dispatcher.gnocchi.GnocchiDispatcher'
|
||||
'._process_resource')
|
||||
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
fixes:
|
||||
- >
|
||||
[`bug 1542189 <https://bugs.launchpad.net/ceilometer/+bug/1542189>`_]
|
||||
Handle malformed resource definitions in gnocchi_resources.yaml
|
||||
gracefully. Currently we raise an exception once we hit a bad
|
||||
resource and skip the rest. Instead the patch skips the bad
|
||||
resource and proceeds with rest of the definitions.
|
Loading…
Reference in New Issue
Block a user