summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Smith <danms@us.ibm.com>2012-12-07 09:00:04 -0800
committerDan Smith <danms@us.ibm.com>2012-12-07 09:00:04 -0800
commitaa97ba926d5bf6bc81903c5d651ece308e9629c0 (patch)
tree12ca5b0aa38a48c8c4c784e2dd6fd625282cbc13
parent3c45436cbfe45236e3e6643b80c061c618e3bfa1 (diff)
Use conductor for migration_get()
This patch removes direct database accesses for looking up migrations by id, and instead queries conductor. Related to blueprint no-db-compute Change-Id: Ia7df121971b14b1eb4ce65063246968b3603309d
-rw-r--r--nova/compute/manager.py15
-rw-r--r--nova/conductor/api.py6
-rw-r--r--nova/conductor/manager.py7
-rw-r--r--nova/conductor/rpcapi.py5
-rw-r--r--nova/tests/conductor/test_conductor.py8
5 files changed, 30 insertions, 11 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index fd8dc7d17..f0c0fe961 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -1625,8 +1625,7 @@ class ComputeManager(manager.SchedulerDependentManager):
migration=None, migration_id=None):
"""Destroys the source instance."""
if not migration:
- migration = self.db.migration_get(context.elevated(),
- migration_id)
+ migration = self.conductor_api.migration_get(context, migration_id)
self._notify_about_instance_usage(context, instance,
"resize.confirm.start")
@@ -1662,8 +1661,7 @@ class ComputeManager(manager.SchedulerDependentManager):
"""
if not migration:
- migration = self.db.migration_get(context.elevated(),
- migration_id)
+ migration = self.conductor_api.migration_get(context, migration_id)
# NOTE(comstud): A revert_resize is essentially a resize back to
# the old size, so we need to send a usage event here.
@@ -1706,10 +1704,8 @@ class ComputeManager(manager.SchedulerDependentManager):
in the database.
"""
- elevated = context.elevated()
-
if not migration:
- migration = self.db.migration_get(elevated, migration_id)
+ migration = self.conductor_api.migration_get(context, migration_id)
with self._error_out_instance_on_exception(context, instance['uuid'],
reservations):
@@ -1889,7 +1885,7 @@ class ComputeManager(manager.SchedulerDependentManager):
instance_type=None):
"""Starts the migration of a running instance to another host."""
if not migration:
- migration = self.db.migration_get(context.elevated(), migration_id)
+ migration = self.conductor_api.migration_get(context, migration_id)
with self._error_out_instance_on_exception(context, instance['uuid'],
reservations):
if not instance_type:
@@ -2026,8 +2022,7 @@ class ComputeManager(manager.SchedulerDependentManager):
"""
if not migration:
- migration = self.db.migration_get(context.elevated(),
- migration_id)
+ migration = self.conductor_api.migration_get(context, migration_id)
try:
self._finish_resize(context, instance, migration,
disk_info, image)
diff --git a/nova/conductor/api.py b/nova/conductor/api.py
index ddbd64d03..781a6ea90 100644
--- a/nova/conductor/api.py
+++ b/nova/conductor/api.py
@@ -53,6 +53,9 @@ class LocalAPI(object):
def instance_get_all_by_host(self, context, host):
return self._manager.instance_get_all_by_host(context, host)
+ def migration_get(self, context, migration_id):
+ return self._manager.migration_get(context, migration_id)
+
def migration_update(self, context, migration, status):
return self._manager.migration_update(context, migration, status)
@@ -81,6 +84,9 @@ class API(object):
def instance_get_all_by_host(self, context, host):
return self.conductor_rpcapi.instance_get_all_by_host(context, host)
+ def migration_get(self, context, migration_id):
+ return self.conductor_rpcapi.migration_get(context, migration_id)
+
def migration_update(self, context, migration, status):
return self.conductor_rpcapi.migration_update(context, migration,
status)
diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py
index 824875b3c..ce76fe02d 100644
--- a/nova/conductor/manager.py
+++ b/nova/conductor/manager.py
@@ -41,7 +41,7 @@ datetime_fields = ['launched_at', 'terminated_at']
class ConductorManager(manager.SchedulerDependentManager):
"""Mission: TBD"""
- RPC_API_VERSION = '1.3'
+ RPC_API_VERSION = '1.4'
def __init__(self, *args, **kwargs):
super(ConductorManager, self).__init__(service_name='conductor',
@@ -69,6 +69,11 @@ class ConductorManager(manager.SchedulerDependentManager):
return jsonutils.to_primitive(
self.db.instance_get_all_by_host(context.elevated(), host))
+ def migration_get(self, context, migration_id):
+ migration_ref = self.db.migration_get(context.elevated(),
+ migration_id)
+ return jsonutils.to_primitive(migration_ref)
+
def migration_update(self, context, migration, status):
migration_ref = self.db.migration_update(context.elevated(),
migration['id'],
diff --git a/nova/conductor/rpcapi.py b/nova/conductor/rpcapi.py
index ae82856e4..0ca1269c4 100644
--- a/nova/conductor/rpcapi.py
+++ b/nova/conductor/rpcapi.py
@@ -30,6 +30,7 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.1 - Added migration_update
1.2 - Added instance_get_by_uuid and instance_get_all_by_host
1.3 - Added aggregate_host_add and aggregate_host_delete
+ 1.4 - Added migration_get
"""
BASE_RPC_API_VERSION = '1.0'
@@ -55,6 +56,10 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy):
msg = self.make_msg('instance_get_all_by_host', host=host)
return self.call(context, msg, version='1.2')
+ def migration_get(self, context, migration_id):
+ msg = self.make_msg('migration_get', migration_id=migration_id)
+ return self.call(context, msg, version='1.4')
+
def migration_update(self, context, migration, status):
migration_p = jsonutils.to_primitive(migration)
msg = self.make_msg('migration_update', migration=migration_p,
diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py
index 880a3a717..8c97c4cdc 100644
--- a/nova/tests/conductor/test_conductor.py
+++ b/nova/tests/conductor/test_conductor.py
@@ -90,6 +90,14 @@ class ConductorTestCase(BaseTestCase):
self.assertRaises(KeyError,
self._do_update, 'any-uuid', foobar=1)
+ def test_migration_get(self):
+ migration = db.migration_create(self.context.elevated(),
+ {'instance_uuid': 'fake-uuid',
+ 'status': 'migrating'})
+ self.assertEqual(jsonutils.to_primitive(migration),
+ self.conductor.migration_get(self.context,
+ migration['id']))
+
def test_migration_update(self):
migration = db.migration_create(self.context.elevated(),
{'instance_uuid': 'fake-uuid',