From 94bfbe53b62892740a8e5d088ea928745ccebcf2 Mon Sep 17 00:00:00 2001 From: Joe Cropper Date: Sun, 16 Aug 2015 11:42:14 -0500 Subject: [PATCH] Return CPU frequency as int vs. float The general expectation is that CPU frequency is returned as an int vs. a floating type (e.g., see libvirt) for the driver's host CPU stats. This patch covers that as well as a simple test case assert. Change-Id: Icd47e82c07fc2e9bf8973a7ee3c46886a3021c34 Closes-Bug: 1485341 --- nova_powervm/tests/virt/powervm/test_host.py | 9 +++++---- nova_powervm/virt/powervm/host.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/nova_powervm/tests/virt/powervm/test_host.py b/nova_powervm/tests/virt/powervm/test_host.py index d2dbf330..52c40922 100644 --- a/nova_powervm/tests/virt/powervm/test_host.py +++ b/nova_powervm/tests/virt/powervm/test_host.py @@ -113,7 +113,7 @@ class TestHostCPUStats(test.TestCase): def test_update_internal_metric(self, mock_ensure_ltm, mock_refresh, mock_cpu_freq): host_stats = pvm_host.HostCPUStats(self.adpt, 'host_uuid') - mock_cpu_freq.return_value = 4116.0 + mock_cpu_freq.return_value = 4116 # Make sure None is returned if there is no data. host_stats.cur_phyp = None @@ -128,7 +128,7 @@ class TestHostCPUStats(test.TestCase): # Validate the dictionary... expect = {'iowait': 0, 'idle': 1.6125096675799704e+16, 'kernel': 58599310268, 'user': 789903553028, - 'frequency': 4116.0} + 'frequency': 4116} self.assertEqual(expect, host_stats.cur_data) # Now 'increment' it with a new current/previous @@ -140,7 +140,7 @@ class TestHostCPUStats(test.TestCase): # overall, even though we add the 'deltas' from each VM. expect = {'iowait': 0, 'idle': 1.6125066665694504e+16, 'kernel': 58599310268, 'user': 819913658228, - 'frequency': 4116.0} + 'frequency': 4116} self.assertEqual(expect, host_stats.cur_data) @mock.patch('subprocess.check_output') @@ -149,7 +149,8 @@ class TestHostCPUStats(test.TestCase): def test_get_cpu_freq(self, mock_ensure_ltm, mock_refresh, mock_cmd): host_stats = pvm_host.HostCPUStats(self.adpt, 'host_uuid') mock_cmd.return_value = '4116.000000MHz\n' - self.assertEqual(4116.0, host_stats._get_cpu_freq()) + self.assertEqual(4116, host_stats._get_cpu_freq()) + self.assertEqual(int, type(host_stats._get_cpu_freq())) @mock.patch('pypowervm.tasks.monitor.util.MetricCache._refresh_if_needed') @mock.patch('pypowervm.tasks.monitor.util.ensure_ltm_monitors') diff --git a/nova_powervm/virt/powervm/host.py b/nova_powervm/virt/powervm/host.py index a057aec7..380c5d57 100644 --- a/nova_powervm/virt/powervm/host.py +++ b/nova_powervm/virt/powervm/host.py @@ -1,4 +1,4 @@ -# Copyright 2014 IBM Corp. +# Copyright 2014, 2015 IBM Corp. # # All Rights Reserved. # @@ -214,7 +214,7 @@ class HostCPUStats(pcm_util.MetricCache): def _get_cpu_freq(): # The output will be similar to '4116.000000MHz' on a POWER system. cmd = ['/usr/bin/awk', '/clock/ {print $3; exit}', '/proc/cpuinfo'] - return float(subprocess.check_output(cmd).rstrip("MHz\n")) + return int(float(subprocess.check_output(cmd).rstrip("MHz\n"))) def _delta_proc_cycles(self, samples, prev_samples): """Sums all the processor delta cycles for a set of VM/VIOS samples.