Merge "Do not post allocations that are zero"

This commit is contained in:
Jenkins 2017-01-04 22:50:17 +00:00 committed by Gerrit Code Review
commit 1bcf3b553a
2 changed files with 20 additions and 1 deletions

View File

@ -114,11 +114,13 @@ def _instance_to_allocations_dict(instance):
disk = ((0 if is_bfv else instance.flavor.root_gb) +
instance.flavor.swap +
instance.flavor.ephemeral_gb)
return {
alloc_dict = {
MEMORY_MB: instance.flavor.memory_mb,
VCPU: instance.flavor.vcpus,
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):

View File

@ -928,6 +928,23 @@ class TestAllocations(SchedulerReportClientTestCase):
}
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.'
'put')
@mock.patch('nova.scheduler.client.report.SchedulerReportClient.'