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.

Conflicts:
      nova/compute/resource_tracker.py

NOTE(mriedem): The conflict is due to change
I6827137f35c0cb4f9fc4c6f753d9a035326ed01b not being in Newton.

Change-Id: I25ba6f7f4e4fab6db223368427d889d6b06a77e8
Closes-Bug: #1698383
(cherry picked from commit 0ddf3ce011)
(cherry picked from commit 3284851437)
This commit is contained in:
Dan Smith 2017-06-16 07:25:40 -07:00 committed by Matt Riedemann
parent 9d299ae50e
commit d8b30c3772
2 changed files with 21 additions and 2 deletions

View File

@ -902,8 +902,6 @@ class ResourceTracker(object):
self.scheduler_client.reportclient.remove_deleted_instances(
self.compute_node, self.tracked_instances.values())
self.compute_node.free_ram_mb = max(0, self.compute_node.free_ram_mb)
self.compute_node.free_disk_gb = max(0, self.compute_node.free_disk_gb)
def _find_orphaned_instances(self):
"""Given the set of instances and migrations already account for

View File

@ -2134,6 +2134,27 @@ class TestUpdateUsageFromInstance(BaseTestCase):
mock_update_usage.assert_called_once_with(
self.rt._get_usage_dict(self.instance), sign=-1)
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,
hypervisor_hostname='foo')
self.rt.compute_node = cn
@mock.patch.object(self.sched_client_mock.reportclient,
'remove_deleted_instances')
@mock.patch.object(self.rt, '_update_usage_from_instance')
def test(uufi, rdia):
self.rt._update_usage_from_instances('ctxt', [])
test()
self.assertEqual(-1024, cn.free_ram_mb)
self.assertEqual(-1, cn.free_disk_gb)
class TestInstanceInResizeState(test.NoDBTestCase):
def test_active_suspending(self):