diff --git a/neat/globals/manager.py b/neat/globals/manager.py index 2b7553f..2c65029 100644 --- a/neat/globals/manager.py +++ b/neat/globals/manager.py @@ -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 diff --git a/tests/globals/test_manager.py b/tests/globals/test_manager.py index f792215..7614f65 100644 --- a/tests/globals/test_manager.py +++ b/tests/globals/test_manager.py @@ -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')