Update compute vnic pollster to use cache

Use the pollster cache to store the VNIC info
for an instance. Eventually the single pollster will
be broken up into separate pollsters that all use
the cache.

blueprint one-meter-per-plugin

Change-Id: I8d9af0006d280f26ea768db97608074c5cfc9457
Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
This commit is contained in:
Doug Hellmann 2013-07-03 17:01:08 -04:00
parent f51b20e21f
commit 19e5eb1536
2 changed files with 44 additions and 1 deletions

View File

@ -275,11 +275,26 @@ class NetPollster(plugin.ComputePollster):
'network.outgoing.bytes',
'network.outgoing.packets']
CACHE_KEY_VNIC = 'vnics'
def _get_vnics_for_instance(self, cache, inspector, instance_name):
i_cache = cache.setdefault(self.CACHE_KEY_VNIC, {})
if instance_name not in i_cache:
i_cache[instance_name] = list(
inspector.inspect_vnics(instance_name)
)
return i_cache[instance_name]
def get_counters(self, manager, cache, instance):
instance_name = _instance_name(instance)
self.LOG.info('checking instance %s', instance.id)
try:
for vnic, info in manager.inspector.inspect_vnics(instance_name):
vnics = self._get_vnics_for_instance(
cache,
manager.inspector,
instance_name,
)
for vnic, info in vnics:
self.LOG.info(self.NET_USAGE_MESSAGE, instance_name,
vnic.name, info.rx_bytes, info.tx_bytes)
yield self.make_vnic_counter(instance,

View File

@ -219,6 +219,34 @@ class TestNetPollster(TestPollsterBase):
_verify_vnic_metering('network.outgoing.packets', '192.168.0.4', 12L,
"%s-%s" % (instance_name_id, vnic2.name))
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_counters_cache(self):
vnic0 = virt_inspector.Interface(
name='vnet0',
fref='fa163e71ec6e',
mac='fa:16:3e:71:ec:6d',
parameters=dict(ip='10.0.0.2',
projmask='255.255.255.0',
projnet='proj1',
dhcp_server='10.0.0.1'))
stats0 = virt_inspector.InterfaceStats(rx_bytes=1L, rx_packets=2L,
tx_bytes=3L, tx_packets=4L)
vnics = [(vnic0, stats0)]
self.mox.ReplayAll()
mgr = manager.AgentManager()
pollster = pollsters.NetPollster()
cache = {
pollster.CACHE_KEY_VNIC: {
self.instance.name: vnics,
},
}
counters = list(pollster.get_counters(mgr, cache, self.instance))
assert counters
# We should have one of each counter for one vnic
self.assertEqual(len(counters), 4)
class TestCPUPollster(TestPollsterBase):