Implement inspector method - inspect_vnics
Implement inspector method - inspect_vnics, return vnic name, rx_bytes, tx_bytes, rx_packets and tx_packets. Change-Id: Idb97937d9c841a271b408dc6fd47303ccf0d8c4b
This commit is contained in:
parent
02c4ba9fde
commit
21e51e2b18
@ -130,6 +130,8 @@ class ZVMInspector(virt_inspector.Inspector):
|
||||
|
||||
if meter in ('cpus', 'memory.usage'):
|
||||
self._update_inst_cpu_mem_stat(instances)
|
||||
elif meter in ('vnics',):
|
||||
self._update_inst_nic_stat(instances)
|
||||
|
||||
def _check_expiration_and_update_cache(self, meter):
|
||||
now = timeutils.utcnow_ts()
|
||||
@ -163,4 +165,18 @@ class ZVMInspector(virt_inspector.Inspector):
|
||||
return virt_inspector.MemoryUsageStats(usage=inst_stat['used_memory'])
|
||||
|
||||
def inspect_vnics(self, instance):
|
||||
pass
|
||||
inst_stat = self._get_inst_stat('vnics', instance)
|
||||
for nic in inst_stat['nics']:
|
||||
nic_id = '_'.join((nic['vswitch_name'], inst_stat['userid'],
|
||||
nic['nic_vdev']))
|
||||
interface = virt_inspector.Interface(
|
||||
name=nic_id,
|
||||
mac=None,
|
||||
fref=None,
|
||||
parameters=None)
|
||||
stats = virt_inspector.InterfaceStats(
|
||||
rx_bytes=nic['nic_rx'],
|
||||
rx_packets=nic['nic_fr_rx'],
|
||||
tx_bytes=nic['nic_tx'],
|
||||
tx_packets=nic['nic_fr_tx'])
|
||||
yield (interface, stats)
|
||||
|
@ -147,6 +147,30 @@ class TestZVMInspector(base.BaseTestCase):
|
||||
check_update.assert_called_once_with('cpus')
|
||||
update.assert_called_once_with('cpus', {'inst1': 'INST1'})
|
||||
|
||||
@mock.patch.object(zvmutils, 'get_inst_name')
|
||||
@mock.patch("ceilometer_zvm.compute.virt.zvm.inspector.ZVMInspector."
|
||||
"_check_expiration_and_update_cache")
|
||||
def test_get_inst_stat_nics(self, check_update, get_name):
|
||||
get_name.return_value = 'inst1'
|
||||
self.inspector.cache.set({'nodename': 'inst1',
|
||||
'userid': 'INST1',
|
||||
'nics': [
|
||||
{'vswitch_name': 'vsw1',
|
||||
'nic_vdev': '0600',
|
||||
'nic_fr_rx': 99999,
|
||||
'nic_fr_tx': 99999,
|
||||
'nic_rx': 9999999,
|
||||
'nic_tx': 9999999},
|
||||
{'vswitch_name': 'vsw2',
|
||||
'nic_vdev': '0700',
|
||||
'nic_fr_rx': 88888,
|
||||
'nic_fr_tx': 88888,
|
||||
'nic_rx': 8888888,
|
||||
'nic_tx': 8888888}]})
|
||||
inst_stat = self.inspector._get_inst_stat('vnics', {'inst1': 'INST1'})
|
||||
self.assertEqual(2, len(inst_stat['nics']))
|
||||
check_update.assert_called_once_with('vnics')
|
||||
|
||||
@mock.patch("ceilometer_zvm.compute.virt.zvm.inspector.ZVMInspector."
|
||||
"_get_inst_stat")
|
||||
def test_inspect_cpus(self, get_stat):
|
||||
@ -233,3 +257,28 @@ class TestZVMInspector(base.BaseTestCase):
|
||||
self.assertEqual(exp_inst1_nics_data,
|
||||
self.inspector.cache.get('inst1')['nics'])
|
||||
vswq.assert_called_once_with('zhcp')
|
||||
|
||||
@mock.patch("ceilometer_zvm.compute.virt.zvm.inspector.ZVMInspector."
|
||||
"_get_inst_stat")
|
||||
def test_inspect_nics(self, get_stat):
|
||||
get_stat.return_value = {'nodename': 'inst1',
|
||||
'userid': 'INST1',
|
||||
'nics': [
|
||||
{'vswitch_name': 'vsw1',
|
||||
'nic_vdev': '0600',
|
||||
'nic_fr_rx': 99999,
|
||||
'nic_fr_tx': 99999,
|
||||
'nic_rx': 9999999,
|
||||
'nic_tx': 9999999},
|
||||
{'vswitch_name': 'vsw2',
|
||||
'nic_vdev': '0700',
|
||||
'nic_fr_rx': 88888,
|
||||
'nic_fr_tx': 88888,
|
||||
'nic_rx': 8888888,
|
||||
'nic_tx': 8888888}]}
|
||||
nic, stat = list(self.inspector.inspect_vnics({'inst1': 'INST1'}))[0]
|
||||
if nic.name == 'vsw1_INST1_0600':
|
||||
self.assertEqual(99999, stat.rx_packets)
|
||||
else:
|
||||
self.assertEqual(8888888, stat.rx_bytes)
|
||||
get_stat.assert_called_once_with('vnics', {'inst1': 'INST1'})
|
||||
|
Loading…
x
Reference in New Issue
Block a user