capabilities flattened and tests fixed

This commit is contained in:
Sandy Walsh
2011-05-09 09:08:56 -07:00
parent b4a8e09764
commit cf65ae85a9
3 changed files with 27 additions and 27 deletions

View File

@@ -96,8 +96,8 @@ class FlavorFilter(HostFilter):
selected_hosts = []
for host, services in zone_manager.service_states.iteritems():
capabilities = services.get('compute', {})
host_ram_mb = capabilities['host_memory']['free']
disk_bytes = capabilities['disk']['available']
host_ram_mb = capabilities['host_memory_free']
disk_bytes = capabilities['disk_available']
if host_ram_mb >= instance_type['memory_mb'] and \
disk_bytes >= instance_type['local_gb']:
selected_hosts.append((host, capabilities))
@@ -106,10 +106,10 @@ class FlavorFilter(HostFilter):
#host entries (currently) are like:
# {'host_name-description': 'Default install of XenServer',
# 'host_hostname': 'xs-mini',
# 'host_memory': {'total': 8244539392,
# 'overhead': 184225792,
# 'free': 3868327936,
# 'free-computed': 3840843776},
# 'host_memory_total': 8244539392,
# 'host_memory_overhead': 184225792,
# 'host_memory_free': 3868327936,
# 'host_memory_free-computed': 3840843776},
# 'host_other-config': {},
# 'host_ip_address': '192.168.1.109',
# 'host_cpu_info': {},
@@ -221,8 +221,8 @@ class JsonFilter(HostFilter):
required_ram = instance_type['memory_mb']
required_disk = instance_type['local_gb']
query = ['and',
['>=', '$compute.host_memory.free', required_ram],
['>=', '$compute.disk.available', required_disk]
['>=', '$compute.host_memory_free', required_ram],
['>=', '$compute.disk_available', required_disk]
]
return (self._full_name(), json.dumps(query))

View File

@@ -43,16 +43,16 @@ class HostFilterTestCase(test.TestCase):
# which means ... don't go above 10 hosts.
return {'host_name-description': 'XenServer %s' % multiplier,
'host_hostname': 'xs-%s' % multiplier,
'host_memory': {'total': 100,
'overhead': 10,
'free': 10 + multiplier * 10,
'free-computed': 10 + multiplier * 10},
'host_memory_total': 100,
'host_memory_overhead': 10,
'host_memory_free': 10 + multiplier * 10,
'host_memory_free-computed': 10 + multiplier * 10,
'host_other-config': {},
'host_ip_address': '192.168.1.%d' % (100 + multiplier),
'host_cpu_info': {},
'disk': {'available': 100 + multiplier * 100,
'total': 1000,
'used': 0},
'disk_available': 100 + multiplier * 100,
'disk_total': 1000,
'disk_used': 0,
'host_uuid': 'xxx-%d' % multiplier,
'host_name-label': 'xs-%s' % multiplier}
@@ -131,12 +131,12 @@ class HostFilterTestCase(test.TestCase):
raw = ['or',
['and',
['<', '$compute.host_memory.free', 30],
['<', '$compute.disk.available', 300]
['<', '$compute.host_memory_free', 30],
['<', '$compute.disk_available', 300]
],
['and',
['>', '$compute.host_memory.free', 70],
['>', '$compute.disk.available', 700]
['>', '$compute.host_memory_free', 70],
['>', '$compute.disk_available', 700]
]
]
cooked = json.dumps(raw)
@@ -149,7 +149,7 @@ class HostFilterTestCase(test.TestCase):
self.assertEquals('host%02d' % index, host)
raw = ['not',
['=', '$compute.host_memory.free', 30],
['=', '$compute.host_memory_free', 30],
]
cooked = json.dumps(raw)
hosts = driver.filter_hosts(self.zone_manager, cooked)
@@ -160,7 +160,7 @@ class HostFilterTestCase(test.TestCase):
for index, host in zip([1, 2, 4, 5, 6, 7, 8, 9, 10], just_hosts):
self.assertEquals('host%02d' % index, host)
raw = ['in', '$compute.host_memory.free', 20, 40, 60, 80, 100]
raw = ['in', '$compute.host_memory_free', 20, 40, 60, 80, 100]
cooked = json.dumps(raw)
hosts = driver.filter_hosts(self.zone_manager, cooked)

View File

@@ -709,9 +709,9 @@ class HostStateTestCase(test.TestCase):
self.stubs.Set(vm_utils, 'safe_find_sr', self._fake_safe_find_sr)
host_state = xenapi_conn.HostState(FakeSession())
stats = host_state._stats
self.assertEquals('disk_total', 10000)
self.assertEquals('disk_used', 20000)
self.assertEquals('host_memory_total', 10)
self.assertEquals('host_memory_overhead', 20)
self.assertEquals('host_memory_free', 30)
self.assertEquals('host_memory_free-computed', 40)
self.assertEquals(stats['disk_total'], 10000)
self.assertEquals(stats['disk_used'], 20000)
self.assertEquals(stats['host_memory_total'], 10)
self.assertEquals(stats['host_memory_overhead'], 20)
self.assertEquals(stats['host_memory_free'], 30)
self.assertEquals(stats['host_memory_free-computed'], 40)