Don't allow compute_node free_disk_gb to be None

As part of commit 5668870, we now explicitly guard against the case
free_disk_gb is None or unset. However, this should never happen
since resource tracker always sets it and guarding against this case
isn't actually needed to fix the bug in question.

Also, simplify the code a little to make the intent more clear. We
assume that free_disk_gb is always set, but we want to use
disk_available_least where the driver has set it. The case where
disk_available_least is less than free_disk_gb is the exceptional
case we want to guard against.

Change-Id: I3973eab6b4ca016df546de8b57245fc0d0f03a80
This commit is contained in:
Mark McLoughlin
2014-02-13 10:41:28 +00:00
parent 5668870713
commit 6aa36ab382
2 changed files with 14 additions and 14 deletions
+9 -9
View File
@@ -183,16 +183,16 @@ class HostState(object):
all_ram_mb = compute['memory_mb']
# Assume virtual size is all consumed by instances if use qcow2 disk.
free_gb = compute.get('free_disk_gb')
free_gb = compute['free_disk_gb']
least_gb = compute.get('disk_available_least')
if least_gb > free_gb and free_gb:
# can occur when an instance in database is not on host
LOG.warn(_("Host has more disk space than database expected"
" (%(physical)sgb > %(database)sgb)") %
{'physical': least_gb, 'database': free_gb})
free_disk_mb = min(val for val in [least_gb,
free_gb] if val is not None)
free_disk_mb *= 1024
if least_gb is not None:
if least_gb > free_gb:
# can occur when an instance in database is not on host
LOG.warn(_("Host has more disk space than database expected"
" (%(physical)sgb > %(database)sgb)") %
{'physical': least_gb, 'database': free_gb})
free_gb = min(least_gb, free_gb)
free_disk_mb = free_gb * 1024
self.disk_mb_used = compute['local_gb_used'] * 1024
+5 -5
View File
@@ -34,7 +34,7 @@ COMPUTE_NODES = [
hypervisor_version=0),
dict(id=2, local_gb=2048, memory_mb=2048, vcpus=2,
disk_available_least=1024, free_ram_mb=1024, vcpus_used=2,
free_disk_gb=None, local_gb_used=0, updated_at=None,
free_disk_gb=1024, local_gb_used=0, updated_at=None,
service=dict(host='host2', disabled=True),
hypervisor_hostname='node2', host_ip='127.0.0.1',
hypervisor_version=0),
@@ -57,7 +57,7 @@ COMPUTE_NODES = [
COMPUTE_NODES_METRICS = [
dict(id=1, local_gb=1024, memory_mb=1024, vcpus=1,
disk_available_least=512, free_ram_mb=512, vcpus_used=1,
free_disk_mb=512, local_gb_used=0, updated_at=None,
free_disk_gb=512, local_gb_used=0, updated_at=None,
service=dict(host='host1', disabled=False),
hypervisor_hostname='node1', host_ip='127.0.0.1',
hypervisor_version=0,
@@ -74,7 +74,7 @@ COMPUTE_NODES_METRICS = [
])),
dict(id=2, local_gb=2048, memory_mb=2048, vcpus=2,
disk_available_least=1024, free_ram_mb=1024, vcpus_used=2,
free_disk_mb=1024, local_gb_used=0, updated_at=None,
free_disk_gb=1024, local_gb_used=0, updated_at=None,
service=dict(host='host2', disabled=True),
hypervisor_hostname='node2', host_ip='127.0.0.1',
hypervisor_version=0,
@@ -91,7 +91,7 @@ COMPUTE_NODES_METRICS = [
])),
dict(id=3, local_gb=4096, memory_mb=4096, vcpus=4,
disk_available_least=3072, free_ram_mb=3072, vcpus_used=1,
free_disk_mb=3072, local_gb_used=0, updated_at=None,
free_disk_gb=3072, local_gb_used=0, updated_at=None,
service=dict(host='host3', disabled=False),
hypervisor_hostname='node3', host_ip='127.0.0.1',
hypervisor_version=0,
@@ -108,7 +108,7 @@ COMPUTE_NODES_METRICS = [
])),
dict(id=4, local_gb=8192, memory_mb=8192, vcpus=8,
disk_available_least=8192, free_ram_mb=8192, vcpus_used=0,
free_disk_mb=8192, local_gb_used=0, updated_at=None,
free_disk_gb=8192, local_gb_used=0, updated_at=None,
service=dict(host='host4', disabled=False),
hypervisor_hostname='node4', host_ip='127.0.0.1',
hypervisor_version=0,