Add attribute 'state' to meter metadata when source is polling

For now, instance attribute 'state' is stored to
metadata of meter which was generated from
notifications. But when meter was generated from
instance polling, 'state' is not stored to
metadata of meter even this attribute could be
retrieved from polling action. Because the meter
generated from notifications or polling update
the resource information in database in cycles,
the resource show API may return the instance
metadata with different style(sometimes the
returned metadata contains 'state', but at other
times, the 'state' is disappeared in it), which
may confuse us in some situations. In this patch,
'state' has been added to the meter metadata if
the meter was generated from polling source.

Closes-Bug: #1491224

Change-Id: Ie869672901b1d13f9444d0ca0e7d849f5e4ffc4b
This commit is contained in:
xiangjun li 2015-09-14 13:14:07 +08:00
parent 551402cd13
commit d054c7c740
3 changed files with 4 additions and 0 deletions

View File

@ -41,6 +41,7 @@ def _get_metadata_from_object(instance):
'host': instance.hostId,
'flavor': instance.flavor,
'status': instance.status.lower(),
'state': getattr(instance, 'OS-EXT-STS:vm_state', u''),
}
# Image properties

View File

@ -30,6 +30,8 @@ class TestPollsterBase(base.BaseTestCase):
self.instance.name = 'instance-00000001'
setattr(self.instance, 'OS-EXT-SRV-ATTR:instance_name',
self.instance.name)
setattr(self.instance, 'OS-EXT-STS:vm_state',
'active')
self.instance.id = 1
self.instance.flavor = {'name': 'm1.small', 'id': 2, 'vcpus': 1,
'ram': 512, 'disk': 20, 'ephemeral': 0}

View File

@ -40,6 +40,7 @@ class TestInstancePollster(base.TestPollsterBase):
self.assertEqual(20, samples[0].resource_metadata['root_gb'])
self.assertEqual(0, samples[0].resource_metadata['ephemeral_gb'])
self.assertEqual('active', samples[0].resource_metadata['status'])
self.assertEqual('active', samples[0].resource_metadata['state'])
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_reserved_metadata_with_keys(self):