summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Smith <danms@us.ibm.com>2013-06-17 13:43:15 -0700
committerDan Smith <danms@us.ibm.com>2013-06-19 13:34:49 -0700
commit2b36b2437f707614889a450f59b7b5bf02aa85a4 (patch)
treea048d63de44e2bd22f2df89c6a19c3b7e942464c
parent6bbe906db0385bcd11e0532b8b180272feb76042 (diff)
downloadnova-2b36b2437f707614889a450f59b7b5bf02aa85a4.tar.gz
nova-2b36b2437f707614889a450f59b7b5bf02aa85a4.tar.xz
nova-2b36b2437f707614889a450f59b7b5bf02aa85a4.zip
Use InstanceList for _heal_instance_info_cache()
This makes _heal_instance_info_cache() use InstanceList for the all-by-host query. Related to blueprint unified-object-model Change-Id: I93872a35ff249bbeb7d02bfe54a7d83676aa447a
-rwxr-xr-xnova/compute/manager.py12
-rw-r--r--nova/tests/compute/test_compute.py17
2 files changed, 16 insertions, 13 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 1def5b069..d98ca3f36 100755
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -3614,20 +3614,20 @@ class ComputeManager(manager.SchedulerDependentManager):
while not instance or instance['host'] != self.host:
if instance_uuids:
try:
- instance = self.conductor_api.instance_get_by_uuid(context,
- instance_uuids.pop(0))
+ instance = instance_obj.Instance.get_by_uuid(
+ context, instance_uuids.pop(0))
except exception.InstanceNotFound:
# Instance is gone. Try to grab another.
continue
else:
# No more in our copy of uuids. Pull from the DB.
- db_instances = self.conductor_api.instance_get_all_by_host(
- context, self.host, columns_to_join=[])
+ db_instances = instance_obj.InstanceList.get_by_host(
+ context, self.host, expected_attrs=[])
if not db_instances:
# None.. just return.
return
- instance = db_instances.pop(0)
- instance_uuids = [inst['uuid'] for inst in db_instances]
+ instance = db_instances[0]
+ instance_uuids = [inst['uuid'] for inst in db_instances[1:]]
self._instance_uuids_to_heal = instance_uuids
# We have an instance now and it's ours
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index 8c6fce3a5..fe3d3e21e 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -4333,9 +4333,11 @@ class ComputeTestCase(BaseTestCase):
instance_map = {}
instances = []
for x in xrange(5):
- uuid = 'fake-uuid-%s' % x
- instance_map[uuid] = {'uuid': uuid, 'host': CONF.host}
- instances.append(instance_map[uuid])
+ inst_uuid = 'fake-uuid-%s' % x
+ instance_map[inst_uuid] = fake_instance.fake_db_instance(
+ uuid=inst_uuid, host=CONF.host, created_at=None)
+ # These won't be in our instance since they're not requested
+ instances.append(instance_map[inst_uuid])
call_info = {'get_all_by_host': 0, 'get_by_uuid': 0,
'get_nw_info': 0, 'expected_instance': None}
@@ -4345,7 +4347,7 @@ class ComputeTestCase(BaseTestCase):
self.assertEqual(columns_to_join, [])
return instances[:]
- def fake_instance_get_by_uuid(context, instance_uuid):
+ def fake_instance_get_by_uuid(context, instance_uuid, columns_to_join):
if instance_uuid not in instance_map:
raise exception.InstanceNotFound(instance_id=instance_uuid)
call_info['get_by_uuid'] += 1
@@ -4357,12 +4359,13 @@ class ComputeTestCase(BaseTestCase):
# and is ignored. However, the below increment of
# 'get_nw_info' won't happen, and you'll get an assert
# failure checking it below.
- self.assertEqual(call_info['expected_instance'], instance)
+ self.assertEqual(call_info['expected_instance']['uuid'],
+ instance['uuid'])
call_info['get_nw_info'] += 1
- self.stubs.Set(self.compute.conductor_api, 'instance_get_all_by_host',
+ self.stubs.Set(db, 'instance_get_all_by_host',
fake_instance_get_all_by_host)
- self.stubs.Set(self.compute.conductor_api, 'instance_get_by_uuid',
+ self.stubs.Set(db, 'instance_get_by_uuid',
fake_instance_get_by_uuid)
self.stubs.Set(self.compute, '_get_instance_nw_info',
fake_get_instance_nw_info)