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:
parent
551402cd13
commit
d054c7c740
@ -41,6 +41,7 @@ def _get_metadata_from_object(instance):
|
|||||||
'host': instance.hostId,
|
'host': instance.hostId,
|
||||||
'flavor': instance.flavor,
|
'flavor': instance.flavor,
|
||||||
'status': instance.status.lower(),
|
'status': instance.status.lower(),
|
||||||
|
'state': getattr(instance, 'OS-EXT-STS:vm_state', u''),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Image properties
|
# Image properties
|
||||||
|
@ -30,6 +30,8 @@ class TestPollsterBase(base.BaseTestCase):
|
|||||||
self.instance.name = 'instance-00000001'
|
self.instance.name = 'instance-00000001'
|
||||||
setattr(self.instance, 'OS-EXT-SRV-ATTR:instance_name',
|
setattr(self.instance, 'OS-EXT-SRV-ATTR:instance_name',
|
||||||
self.instance.name)
|
self.instance.name)
|
||||||
|
setattr(self.instance, 'OS-EXT-STS:vm_state',
|
||||||
|
'active')
|
||||||
self.instance.id = 1
|
self.instance.id = 1
|
||||||
self.instance.flavor = {'name': 'm1.small', 'id': 2, 'vcpus': 1,
|
self.instance.flavor = {'name': 'm1.small', 'id': 2, 'vcpus': 1,
|
||||||
'ram': 512, 'disk': 20, 'ephemeral': 0}
|
'ram': 512, 'disk': 20, 'ephemeral': 0}
|
||||||
|
@ -40,6 +40,7 @@ class TestInstancePollster(base.TestPollsterBase):
|
|||||||
self.assertEqual(20, samples[0].resource_metadata['root_gb'])
|
self.assertEqual(20, samples[0].resource_metadata['root_gb'])
|
||||||
self.assertEqual(0, samples[0].resource_metadata['ephemeral_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['status'])
|
||||||
|
self.assertEqual('active', samples[0].resource_metadata['state'])
|
||||||
|
|
||||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||||
def test_get_reserved_metadata_with_keys(self):
|
def test_get_reserved_metadata_with_keys(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user