From 4e3616b562647ea140f6f67d1bf888f562b4b6d7 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 29 Oct 2018 12:55:03 -0400 Subject: [PATCH] No longer call _normalize_inventory_from_cn_obj from upt flow With change I72c83a95dabd581998470edb9543079acb6536a5 we no longer have a need to call _normalize_inventory_from_cn_obj for in-tree drivers that implement the update_provider_tree() interface. That change also documented the expectation on the upt interface that virt drivers should report allocation ratios and reserved amounts if necessary, like the libvirt driver does with config option values. This change removes the call to _normalize_inventory_from_cn_obj from the ResourceTracker when the virt driver implements the update_provider_tree() method. Change-Id: Ib3591f583453d98245382be0f7a04b6195d67106 Related-Bug: #1799727 --- nova/compute/resource_tracker.py | 11 --------- .../unit/compute/test_resource_tracker.py | 24 +++++++------------ 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/nova/compute/resource_tracker.py b/nova/compute/resource_tracker.py index e9a5ce06c40b..16acaf04e2fe 100644 --- a/nova/compute/resource_tracker.py +++ b/nova/compute/resource_tracker.py @@ -939,17 +939,6 @@ class ResourceTracker(object): self.driver.update_provider_tree(prov_tree, nodename, allocations=allocs) - # We need to normalize inventory data for the compute node provider - # (inject allocation ratio and reserved amounts from the - # compute_node record if not set by the virt driver) because the - # virt driver does not and will not have access to the compute_node - inv_data = prov_tree.data(nodename).inventory - # TODO(mriedem): Stop calling _normalize_inventory_from_cn_obj when - # a virt driver implements update_provider_tree() since we expect - # the driver to manage the allocation ratios and reserved resource - # amounts. - _normalize_inventory_from_cn_obj(inv_data, compute_node) - prov_tree.update_inventory(nodename, inv_data) # Flush any changes. If we processed ReshapeNeeded above, allocs is # not None, and this will hit placement's POST /reshaper route. reportclient.update_from_provider_tree(context, prov_tree, diff --git a/nova/tests/unit/compute/test_resource_tracker.py b/nova/tests/unit/compute/test_resource_tracker.py index 7b7853d42e21..05fa195c4c2e 100644 --- a/nova/tests/unit/compute/test_resource_tracker.py +++ b/nova/tests/unit/compute/test_resource_tracker.py @@ -1412,18 +1412,24 @@ class TestUpdateComputeNode(BaseTestCase): 'min_unit': 1, 'max_unit': 2, 'step_size': 1, + 'allocation_ratio': 16.0, + 'reserved': 1, }, rc_fields.ResourceClass.MEMORY_MB: { 'total': 4096, 'min_unit': 1, 'max_unit': 4096, 'step_size': 1, + 'allocation_ratio': 1.5, + 'reserved': 512, }, rc_fields.ResourceClass.DISK_GB: { 'total': 500, 'min_unit': 1, 'max_unit': 500, 'step_size': 1, + 'allocation_ratio': 1.0, + 'reserved': 1, }, } @@ -1431,24 +1437,13 @@ class TestUpdateComputeNode(BaseTestCase): self.assertIsNone(allocations) ptree.update_inventory(nodename, fake_inv) - # These will get set on ptree by _normalize_inventory_from_cn_obj - self.flags(reserved_host_disk_mb=1024, - reserved_host_memory_mb=512, - reserved_host_cpus=1) - self._setup_rt() # Emulate a driver that has implemented the update_from_provider_tree() # virt driver method self.driver_mock.update_provider_tree.side_effect = fake_upt - orig_compute = _COMPUTE_NODE_FIXTURES[0].obj_clone() - # TODO(efried): These are being overwritten to 0.0 on the global - # somewhere else in this module. Find and fix that, and remove these: - orig_compute.cpu_allocation_ratio = 16.0 - orig_compute.ram_allocation_ratio = 1.5 - orig_compute.disk_allocation_ratio = 1.0 - + orig_compute = _COMPUTE_NODE_FIXTURES[0].obj_clone() # self.rt.compute_nodes[_NODENAME] = orig_compute self.rt.old_resources[_NODENAME] = orig_compute @@ -1474,14 +1469,11 @@ class TestUpdateComputeNode(BaseTestCase): mock.sentinel.ctx, ptree, allocations=None) self.sched_client_mock.update_compute_node.assert_not_called() self.sched_client_mock.set_inventory_for_provider.assert_not_called() - # _normalize_inventory_from_cn_obj should have set allocation ratios - # and reserved values exp_inv = copy.deepcopy(fake_inv) - # These ratios come from the compute node fixture + # These ratios and reserved amounts come from fake_upt exp_inv[rc_fields.ResourceClass.VCPU]['allocation_ratio'] = 16.0 exp_inv[rc_fields.ResourceClass.MEMORY_MB]['allocation_ratio'] = 1.5 exp_inv[rc_fields.ResourceClass.DISK_GB]['allocation_ratio'] = 1.0 - # and these come from the conf values set above exp_inv[rc_fields.ResourceClass.VCPU]['reserved'] = 1 exp_inv[rc_fields.ResourceClass.MEMORY_MB]['reserved'] = 512 # 1024MB in GB