Fixed vm_mhz_to_percentage to correctly handle 0 filling
This commit is contained in:
parent
269ce0c065
commit
010e416d3c
@ -410,8 +410,9 @@ def vm_mhz_to_percentage(vm_mhz_history, host_mhz_history, physical_cpu_mhz):
|
||||
:return: The history of the host's CPU utilization in percentages.
|
||||
:rtype: list(float)
|
||||
"""
|
||||
host_mhz_history = [0] * (len(vm_mhz_history) -
|
||||
len(host_mhz_history)) + host_mhz_history
|
||||
data = itertools.izip_longest(*(vm_mhz_history + [host_mhz_history]),
|
||||
fillvalue=0)
|
||||
return [float(sum(x)) / physical_cpu_mhz for x in data]
|
||||
max_len = max(len(x) for x in vm_mhz_history)
|
||||
if len(host_mhz_history) > max_len:
|
||||
host_mhz_history = host_mhz_history[-max_len:]
|
||||
mhz_history = [[0] * (max_len - len(x)) + x
|
||||
for x in vm_mhz_history + [host_mhz_history]]
|
||||
return [float(sum(x)) / physical_cpu_mhz for x in zip(*mhz_history)]
|
||||
|
@ -161,11 +161,11 @@ class LocalManager(TestCase):
|
||||
def test_vm_mhz_to_percentage(self):
|
||||
self.assertEqual(manager.vm_mhz_to_percentage(
|
||||
[[100, 200, 300],
|
||||
[100, 300, 200],
|
||||
[300, 100, 300, 200],
|
||||
[100, 100, 700]],
|
||||
[300, 0, 300],
|
||||
3000),
|
||||
[0.2, 0.2, 0.5])
|
||||
[0.1, 0.2, 0.2, 0.5])
|
||||
|
||||
self.assertEqual(manager.vm_mhz_to_percentage(
|
||||
[[100, 200, 300],
|
||||
@ -174,3 +174,12 @@ class LocalManager(TestCase):
|
||||
[0, 300],
|
||||
3000),
|
||||
[0.1, 0.2, 0.5])
|
||||
|
||||
self.assertEqual(manager.vm_mhz_to_percentage(
|
||||
[[100, 200, 300],
|
||||
[300, 100, 300, 200],
|
||||
[100, 100, 700]],
|
||||
[300, 0, 300, 0, 300],
|
||||
3000),
|
||||
[0.1, 0.2, 0.2, 0.5])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user