Handle malformed resource definitions gracefully

Change-Id: Ibfe49741ad5df82a57cc1c344a471be4d23fdffb
Closes-bug: #1542189
This commit is contained in:
Pradeep Kilambi 2016-02-05 14:03:28 -05:00
parent 7a69e46c14
commit 02b1e1399b
3 changed files with 23 additions and 7 deletions

View File

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

View File

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

View File

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