Fixed host_used_ram to return the max RAM used by the VMs

This commit is contained in:
Anton Beloglazov 2012-10-08 16:33:31 +11:00
parent 4c64408cac
commit f9104a0bef
2 changed files with 18 additions and 1 deletions

View File

@ -407,7 +407,10 @@ def host_used_ram(nova, host):
:return: The used RAM of the host.
:rtype: int
"""
return nova.hosts.get(host)[1].memory_mb
data = nova.hosts.get(host)
if len(data) > 2 and data[2].memory_mb != 0:
return data[2].memory_mb
return data[1].memory_mb
@contract

View File

@ -261,6 +261,20 @@ class GlobalManager(TestCase):
and_return([host1, host2]).once()
assert manager.host_used_ram(nova, hostname) == 3000
with MockTransaction:
hostname = 'hosthost'
nova = mock('nova')
nova.hosts = mock('hosts')
host1 = mock('host1')
host1.memory_mb = 4000
host2 = mock('host2')
host2.memory_mb = 3000
host3 = mock('host3')
host3.memory_mb = 3500
expect(nova.hosts).get(hostname). \
and_return([host1, host2, host3]).once()
assert manager.host_used_ram(nova, hostname) == 3500
def test_flavors_ram(self):
with MockTransaction:
nova = mock('nova')