Updated vm_mhz_to_percentage, return [0] if there are no VMs - the host is idle

This commit is contained in:
Anton Beloglazov 2012-10-24 14:19:13 +11:00
parent 222cb18e02
commit ad07469551
2 changed files with 9 additions and 0 deletions

View File

@ -431,6 +431,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)
"""
if not vm_mhz_history:
return [0.]
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:]

View File

@ -196,3 +196,9 @@ class LocalManager(TestCase):
3000),
[0.1, 0.2, 0.2, 0.5])
self.assertEqual(manager.vm_mhz_to_percentage(
[],
[300, 0, 300, 0, 300],
3000),
[0.])