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
This commit is contained in:
parent
d6f80f25f6
commit
94bfbe53b6
@ -113,7 +113,7 @@ class TestHostCPUStats(test.TestCase):
|
|||||||
def test_update_internal_metric(self, mock_ensure_ltm, mock_refresh,
|
def test_update_internal_metric(self, mock_ensure_ltm, mock_refresh,
|
||||||
mock_cpu_freq):
|
mock_cpu_freq):
|
||||||
host_stats = pvm_host.HostCPUStats(self.adpt, 'host_uuid')
|
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.
|
# Make sure None is returned if there is no data.
|
||||||
host_stats.cur_phyp = None
|
host_stats.cur_phyp = None
|
||||||
@ -128,7 +128,7 @@ class TestHostCPUStats(test.TestCase):
|
|||||||
# Validate the dictionary...
|
# Validate the dictionary...
|
||||||
expect = {'iowait': 0, 'idle': 1.6125096675799704e+16,
|
expect = {'iowait': 0, 'idle': 1.6125096675799704e+16,
|
||||||
'kernel': 58599310268, 'user': 789903553028,
|
'kernel': 58599310268, 'user': 789903553028,
|
||||||
'frequency': 4116.0}
|
'frequency': 4116}
|
||||||
self.assertEqual(expect, host_stats.cur_data)
|
self.assertEqual(expect, host_stats.cur_data)
|
||||||
|
|
||||||
# Now 'increment' it with a new current/previous
|
# 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.
|
# overall, even though we add the 'deltas' from each VM.
|
||||||
expect = {'iowait': 0, 'idle': 1.6125066665694504e+16,
|
expect = {'iowait': 0, 'idle': 1.6125066665694504e+16,
|
||||||
'kernel': 58599310268, 'user': 819913658228,
|
'kernel': 58599310268, 'user': 819913658228,
|
||||||
'frequency': 4116.0}
|
'frequency': 4116}
|
||||||
self.assertEqual(expect, host_stats.cur_data)
|
self.assertEqual(expect, host_stats.cur_data)
|
||||||
|
|
||||||
@mock.patch('subprocess.check_output')
|
@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):
|
def test_get_cpu_freq(self, mock_ensure_ltm, mock_refresh, mock_cmd):
|
||||||
host_stats = pvm_host.HostCPUStats(self.adpt, 'host_uuid')
|
host_stats = pvm_host.HostCPUStats(self.adpt, 'host_uuid')
|
||||||
mock_cmd.return_value = '4116.000000MHz\n'
|
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.MetricCache._refresh_if_needed')
|
||||||
@mock.patch('pypowervm.tasks.monitor.util.ensure_ltm_monitors')
|
@mock.patch('pypowervm.tasks.monitor.util.ensure_ltm_monitors')
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright 2014 IBM Corp.
|
# Copyright 2014, 2015 IBM Corp.
|
||||||
#
|
#
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
@ -214,7 +214,7 @@ class HostCPUStats(pcm_util.MetricCache):
|
|||||||
def _get_cpu_freq():
|
def _get_cpu_freq():
|
||||||
# The output will be similar to '4116.000000MHz' on a POWER system.
|
# The output will be similar to '4116.000000MHz' on a POWER system.
|
||||||
cmd = ['/usr/bin/awk', '/clock/ {print $3; exit}', '/proc/cpuinfo']
|
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):
|
def _delta_proc_cycles(self, samples, prev_samples):
|
||||||
"""Sums all the processor delta cycles for a set of VM/VIOS samples.
|
"""Sums all the processor delta cycles for a set of VM/VIOS samples.
|
||||||
|
Loading…
Reference in New Issue
Block a user