diff --git a/nova/scheduler/client/report.py b/nova/scheduler/client/report.py index 5acbbd3314ca..be2ac6ae79ed 100644 --- a/nova/scheduler/client/report.py +++ b/nova/scheduler/client/report.py @@ -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): diff --git a/nova/tests/unit/scheduler/client/test_report.py b/nova/tests/unit/scheduler/client/test_report.py index 1c30ee34224a..b60620dbbf0b 100644 --- a/nova/tests/unit/scheduler/client/test_report.py +++ b/nova/tests/unit/scheduler/client/test_report.py @@ -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.'