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 016b810f67 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 047da6498d.
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.

Change-Id: I25ba6f7f4e4fab6db223368427d889d6b06a77e8
Closes-Bug: #1698383
This commit is contained in:
Dan Smith 2017-06-16 07:25:40 -07:00
parent a43dbba2b8
commit 0ddf3ce011
2 changed files with 20 additions and 3 deletions

View File

@ -1046,9 +1046,6 @@ class ResourceTracker(object):
# Remove allocations for instances that have been removed.
self._remove_deleted_instances_allocations(context, cn)
cn.free_ram_mb = max(0, cn.free_ram_mb)
cn.free_disk_gb = max(0, cn.free_disk_gb)
def _remove_deleted_instances_allocations(self, context, cn):
tracked_keys = set(self.tracked_instances.keys())
allocations = self.reportclient.get_allocations_for_resource_provider(

View File

@ -2472,6 +2472,26 @@ class TestUpdateUsageFromInstance(BaseTestCase):
# instance that no longer exists.
rc.delete_allocation_for_instance.assert_called_once_with(uuids.inst0)
def test_update_usage_from_instances_goes_negative(self):
# NOTE(danms): The resource tracker _should_ report negative resources
# for things like free_ram_mb if overcommit is being used. This test
# ensures that we don't collapse negative values to zero.
self.flags(reserved_host_memory_mb=2048)
self.flags(reserved_host_disk_mb=(11 * 1024))
cn = objects.ComputeNode(memory_mb=1024, local_gb=10)
self.rt.compute_nodes['foo'] = cn
@mock.patch.object(self.rt,
'_remove_deleted_instances_allocations')
@mock.patch.object(self.rt, '_update_usage_from_instance')
def test(uufi, rdia):
self.rt._update_usage_from_instances('ctxt', [], 'foo')
test()
self.assertEqual(-1024, cn.free_ram_mb)
self.assertEqual(-1, cn.free_disk_gb)
class TestInstanceInResizeState(test.NoDBTestCase):
def test_active_suspending(self):