From c60cc14bfc34175b8232bc0af4d2cebbc3e8ded4 Mon Sep 17 00:00:00 2001 From: Brian Elliott Date: Mon, 10 Dec 2012 20:49:06 +0000 Subject: [PATCH] Add accounting for orphans to resource tracker. Add accounting for orphaned instances to resource tracker. Orphans are instances that, for whatever reason, exist on the hypervisor but are not accounted for in the Nova DB. Such instances would cause resource tracker to under-report usage numbers and result in out of memory errors during build. Change-Id: Icc970e34e01ff8c7dfb000889e5ea6e2d0421c77 --- nova/tests/test_xenapi.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index c49664aa..f2799b8f 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -1016,6 +1016,33 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): pass self.assertTrue(was['called']) + def test_per_instance_usage_running(self): + instance = self._create_instance(spawn=True) + instance_type = instance_types.get_instance_type(3) + + expected = {instance['uuid']: {'memory_mb': instance_type['memory_mb'], + 'uuid': instance['uuid']}} + actual = self.conn.get_per_instance_usage() + self.assertEqual(expected, actual) + + # Paused instances still consume resources: + self.conn.pause(instance) + actual = self.conn.get_per_instance_usage() + self.assertEqual(expected, actual) + + def test_per_instance_usage_suspended(self): + # Suspended instances do not consume memory: + instance = self._create_instance(spawn=True) + self.conn.suspend(instance) + actual = self.conn.get_per_instance_usage() + self.assertEqual({}, actual) + + def test_per_instance_usage_halted(self): + instance = self._create_instance(spawn=True) + self.conn.power_off(instance) + actual = self.conn.get_per_instance_usage() + self.assertEqual({}, actual) + def _create_instance(self, instance_id=1, spawn=True): """Creates and spawns a test instance.""" instance_values = {