Browse Source

Fix handling of metadatas that are set to None or False

Change-Id: I19bd14f57d925319a220fa7e2b8b492f29e1b8ed
tags/15.0.0.0rc1^0
Rafael Weingärtner 3 weeks ago
committed by Matthias Runge
parent
commit
76d373b1e6
2 changed files with 64 additions and 2 deletions
  1. +2
    -2
      ceilometer/polling/dynamic_pollster.py
  2. +62
    -0
      ceilometer/tests/unit/polling/test_dynamic_pollster.py

+ 2
- 2
ceilometer/polling/dynamic_pollster.py View File

@@ -117,8 +117,8 @@ class PollsterSampleExtractor(object):
for k in pollster_definitions['metadata_fields']:
val = self.retrieve_attribute_nested_value(pollster_sample, k)

if val:
metadata[k] = val
LOG.debug("Assigning value [%s] to metadata key [%s].", val, k)
metadata[k] = val

self.generate_new_metadata_fields(
metadata=metadata, pollster_definitions=pollster_definitions)


+ 62
- 0
ceilometer/tests/unit/polling/test_dynamic_pollster.py View File

@@ -935,3 +935,65 @@ class TestDynamicPollster(base.BaseTestCase):
.get_request_linked_samples_url(kwargs)

self.assertEqual(expected_url, url)

def test_generate_sample_and_extract_metadata(self):
definition = self.pollster_definition_only_required_fields.copy()
definition['metadata_fields'] = ["metadata1", 'metadata2']

pollster = dynamic_pollster.DynamicPollster(definition)

pollster_sample = {'metadata1': 'metadata1',
'metadata2': 'metadata2',
'value': 1}

sample = pollster.definitions.sample_extractor.generate_sample(
pollster_sample)

self.assertEqual(1, sample.volume)
self.assertEqual(2, len(sample.resource_metadata))
self.assertEqual('metadata1', sample.resource_metadata['metadata1'])
self.assertEqual('metadata2', sample.resource_metadata['metadata2'])

def test_generate_sample_and_extract_metadata_false_value(self):
definition = self.pollster_definition_only_required_fields.copy()
definition['metadata_fields'] = ["metadata1",
'metadata2',
'metadata3_false']

pollster = dynamic_pollster.DynamicPollster(definition)

pollster_sample = {'metadata1': 'metadata1',
'metadata2': 'metadata2',
'metadata3_false': False,
'value': 1}

sample = pollster.definitions.sample_extractor.generate_sample(
pollster_sample)

self.assertEqual(1, sample.volume)
self.assertEqual(3, len(sample.resource_metadata))
self.assertEqual('metadata1', sample.resource_metadata['metadata1'])
self.assertEqual('metadata2', sample.resource_metadata['metadata2'])
self.assertIs(False, sample.resource_metadata['metadata3_false'])

def test_generate_sample_and_extract_metadata_none_value(self):
definition = self.pollster_definition_only_required_fields.copy()
definition['metadata_fields'] = ["metadata1",
'metadata2',
'metadata3']

pollster = dynamic_pollster.DynamicPollster(definition)

pollster_sample = {'metadata1': 'metadata1',
'metadata2': 'metadata2',
'metadata3': None,
'value': 1}

sample = pollster.definitions.sample_extractor.generate_sample(
pollster_sample)

self.assertEqual(1, sample.volume)
self.assertEqual(3, len(sample.resource_metadata))
self.assertEqual('metadata1', sample.resource_metadata['metadata1'])
self.assertEqual('metadata2', sample.resource_metadata['metadata2'])
self.assertIsNone(sample.resource_metadata['metadata3'])

Loading…
Cancel
Save