Merge "Update compute vnic pollster to use cache"
This commit is contained in:
commit
ced2b691c1
@ -348,11 +348,26 @@ class NetPollster(plugin.ComputePollster):
|
|||||||
'network.outgoing.bytes',
|
'network.outgoing.bytes',
|
||||||
'network.outgoing.packets']
|
'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):
|
def get_counters(self, manager, cache, instance):
|
||||||
instance_name = _instance_name(instance)
|
instance_name = _instance_name(instance)
|
||||||
self.LOG.info('checking instance %s', instance.id)
|
self.LOG.info('checking instance %s', instance.id)
|
||||||
try:
|
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,
|
self.LOG.info(self.NET_USAGE_MESSAGE, instance_name,
|
||||||
vnic.name, info.rx_bytes, info.tx_bytes)
|
vnic.name, info.rx_bytes, info.tx_bytes)
|
||||||
yield self.make_vnic_counter(instance,
|
yield self.make_vnic_counter(instance,
|
||||||
|
@ -295,6 +295,34 @@ class TestNetPollster(TestPollsterBase):
|
|||||||
_verify_vnic_metering('network.outgoing.packets', '192.168.0.4', 12L,
|
_verify_vnic_metering('network.outgoing.packets', '192.168.0.4', 12L,
|
||||||
"%s-%s" % (instance_name_id, vnic2.name))
|
"%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):
|
class TestCPUPollster(TestPollsterBase):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user