Merge "Fix empty metadata issue of instance"
This commit is contained in:
commit
f99d550aa5
@ -122,6 +122,10 @@ class Instance(object):
|
||||
return {
|
||||
'id': self.instance_type_id,
|
||||
'name': self.flavor_name,
|
||||
'vcpus': self.vcpus,
|
||||
'ram': self.memory_mb,
|
||||
'disk': self.root_gb + self.ephemeral_gb,
|
||||
'ephemeral': self.ephemeral_gb
|
||||
}
|
||||
|
||||
@property
|
||||
|
@ -33,12 +33,7 @@ INSTANCE_PROPERTIES = [
|
||||
'kernel_id',
|
||||
'os_type',
|
||||
'ramdisk_id',
|
||||
# Capacity properties
|
||||
'disk_gb',
|
||||
'ephemeral_gb',
|
||||
'memory_mb',
|
||||
'root_gb',
|
||||
'vcpus']
|
||||
]
|
||||
|
||||
OPTS = [
|
||||
cfg.ListOpt('reserved_metadata_namespace',
|
||||
@ -92,7 +87,16 @@ def _get_metadata_from_object(instance):
|
||||
metadata['image_ref_url'] = None
|
||||
|
||||
for name in INSTANCE_PROPERTIES:
|
||||
metadata[name] = getattr(instance, name, u'')
|
||||
if hasattr(instance, name):
|
||||
metadata[name] = getattr(instance, name)
|
||||
|
||||
metadata['vcpus'] = instance.flavor['vcpus']
|
||||
metadata['memory_mb'] = instance.flavor['ram']
|
||||
metadata['disk_gb'] = instance.flavor['disk']
|
||||
metadata['ephemeral_gb'] = instance.flavor['ephemeral']
|
||||
metadata['root_gb'] = int(metadata['disk_gb']) - \
|
||||
int(metadata['ephemeral_gb'])
|
||||
|
||||
return _add_reserved_user_metadata(instance, metadata)
|
||||
|
||||
|
||||
|
@ -70,7 +70,9 @@ class Client(object):
|
||||
flavor = None
|
||||
|
||||
attr_defaults = [('name', 'unknown-id-%s' % fid),
|
||||
('vcpus', 0), ('ram', 0), ('disk', 0)]
|
||||
('vcpus', 0), ('ram', 0), ('disk', 0),
|
||||
('ephemeral', 0)]
|
||||
|
||||
for attr, default in attr_defaults:
|
||||
if not flavor:
|
||||
instance.flavor[attr] = default
|
||||
|
@ -37,4 +37,4 @@ class TestPollsterBase(test_base.TestCase):
|
||||
self.instance.name)
|
||||
self.instance.id = 1
|
||||
self.instance.flavor = {'name': 'm1.small', 'id': 2, 'vcpus': 1,
|
||||
'ram': 512, 'disk': 0}
|
||||
'ram': 512, 'disk': 20, 'ephemeral': 0}
|
||||
|
@ -40,6 +40,11 @@ class TestInstancePollster(base.TestPollsterBase):
|
||||
samples = list(pollster.get_samples(mgr, {}, self.instance))
|
||||
self.assertEqual(len(samples), 1)
|
||||
self.assertEqual(samples[0].name, 'instance')
|
||||
self.assertEqual(samples[0].resource_metadata['vcpus'], 1)
|
||||
self.assertEqual(samples[0].resource_metadata['memory_mb'], 512)
|
||||
self.assertEqual(samples[0].resource_metadata['disk_gb'], 20)
|
||||
self.assertEqual(samples[0].resource_metadata['root_gb'], 20)
|
||||
self.assertEqual(samples[0].resource_metadata['ephemeral_gb'], 0)
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
def test_get_samples_instance_flavor(self):
|
||||
|
@ -61,16 +61,18 @@ class TestLocationMetadata(test_base.TestCase):
|
||||
'kernel_id': 'kernel id',
|
||||
'os_type': 'linux',
|
||||
'ramdisk_id': 'ramdisk id',
|
||||
'ephemeral_gb': 7,
|
||||
'root_gb': 3,
|
||||
'ephemeral_gb': 0,
|
||||
'root_gb': 20,
|
||||
'disk_gb': 20,
|
||||
'image': {'id': 1,
|
||||
'links': [{"rel": "bookmark",
|
||||
'href': 2}]},
|
||||
'hostId': '1234-5678',
|
||||
'flavor': {'id': 1,
|
||||
'disk': 0,
|
||||
'disk': 20,
|
||||
'ram': 512,
|
||||
'vcpus': 2},
|
||||
'vcpus': 2,
|
||||
'ephemeral': 0},
|
||||
'metadata': {'metering.autoscale.group':
|
||||
'X' * 512,
|
||||
'metering.ephemeral_gb': 42}}
|
||||
|
Loading…
Reference in New Issue
Block a user