From d054c7c7407f5f20e6b01f151529bf44fe8ef577 Mon Sep 17 00:00:00 2001 From: xiangjun li Date: Mon, 14 Sep 2015 13:14:07 +0800 Subject: [PATCH] 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 --- ceilometer/compute/pollsters/util.py | 1 + ceilometer/tests/unit/compute/pollsters/base.py | 2 ++ ceilometer/tests/unit/compute/pollsters/test_instance.py | 1 + 3 files changed, 4 insertions(+) diff --git a/ceilometer/compute/pollsters/util.py b/ceilometer/compute/pollsters/util.py index a9371f11..f3268997 100644 --- a/ceilometer/compute/pollsters/util.py +++ b/ceilometer/compute/pollsters/util.py @@ -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 diff --git a/ceilometer/tests/unit/compute/pollsters/base.py b/ceilometer/tests/unit/compute/pollsters/base.py index 1aa3afe7..95fd86b2 100644 --- a/ceilometer/tests/unit/compute/pollsters/base.py +++ b/ceilometer/tests/unit/compute/pollsters/base.py @@ -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} diff --git a/ceilometer/tests/unit/compute/pollsters/test_instance.py b/ceilometer/tests/unit/compute/pollsters/test_instance.py index ea6df35d..f100f543 100644 --- a/ceilometer/tests/unit/compute/pollsters/test_instance.py +++ b/ceilometer/tests/unit/compute/pollsters/test_instance.py @@ -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):