summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Lindgren <hanlind@kth.se>2013-02-27 00:23:47 +0100
committerHans Lindgren <hanlind@kth.se>2013-03-03 14:02:22 +0100
commit58889a08fcce7407366f8aae0c703b4fa0480725 (patch)
tree0691c58701a89080335d5d26b714e651a8e1cd78
parente03a3df8869ad5303aaba0f006c17d0927fa6dab (diff)
downloadnova-58889a08fcce7407366f8aae0c703b4fa0480725.tar.gz
nova-58889a08fcce7407366f8aae0c703b4fa0480725.tar.xz
nova-58889a08fcce7407366f8aae0c703b4fa0480725.zip
Make ComputeManager _running_deleted_instances query by uuid
Reuse existing _get_instances_on_driver method to query driver for running instances. Resolves bug 1129519. Change-Id: I9186b289fadfc4414874b3ba52195e9acfac18b4
-rwxr-xr-xnova/compute/manager.py14
-rw-r--r--nova/tests/compute/test_compute.py28
2 files changed, 16 insertions, 26 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index c875c50e1..48e33da39 100755
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -3674,22 +3674,20 @@ class ComputeManager(manager.SchedulerDependentManager):
def _running_deleted_instances(self, context):
"""Returns a list of instances nova thinks is deleted,
- but the hypervisor thinks is still running. This method
- should be pushed down to the virt layer for efficiency.
+ but the hypervisor thinks is still running.
"""
+ timeout = CONF.running_deleted_instance_timeout
+
def deleted_instance(instance):
- timeout = CONF.running_deleted_instance_timeout
- present = instance['name'] in present_name_labels
- erroneously_running = instance['deleted'] and present
+ erroneously_running = instance['deleted']
old_enough = (not instance['deleted_at'] or
timeutils.is_older_than(instance['deleted_at'],
timeout))
if erroneously_running and old_enough:
return True
return False
- present_name_labels = set(self.driver.list_instances())
- instances = self.conductor_api.instance_get_all_by_host(context,
- self.host)
+
+ instances = self._get_instances_on_driver(context)
return [i for i in instances if deleted_instance(i)]
@contextlib.contextmanager
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index d6c9d23a8..083176a89 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -3039,16 +3039,12 @@ class ComputeTestCase(BaseTestCase):
self.compute.host = instance['host']
- self.mox.StubOutWithMock(self.compute.driver, 'list_instances')
- self.compute.driver.list_instances().AndReturn([instance['name']])
+ self.mox.StubOutWithMock(self.compute, '_get_instances_on_driver')
+ self.compute._get_instances_on_driver(admin_context).AndReturn(
+ [instance])
self.flags(running_deleted_instance_timeout=3600,
running_deleted_instance_action='reap')
- self.mox.StubOutWithMock(self.compute.conductor_api,
- "instance_get_all_by_host")
- self.compute.conductor_api.instance_get_all_by_host(
- admin_context, self.compute.host).AndReturn([instance])
-
bdms = []
self.mox.StubOutWithMock(self.compute, "_shutdown_instance")
@@ -3065,32 +3061,28 @@ class ComputeTestCase(BaseTestCase):
self.compute._cleanup_running_deleted_instances(admin_context)
def test_running_deleted_instances(self):
- self.mox.StubOutWithMock(self.compute.driver, 'list_instances')
- self.compute.driver.list_instances().AndReturn(['herp', 'derp'])
+ admin_context = context.get_admin_context()
+
self.compute.host = 'host'
instance1 = {}
- instance1['name'] = 'herp'
instance1['deleted'] = True
instance1['deleted_at'] = "sometimeago"
instance2 = {}
- instance2['name'] = 'derp'
instance2['deleted'] = False
instance2['deleted_at'] = None
+ self.mox.StubOutWithMock(self.compute, '_get_instances_on_driver')
+ self.compute._get_instances_on_driver(admin_context).AndReturn(
+ [instance1, instance2])
+
self.mox.StubOutWithMock(timeutils, 'is_older_than')
timeutils.is_older_than('sometimeago',
CONF.running_deleted_instance_timeout).AndReturn(True)
- self.mox.StubOutWithMock(self.compute.conductor_api,
- "instance_get_all_by_host")
- self.compute.conductor_api.instance_get_all_by_host('context',
- 'host').AndReturn(
- [instance1,
- instance2])
self.mox.ReplayAll()
- val = self.compute._running_deleted_instances('context')
+ val = self.compute._running_deleted_instances(admin_context)
self.assertEqual(val, [instance1])
def test_get_instance_nw_info(self):