Fix error if free_disk_gb is None in CellStateManager

The field 'free_disk_gb' in Objects.ComputeNode can be nullable.
In CellStateManager._get_compute_hosts, we compute free_disk_mb
by 'free_disk_gb * 1024'. If the free_disk_gb is None, it will raise
a TypeError exception because None type can't multiply by an integer.
We should check this value, and if it's None, we just let it return
zero.

Closes-Bug: #1648983

Change-Id: I558d544ff838807c1d605cb5ed8d0e0fa97ab00e
This commit is contained in:
int32bit 2016-12-11 15:08:45 +08:00
parent 6d486ffe46
commit 58bf5d0053
1 changed files with 2 additions and 4 deletions

View File

@ -276,11 +276,9 @@ class CellStateManager(base.Base):
chost = compute_hosts[host]
chost['free_ram_mb'] += max(0, compute.free_ram_mb)
free_disk = compute.free_disk_gb * 1024
chost['free_disk_mb'] += max(0, free_disk)
chost['free_disk_mb'] += max(0, compute.free_disk_gb) * 1024
chost['total_ram_mb'] += max(0, compute.memory_mb)
total_disk = compute.local_gb * 1024
chost['total_disk_mb'] += max(0, total_disk)
chost['total_disk_mb'] += max(0, compute.local_gb) * 1024
_get_compute_hosts()
if not compute_hosts: