diff options
authorDan Smith <>2017-06-16 07:25:40 -0700
committerMatt Riedemann <>2017-06-16 13:49:52 -0400
commit3284851437e24250d46edba20789a2e5f1f435a0 (patch)
parentfe329029265e10296a550fc9153b7977da4aefe2 (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/ nova/tests/unit/compute/ NOTE(mriedem): The conflict is due to change I80ba844a6e0fcea89f80aa253d57ac73092773ae not being in Ocata. Change-Id: I25ba6f7f4e4fab6db223368427d889d6b06a77e8 Closes-Bug: #1698383 (cherry picked from commit 0ddf3ce01149d78ee0cf8f7497f8a9074c6f167d)
Notes (review): Code-Review+2: Sean Dague <> Code-Review+2: Dan Smith <> Workflow+1: Dan Smith <> Code-Review+1: Erik Olof Gunnar Andersson <> Verified+1: IBM PowerKVM CI <> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Fri, 16 Jun 2017 20:32:56 +0000 Reviewed-on: Project: openstack/nova Branch: refs/heads/stable/ocata
2 files changed, 20 insertions, 2 deletions
diff --git a/nova/compute/ b/nova/compute/
index 7d1c94e..1bad396 100644
--- a/nova/compute/
+++ b/nova/compute/
@@ -954,8 +954,6 @@ class ResourceTracker(object):
954 954
955 self.scheduler_client.reportclient.remove_deleted_instances( 955 self.scheduler_client.reportclient.remove_deleted_instances(
956 cn, self.tracked_instances.values()) 956 cn, self.tracked_instances.values())
957 cn.free_ram_mb = max(0, cn.free_ram_mb)
958 cn.free_disk_gb = max(0, cn.free_disk_gb)
959 957
960 def _find_orphaned_instances(self): 958 def _find_orphaned_instances(self):
961 """Given the set of instances and migrations already account for 959 """Given the set of instances and migrations already account for
diff --git a/nova/tests/unit/compute/ b/nova/tests/unit/compute/
index 51a5647..f0bc9bb 100644
--- a/nova/tests/unit/compute/
+++ b/nova/tests/unit/compute/
@@ -2170,6 +2170,26 @@ class TestUpdateUsageFromInstance(BaseTestCase):
2170 mock_update_usage.assert_called_once_with( 2170 mock_update_usage.assert_called_once_with(
2171 self.rt._get_usage_dict(self.instance), _NODENAME, sign=-1) 2171 self.rt._get_usage_dict(self.instance), _NODENAME, sign=-1)
2172 2172
2173 def test_update_usage_from_instances_goes_negative(self):
2174 # NOTE(danms): The resource tracker _should_ report negative resources
2175 # for things like free_ram_mb if overcommit is being used. This test
2176 # ensures that we don't collapse negative values to zero.
2177 self.flags(reserved_host_memory_mb=2048)
2178 self.flags(reserved_host_disk_mb=(11 * 1024))
2179 cn = objects.ComputeNode(memory_mb=1024, local_gb=10)
2180 self.rt.compute_nodes['foo'] = cn
2182 @mock.patch.object(self.sched_client_mock.reportclient,
2183 'remove_deleted_instances')
2184 @mock.patch.object(self.rt, '_update_usage_from_instance')
2185 def test(uufi, rdia):
2186 self.rt._update_usage_from_instances('ctxt', [], 'foo')
2188 test()
2190 self.assertEqual(-1024, cn.free_ram_mb)
2191 self.assertEqual(-1, cn.free_disk_gb)
2173 2193
2174class TestInstanceInResizeState(test.NoDBTestCase): 2194class TestInstanceInResizeState(test.NoDBTestCase):
2175 def test_active_suspending(self): 2195 def test_active_suspending(self):