Support new InterfaceStats

The InterfaceStats API has been updated to include a new set of metrics.
PowerVM does not support all of the new drop/error types.  However, it
does have a total drop packets count.  Since we poll the client side
VEA, those are likely dropped on transmit.  Therefore the dropped
packets counter works against the client side NIC, and counts all drops
as transmit drops.

Change-Id: Id75757d886df4b859e86da8a498b75d36c267e39
Closes-Bug: #1632710
This commit is contained in:
Drew Thorstensen 2016-10-12 09:41:46 -04:00
parent 98bb94a9b4
commit 793901ffc7
2 changed files with 21 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# Copyright 2015 IBM Corp.
# Copyright 2015, 2016 IBM Corp.
#
# All Rights Reserved.
#
@ -283,11 +283,18 @@ class PowerVMInspector(virt_inspector.Inspector):
name=metric_cna.physical_location,
mac=mac, fref=None, parameters=None)
# PowerVM doesn't specify drops by receive vs. transmit. Since we
# have the client adapter, we assume all are receive drops.
# There are no error metrics available.
stats = virt_inspector.InterfaceStats(
rx_bytes=metric_cna.received_bytes,
rx_packets=metric_cna.received_packets,
rx_drop=metric_cna.dropped_packets,
rx_errors=0,
tx_bytes=metric_cna.sent_bytes,
tx_packets=metric_cna.sent_packets)
tx_packets=metric_cna.sent_packets,
tx_drop=0,
tx_errors=0)
# Yield the stats up to the invoker
yield (interface, stats)

View File

@ -187,17 +187,18 @@ class TestPowerVMInspector(base.BaseTestCase):
self.assertEqual(0.0, resp.util)
@staticmethod
def _mock_vnic_metric(rec_bytes, tx_bytes, rec_pkts, tx_pkts, phys_loc):
def _mock_vnic_metric(rec_bytes, tx_bytes, rec_pkts, tx_pkts, phys_loc,
drop_pkts):
"""Helper method to create a specific mock network metric."""
return mock.Mock(received_bytes=rec_bytes, sent_bytes=tx_bytes,
received_packets=rec_pkts, sent_packets=tx_pkts,
physical_location=phys_loc)
dropped_packets=drop_pkts, physical_location=phys_loc)
def _build_cur_mock_vnic_metrics(self):
"""Helper method to create mock network metrics."""
cna1 = self._mock_vnic_metric(1000, 1000, 10, 10, 'a')
cna2 = self._mock_vnic_metric(2000, 2000, 20, 20, 'b')
cna3 = self._mock_vnic_metric(3000, 3000, 30, 30, 'c')
cna1 = self._mock_vnic_metric(1000, 1000, 10, 10, 'a', 1)
cna2 = self._mock_vnic_metric(2000, 2000, 20, 20, 'b', 2)
cna3 = self._mock_vnic_metric(3000, 3000, 30, 30, 'c', 3)
metric = mock.MagicMock()
metric.network.cnas = [cna1, cna2, cna3]
@ -205,8 +206,8 @@ class TestPowerVMInspector(base.BaseTestCase):
def _build_prev_mock_vnic_metrics(self):
"""Helper method to create mock network metrics."""
cna1 = self._mock_vnic_metric(1000, 1000, 10, 10, 'a')
cna2 = self._mock_vnic_metric(200, 200, 20, 20, 'b')
cna1 = self._mock_vnic_metric(1000, 1000, 10, 10, 'a', 1)
cna2 = self._mock_vnic_metric(200, 200, 20, 20, 'b', 2)
metric = mock.MagicMock()
metric.network.cnas = [cna1, cna2]
@ -258,6 +259,10 @@ class TestPowerVMInspector(base.BaseTestCase):
self.assertEqual(1000, stats1.tx_bytes)
self.assertEqual(10, stats1.rx_packets)
self.assertEqual(10, stats1.tx_packets)
self.assertEqual(1, stats1.rx_drop)
self.assertEqual(0, stats1.tx_drop)
self.assertEqual(0, stats1.rx_errors)
self.assertEqual(0, stats1.tx_errors)
@mock.patch('pypowervm.wrappers.network.CNA.wrap')
def test_inspect_vnic_rates(self, mock_wrap):