From f55e3510bbee39d3101fcbf2283fc037c7a42c99 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Thu, 6 Mar 2014 14:13:11 -0800 Subject: [PATCH] Fixes Hyper-V metrics units Changes the units of the values returned for the network and disks data to bytes as expected. Closes-Bug: #1289015 Change-Id: If4950d05213a345900b3450c83450345e04560fc --- ceilometer/compute/virt/hyperv/inspector.py | 8 ++++---- ceilometer/compute/virt/hyperv/utilsv2.py | 4 ++-- .../tests/compute/virt/hyperv/test_inspector.py | 17 +++++++++-------- .../tests/compute/virt/hyperv/test_utilsv2.py | 10 +++++----- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/ceilometer/compute/virt/hyperv/inspector.py b/ceilometer/compute/virt/hyperv/inspector.py index 01c0de366..6cb2a6966 100644 --- a/ceilometer/compute/virt/hyperv/inspector.py +++ b/ceilometer/compute/virt/hyperv/inspector.py @@ -60,9 +60,9 @@ class HyperVInspector(virt_inspector.Inspector): parameters=None) stats = virt_inspector.InterfaceStats( - rx_bytes=vnic_metrics['rx_bytes'], + rx_bytes=vnic_metrics['rx_mb'] * units.Mi, rx_packets=0, - tx_bytes=vnic_metrics['tx_bytes'], + tx_bytes=vnic_metrics['tx_mb'] * units.Mi, tx_packets=0) yield (interface, stats) @@ -77,9 +77,9 @@ class HyperVInspector(virt_inspector.Inspector): stats = virt_inspector.DiskStats( read_requests=0, # Return bytes - read_bytes=disk_metrics['read_mb'] * units.Ki, + read_bytes=disk_metrics['read_mb'] * units.Mi, write_requests=0, - write_bytes=disk_metrics['write_mb'] * units.Ki, + write_bytes=disk_metrics['write_mb'] * units.Mi, errors=0) yield (disk, stats) diff --git a/ceilometer/compute/virt/hyperv/utilsv2.py b/ceilometer/compute/virt/hyperv/utilsv2.py index 7c96d9cc3..1e45f6f76 100644 --- a/ceilometer/compute/virt/hyperv/utilsv2.py +++ b/ceilometer/compute/virt/hyperv/utilsv2.py @@ -115,8 +115,8 @@ class UtilsV2(object): metric_value_instances, [metric_def_in, metric_def_out]) yield { - 'rx_bytes': metric_values[0], - 'tx_bytes': metric_values[1], + 'rx_mb': metric_values[0], + 'tx_mb': metric_values[1], 'element_name': vnic.ElementName, 'address': vnic.Address } diff --git a/ceilometer/tests/compute/virt/hyperv/test_inspector.py b/ceilometer/tests/compute/virt/hyperv/test_inspector.py index fbc4e0aa4..9850734b2 100644 --- a/ceilometer/tests/compute/virt/hyperv/test_inspector.py +++ b/ceilometer/tests/compute/virt/hyperv/test_inspector.py @@ -21,6 +21,7 @@ import mock from ceilometer.compute.virt.hyperv import inspector as hyperv_inspector from ceilometer.openstack.common import test +from ceilometer.openstack.common import units class TestHyperVInspection(test.BaseTestCase): @@ -69,14 +70,14 @@ class TestHyperVInspection(test.BaseTestCase): def test_inspect_vnics(self): fake_instance_name = 'fake_instance_name' - fake_rx_bytes = 1000 - fake_tx_bytes = 2000 + fake_rx_mb = 1000 + fake_tx_mb = 2000 fake_element_name = 'fake_element_name' fake_address = 'fake_address' self._inspector._utils.get_vnic_metrics.return_value = [{ - 'rx_bytes': fake_rx_bytes, - 'tx_bytes': fake_tx_bytes, + 'rx_mb': fake_rx_mb, + 'tx_mb': fake_tx_mb, 'element_name': fake_element_name, 'address': fake_address}] @@ -91,8 +92,8 @@ class TestHyperVInspection(test.BaseTestCase): self.assertEqual(fake_element_name, inspected_vnic.name) self.assertEqual(fake_address, inspected_vnic.mac) - self.assertEqual(fake_rx_bytes, inspected_stats.rx_bytes) - self.assertEqual(fake_tx_bytes, inspected_stats.tx_bytes) + self.assertEqual(fake_rx_mb * units.Mi, inspected_stats.rx_bytes) + self.assertEqual(fake_tx_mb * units.Mi, inspected_stats.tx_bytes) def test_inspect_disks(self): fake_instance_name = 'fake_instance_name' @@ -120,5 +121,5 @@ class TestHyperVInspection(test.BaseTestCase): self.assertEqual(fake_device, inspected_disk.device) - self.assertEqual(fake_read_mb * 1024, inspected_stats.read_bytes) - self.assertEqual(fake_write_mb * 1024, inspected_stats.write_bytes) + self.assertEqual(fake_read_mb * units.Mi, inspected_stats.read_bytes) + self.assertEqual(fake_write_mb * units.Mi, inspected_stats.write_bytes) diff --git a/ceilometer/tests/compute/virt/hyperv/test_utilsv2.py b/ceilometer/tests/compute/virt/hyperv/test_utilsv2.py index bb7ccea09..458a11c29 100644 --- a/ceilometer/tests/compute/virt/hyperv/test_utilsv2.py +++ b/ceilometer/tests/compute/virt/hyperv/test_utilsv2.py @@ -94,8 +94,8 @@ class TestUtilsV2(test.BaseTestCase): fake_vnic_element_name = "fake_vnic_name" fake_vnic_address = "fake_vnic_address" fake_vnic_path = "fake_vnic_path" - fake_rx_bytes = 1000 - fake_tx_bytes = 2000 + fake_rx_mb = 1000 + fake_tx_mb = 2000 self._utils._lookup_vm = mock.MagicMock() self._utils._get_vm_resources = mock.MagicMock() @@ -112,13 +112,13 @@ class TestUtilsV2(test.BaseTestCase): self._utils._get_metric_def = mock.MagicMock() - mock_get_by_defs.return_value = [fake_rx_bytes, fake_tx_bytes] + mock_get_by_defs.return_value = [fake_rx_mb, fake_tx_mb] vnic_metrics = list(self._utils.get_vnic_metrics(fake_vm_element_name)) self.assertEqual(1, len(vnic_metrics)) - self.assertEqual(fake_rx_bytes, vnic_metrics[0]['rx_bytes']) - self.assertEqual(fake_tx_bytes, vnic_metrics[0]['tx_bytes']) + self.assertEqual(fake_rx_mb, vnic_metrics[0]['rx_mb']) + self.assertEqual(fake_tx_mb, vnic_metrics[0]['tx_mb']) self.assertEqual(fake_vnic_element_name, vnic_metrics[0]['element_name']) self.assertEqual(fake_vnic_address, vnic_metrics[0]['address'])