summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-16 17:24:20 +0000
committerGerrit Code Review <review@openstack.org>2017-06-16 17:24:20 +0000
commit3e732d332a26ec168c378714d65280cd77b32b28 (patch)
treed8ef0e32131c60036eba5e05d4fae64ff4e7bd03
parent8238e8aaa0103e96ddb67ad178ed9848e9071ea6 (diff)
parent0ddf3ce01149d78ee0cf8f7497f8a9074c6f167d (diff)
Merge "Fix regression preventing reporting negative resources for overcommit"
-rw-r--r--nova/compute/resource_tracker.py3
-rw-r--r--nova/tests/unit/compute/test_resource_tracker.py20
2 files changed, 20 insertions, 3 deletions
diff --git a/nova/compute/resource_tracker.py b/nova/compute/resource_tracker.py
index 28e5848..fe37520 100644
--- a/nova/compute/resource_tracker.py
+++ b/nova/compute/resource_tracker.py
@@ -1046,9 +1046,6 @@ class ResourceTracker(object):
1046 # Remove allocations for instances that have been removed. 1046 # Remove allocations for instances that have been removed.
1047 self._remove_deleted_instances_allocations(context, cn) 1047 self._remove_deleted_instances_allocations(context, cn)
1048 1048
1049 cn.free_ram_mb = max(0, cn.free_ram_mb)
1050 cn.free_disk_gb = max(0, cn.free_disk_gb)
1051
1052 def _remove_deleted_instances_allocations(self, context, cn): 1049 def _remove_deleted_instances_allocations(self, context, cn):
1053 tracked_keys = set(self.tracked_instances.keys()) 1050 tracked_keys = set(self.tracked_instances.keys())
1054 allocations = self.reportclient.get_allocations_for_resource_provider( 1051 allocations = self.reportclient.get_allocations_for_resource_provider(
diff --git a/nova/tests/unit/compute/test_resource_tracker.py b/nova/tests/unit/compute/test_resource_tracker.py
index 48e5a19..14cf0a6 100644
--- a/nova/tests/unit/compute/test_resource_tracker.py
+++ b/nova/tests/unit/compute/test_resource_tracker.py
@@ -2472,6 +2472,26 @@ class TestUpdateUsageFromInstance(BaseTestCase):
2472 # instance that no longer exists. 2472 # instance that no longer exists.
2473 rc.delete_allocation_for_instance.assert_called_once_with(uuids.inst0) 2473 rc.delete_allocation_for_instance.assert_called_once_with(uuids.inst0)
2474 2474
2475 def test_update_usage_from_instances_goes_negative(self):
2476 # NOTE(danms): The resource tracker _should_ report negative resources
2477 # for things like free_ram_mb if overcommit is being used. This test
2478 # ensures that we don't collapse negative values to zero.
2479 self.flags(reserved_host_memory_mb=2048)
2480 self.flags(reserved_host_disk_mb=(11 * 1024))
2481 cn = objects.ComputeNode(memory_mb=1024, local_gb=10)
2482 self.rt.compute_nodes['foo'] = cn
2483
2484 @mock.patch.object(self.rt,
2485 '_remove_deleted_instances_allocations')
2486 @mock.patch.object(self.rt, '_update_usage_from_instance')
2487 def test(uufi, rdia):
2488 self.rt._update_usage_from_instances('ctxt', [], 'foo')
2489
2490 test()
2491
2492 self.assertEqual(-1024, cn.free_ram_mb)
2493 self.assertEqual(-1, cn.free_disk_gb)
2494
2475 2495
2476class TestInstanceInResizeState(test.NoDBTestCase): 2496class TestInstanceInResizeState(test.NoDBTestCase):
2477 def test_active_suspending(self): 2497 def test_active_suspending(self):