Add user_metadata to network samples
Previously 'user_metadata' is not included in ceilometer network samples, while it is in other samples. This causes network samples not triggering alarms heat created. Change-Id: Iafb4c42955fceaaf20fef1f9580ddb1331a0c724 Closes-Bug: 1369500
This commit is contained in:
parent
c3696451d4
commit
cca6fcd89e
@ -24,6 +24,7 @@ from oslo.utils import timeutils
|
||||
import ceilometer
|
||||
from ceilometer.compute import plugin
|
||||
from ceilometer.compute.pollsters import util
|
||||
from ceilometer.compute import util as compute_util
|
||||
from ceilometer.compute.virt import inspector as virt_inspector
|
||||
from ceilometer.openstack.common.gettextutils import _
|
||||
from ceilometer.openstack.common import log
|
||||
@ -45,6 +46,9 @@ class _Base(plugin.ComputePollster):
|
||||
resource_metadata['instance_type'] = (instance.flavor['id'] if
|
||||
instance.flavor else None)
|
||||
|
||||
compute_util.add_reserved_user_metadata(instance.metadata,
|
||||
resource_metadata)
|
||||
|
||||
if vnic_data.fref is not None:
|
||||
rid = vnic_data.fref
|
||||
else:
|
||||
|
@ -22,9 +22,23 @@ import mock
|
||||
from ceilometer.compute import manager
|
||||
from ceilometer.compute.pollsters import net
|
||||
from ceilometer.compute.virt import inspector as virt_inspector
|
||||
from ceilometer import sample
|
||||
from ceilometer.tests.compute.pollsters import base
|
||||
|
||||
|
||||
class FauxInstance(object):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
for name, value in kwargs.items():
|
||||
setattr(self, name, value)
|
||||
|
||||
def __getitem__(self, key):
|
||||
return getattr(self, key)
|
||||
|
||||
def get(self, key, default):
|
||||
return getattr(self, key, default)
|
||||
|
||||
|
||||
class TestNetPollster(base.TestPollsterBase):
|
||||
|
||||
def setUp(self):
|
||||
@ -67,6 +81,37 @@ class TestNetPollster(base.TestPollsterBase):
|
||||
]
|
||||
self.inspector.inspect_vnics = mock.Mock(return_value=vnics)
|
||||
|
||||
self.INSTANCE_PROPERTIES = {'name': 'display name',
|
||||
'OS-EXT-SRV-ATTR:instance_name':
|
||||
'instance-000001',
|
||||
'OS-EXT-AZ:availability_zone': 'foo-zone',
|
||||
'reservation_id': 'reservation id',
|
||||
'id': 'instance id',
|
||||
'user_id': 'user id',
|
||||
'tenant_id': 'tenant id',
|
||||
'architecture': 'x86_64',
|
||||
'kernel_id': 'kernel id',
|
||||
'os_type': 'linux',
|
||||
'ramdisk_id': 'ramdisk id',
|
||||
'status': 'active',
|
||||
'ephemeral_gb': 0,
|
||||
'root_gb': 20,
|
||||
'disk_gb': 20,
|
||||
'image': {'id': 1,
|
||||
'links': [{"rel": "bookmark",
|
||||
'href': 2}]},
|
||||
'hostId': '1234-5678',
|
||||
'flavor': {'id': 1,
|
||||
'disk': 20,
|
||||
'ram': 512,
|
||||
'vcpus': 2,
|
||||
'ephemeral': 0},
|
||||
'metadata': {'metering.autoscale.group':
|
||||
'X' * 512,
|
||||
'metering.ephemeral_gb': 42}}
|
||||
|
||||
self.faux_instance = FauxInstance(**self.INSTANCE_PROPERTIES)
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
def _check_get_samples(self, factory, expected):
|
||||
mgr = manager.AgentManager()
|
||||
@ -132,6 +177,23 @@ class TestNetPollster(base.TestPollsterBase):
|
||||
],
|
||||
)
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
def test_metadata(self):
|
||||
factory = net.OutgoingBytesPollster
|
||||
pollster = factory()
|
||||
sm = pollster.make_vnic_sample(self.faux_instance,
|
||||
name='network.outgoing.bytes',
|
||||
type=sample.TYPE_CUMULATIVE,
|
||||
unit='B',
|
||||
volume=100,
|
||||
vnic_data=self.vnic0)
|
||||
|
||||
user_metadata = sm.resource_metadata['user_metadata']
|
||||
expected = self.INSTANCE_PROPERTIES[
|
||||
'metadata']['metering.autoscale.group'][:256]
|
||||
self.assertEqual(expected, user_metadata['autoscale_group'])
|
||||
self.assertEqual(2, len(user_metadata))
|
||||
|
||||
|
||||
class TestNetPollsterCache(base.TestPollsterBase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user