From 7855afe5f32ff865de9bf56ea1c62e77541216df Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 14 Jan 2013 12:33:30 -0500 Subject: [PATCH] Move migration_get_..._by_host_and_node to conductor This moves the remaining migration-related database call out of the resource tracker to conductor: migration_get_in_progress_by_host_and_node() Related to blueprint no-db-compute Change-Id: I9bdf9fbbc3131964bf6078d19bf1cd9053a7e224 --- nova/compute/resource_tracker.py | 3 ++- nova/conductor/api.py | 9 +++++++++ nova/conductor/manager.py | 8 +++++++- nova/conductor/rpcapi.py | 7 +++++++ nova/tests/compute/test_multiple_nodes.py | 3 +++ nova/tests/conductor/test_conductor.py | 10 ++++++++++ 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/nova/compute/resource_tracker.py b/nova/compute/resource_tracker.py index f3c3ae7a309a..a4bb92425122 100644 --- a/nova/compute/resource_tracker.py +++ b/nova/compute/resource_tracker.py @@ -259,7 +259,8 @@ class ResourceTracker(object): self._update_usage_from_instances(resources, instances) # Grab all in-progress migrations: - migrations = db.migration_get_in_progress_by_host_and_node(context, + capi = self.conductor_api + migrations = capi.migration_get_in_progress_by_host_and_node(context, self.host, self.nodename) self._update_usage_from_migrations(resources, migrations) diff --git a/nova/conductor/api.py b/nova/conductor/api.py index 63b64f830afe..dbd777ebf487 100644 --- a/nova/conductor/api.py +++ b/nova/conductor/api.py @@ -134,6 +134,10 @@ class LocalAPI(object): return self._manager.migration_get_unconfirmed_by_dest_compute( context, confirm_window, dest_compute) + def migration_get_in_progress_by_host_and_node(self, context, host, node): + return self._manager.migration_get_in_progress_by_host_and_node( + context, host, node) + def migration_create(self, context, instance, values): return self._manager.migration_create(context, instance, values) @@ -370,6 +374,11 @@ class API(object): return crpcapi.migration_get_unconfirmed_by_dest_compute( context, confirm_window, dest_compute) + def migration_get_in_progress_by_host_and_node(self, context, host, node): + crpcapi = self.conductor_rpcapi + return crpcapi.migration_get_in_progress_by_host_and_node(context, + host, node) + def migration_create(self, context, instance, values): return self.conductor_rpcapi.migration_create(context, instance, values) diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py index b0d4011ad855..0ff60f920861 100644 --- a/nova/conductor/manager.py +++ b/nova/conductor/manager.py @@ -43,7 +43,7 @@ datetime_fields = ['launched_at', 'terminated_at'] class ConductorManager(manager.SchedulerDependentManager): """Mission: TBD.""" - RPC_API_VERSION = '1.30' + RPC_API_VERSION = '1.31' def __init__(self, *args, **kwargs): super(ConductorManager, self).__init__(service_name='conductor', @@ -100,6 +100,12 @@ class ConductorManager(manager.SchedulerDependentManager): context, confirm_window, dest_compute) return jsonutils.to_primitive(migrations) + def migration_get_in_progress_by_host_and_node(self, context, + host, node): + migrations = self.db.migration_get_in_progress_by_host_and_node( + context, host, node) + return jsonutils.to_primitive(migrations) + def migration_create(self, context, instance, values): values.update({'instance_uuid': instance['uuid'], 'source_compute': instance['host'], diff --git a/nova/conductor/rpcapi.py b/nova/conductor/rpcapi.py index b7f760cf5c19..a39095ef4ee3 100644 --- a/nova/conductor/rpcapi.py +++ b/nova/conductor/rpcapi.py @@ -63,6 +63,7 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy): 1.28 - Added binary arg to service_get_all_by 1.29 - Added service_destroy 1.30 - Added migration_create + 1.31 - Added migration_get_in_progress_by_host_and_node """ BASE_RPC_API_VERSION = '1.0' @@ -106,6 +107,12 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy): dest_compute=dest_compute) return self.call(context, msg, version='1.20') + def migration_get_in_progress_by_host_and_node(self, context, + host, node): + msg = self.make_msg('migration_get_in_progress_by_host_and_node', + host=host, node=node) + return self.call(context, msg, version='1.31') + def migration_create(self, context, instance, values): instance_p = jsonutils.to_primitive(instance) msg = self.make_msg('migration_create', instance=instance_p, diff --git a/nova/tests/compute/test_multiple_nodes.py b/nova/tests/compute/test_multiple_nodes.py index 78ed0cea7eb1..27ee7aaba5ce 100644 --- a/nova/tests/compute/test_multiple_nodes.py +++ b/nova/tests/compute/test_multiple_nodes.py @@ -80,6 +80,9 @@ class MultiNodeComputeTestCase(BaseTestCase): super(MultiNodeComputeTestCase, self).setUp() self.flags(compute_driver='nova.virt.fake.FakeDriver') self.compute = importutils.import_object(CONF.compute_manager) + self.flags(use_local=True, group='conductor') + self.conductor = self.start_service('conductor', + manager=CONF.conductor.manager) def test_update_available_resource_add_remove_node(self): ctx = context.get_admin_context() diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py index cc3dbfcc00b7..5fc4caaea2af 100644 --- a/nova/tests/conductor/test_conductor.py +++ b/nova/tests/conductor/test_conductor.py @@ -130,6 +130,16 @@ class _BaseTestCase(object): 'fake-window', 'fake-host') + def test_migration_get_in_progress_by_host_and_node(self): + self.mox.StubOutWithMock(db, + 'migration_get_in_progress_by_host_and_node') + db.migration_get_in_progress_by_host_and_node( + self.context, 'fake-host', 'fake-node').AndReturn('fake-result') + self.mox.ReplayAll() + result = self.conductor.migration_get_in_progress_by_host_and_node( + self.context, 'fake-host', 'fake-node') + self.assertEqual(result, 'fake-result') + def test_migration_create(self): inst = {'uuid': 'fake-uuid', 'host': 'fake-host',