Merge "Do not post allocations that are zero"
This commit is contained in:
commit
1bcf3b553a
|
@ -114,11 +114,13 @@ def _instance_to_allocations_dict(instance):
|
||||||
disk = ((0 if is_bfv else instance.flavor.root_gb) +
|
disk = ((0 if is_bfv else instance.flavor.root_gb) +
|
||||||
instance.flavor.swap +
|
instance.flavor.swap +
|
||||||
instance.flavor.ephemeral_gb)
|
instance.flavor.ephemeral_gb)
|
||||||
return {
|
alloc_dict = {
|
||||||
MEMORY_MB: instance.flavor.memory_mb,
|
MEMORY_MB: instance.flavor.memory_mb,
|
||||||
VCPU: instance.flavor.vcpus,
|
VCPU: instance.flavor.vcpus,
|
||||||
DISK_GB: disk,
|
DISK_GB: disk,
|
||||||
}
|
}
|
||||||
|
# Remove any zero allocations.
|
||||||
|
return {key: val for key, val in alloc_dict.items() if val}
|
||||||
|
|
||||||
|
|
||||||
def _extract_inventory_in_use(body):
|
def _extract_inventory_in_use(body):
|
||||||
|
|
|
@ -928,6 +928,23 @@ class TestAllocations(SchedulerReportClientTestCase):
|
||||||
}
|
}
|
||||||
self.assertEqual(expected, result)
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
|
@mock.patch('nova.compute.utils.is_volume_backed_instance')
|
||||||
|
def test_instance_to_allocations_dict_zero_disk(self, mock_vbi):
|
||||||
|
mock_vbi.return_value = True
|
||||||
|
inst = objects.Instance(
|
||||||
|
uuid=uuids.inst,
|
||||||
|
flavor=objects.Flavor(root_gb=10,
|
||||||
|
swap=0,
|
||||||
|
ephemeral_gb=0,
|
||||||
|
memory_mb=1024,
|
||||||
|
vcpus=2))
|
||||||
|
result = report._instance_to_allocations_dict(inst)
|
||||||
|
expected = {
|
||||||
|
'MEMORY_MB': 1024,
|
||||||
|
'VCPU': 2,
|
||||||
|
}
|
||||||
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||||
'put')
|
'put')
|
||||||
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'
|
||||||
|
|
Loading…
Reference in New Issue