diff options
authorDan Smith <>2017-06-16 07:25:40 -0700
committerMatt Riedemann <>2017-06-16 15:04:11 -0400
commitd8b30c3772dae32ac4cbedb659f6d08eb795425a (patch)
parent9d299ae50ea52c63811eba11ee974643c17079ad (diff)
Fix regression preventing reporting negative resources for overcommit
In Nova prior to Ocata, the scheduler computes available resources for a compute node, attempting to mirror the same calculation that happens locally. It does this to determine if a new instance should fit on the node. If overcommit is being used, some of these numbers can be negative. In change 016b810f675b20e8ce78f4c82dc9c679c0162b7a we changed the compute side to never report negative resources, which was an ironic- specific fix for nodes that are offline. That, however, has been corrected for ironic nodes in 047da6498dbb3af71bcb9e6d0e2c38aa23b06615. Since the base change to the resource tracker has caused the scheduler and compute to do different math, we need to revert it to avoid the scheduler sending instances to nodes where it believes -NNN is the lower limit (with overcommit), but the node is reporting zero. This doesn't actually affect Ocata because of our use of the placement engine. However, this code is still in master and needs to be backported. This part of the change actually didn't even have a unit test, so this patch adds one to validate that the resource tracker will calculate and report negative resources. Conflicts: nova/compute/ NOTE(mriedem): The conflict is due to change I6827137f35c0cb4f9fc4c6f753d9a035326ed01b not being in Newton. Change-Id: I25ba6f7f4e4fab6db223368427d889d6b06a77e8 Closes-Bug: #1698383 (cherry picked from commit 0ddf3ce01149d78ee0cf8f7497f8a9074c6f167d) (cherry picked from commit 3284851437e24250d46edba20789a2e5f1f435a0)
Notes (review): Code-Review+1: Erik Olof Gunnar Andersson <> Code-Review+2: Dan Smith <> Verified+1: IBM PowerKVM CI <> Code-Review+2: Sean Dague <> Workflow+1: Sean Dague <> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Fri, 16 Jun 2017 22:02:30 +0000 Reviewed-on: Project: openstack/nova Branch: refs/heads/stable/newton
2 files changed, 21 insertions, 2 deletions
diff --git a/nova/compute/ b/nova/compute/
index 4436f71..e2bfe4e 100644
--- a/nova/compute/
+++ b/nova/compute/
@@ -902,8 +902,6 @@ class ResourceTracker(object):
902 902
903 self.scheduler_client.reportclient.remove_deleted_instances( 903 self.scheduler_client.reportclient.remove_deleted_instances(
904 self.compute_node, self.tracked_instances.values()) 904 self.compute_node, self.tracked_instances.values())
905 self.compute_node.free_ram_mb = max(0, self.compute_node.free_ram_mb)
906 self.compute_node.free_disk_gb = max(0, self.compute_node.free_disk_gb)
907 905
908 def _find_orphaned_instances(self): 906 def _find_orphaned_instances(self):
909 """Given the set of instances and migrations already account for 907 """Given the set of instances and migrations already account for
diff --git a/nova/tests/unit/compute/ b/nova/tests/unit/compute/
index fcc623e..d3297f9 100644
--- a/nova/tests/unit/compute/
+++ b/nova/tests/unit/compute/
@@ -2134,6 +2134,27 @@ class TestUpdateUsageFromInstance(BaseTestCase):
2134 mock_update_usage.assert_called_once_with( 2134 mock_update_usage.assert_called_once_with(
2135 self.rt._get_usage_dict(self.instance), sign=-1) 2135 self.rt._get_usage_dict(self.instance), sign=-1)
2136 2136
2137 def test_update_usage_from_instances_goes_negative(self):
2138 # NOTE(danms): The resource tracker _should_ report negative resources
2139 # for things like free_ram_mb if overcommit is being used. This test
2140 # ensures that we don't collapse negative values to zero.
2141 self.flags(reserved_host_memory_mb=2048)
2142 self.flags(reserved_host_disk_mb=(11 * 1024))
2143 cn = objects.ComputeNode(memory_mb=1024, local_gb=10,
2144 hypervisor_hostname='foo')
2145 self.rt.compute_node = cn
2147 @mock.patch.object(self.sched_client_mock.reportclient,
2148 'remove_deleted_instances')
2149 @mock.patch.object(self.rt, '_update_usage_from_instance')
2150 def test(uufi, rdia):
2151 self.rt._update_usage_from_instances('ctxt', [])
2153 test()
2155 self.assertEqual(-1024, cn.free_ram_mb)
2156 self.assertEqual(-1, cn.free_disk_gb)
2137 2158
2138class TestInstanceInResizeState(test.NoDBTestCase): 2159class TestInstanceInResizeState(test.NoDBTestCase):
2139 def test_active_suspending(self): 2160 def test_active_suspending(self):