diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-01-04 22:37:08 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-01-04 22:37:08 +0000 |
commit | 11698a3073d743154360ebeac982fb0a5f566bcc (patch) | |
tree | bc0b862095263a2ba5409582a63ea17c014c1a5b | |
parent | 20a338d5cbe6ef6e0661cf8294404a88bac32e41 (diff) | |
parent | 03c2a0ba5228448baf90fd9248bc51c8071a7d47 (diff) | |
download | nova-11698a3073d743154360ebeac982fb0a5f566bcc.tar.gz nova-11698a3073d743154360ebeac982fb0a5f566bcc.tar.xz nova-11698a3073d743154360ebeac982fb0a5f566bcc.zip |
Merge "Move block_device_mapping update operations to conductor"
-rw-r--r-- | nova/compute/manager.py | 9 | ||||
-rw-r--r-- | nova/conductor/api.py | 29 | ||||
-rw-r--r-- | nova/conductor/manager.py | 11 | ||||
-rw-r--r-- | nova/conductor/rpcapi.py | 7 | ||||
-rw-r--r-- | nova/tests/conductor/test_conductor.py | 51 |
5 files changed, 102 insertions, 5 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 489deef42..6876b0a6d 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -551,7 +551,7 @@ class ComputeManager(manager.SchedulerDependentManager): if volume['status'] != 'creating': break greenthread.sleep(1) - self.db.block_device_mapping_update( + self.conductor_api.block_device_mapping_update( context, bdm['id'], {'volume_id': vol['id']}) bdm['volume_id'] = vol['id'] @@ -562,7 +562,7 @@ class ComputeManager(manager.SchedulerDependentManager): instance, volume, bdm['device_name']) - self.db.block_device_mapping_update( + self.conductor_api.block_device_mapping_update( context, bdm['id'], {'connection_info': jsonutils.dumps(cinfo)}) bdmap = {'connection_info': cinfo, @@ -2308,7 +2308,7 @@ class ComputeManager(manager.SchedulerDependentManager): values = {'instance_uuid': instance['uuid'], 'volume_id': volume_id or 'reserved', 'device_name': result} - self.db.block_device_mapping_create(context, values) + self.conductor_api.block_device_mapping_create(context, values) return result return do_reserve() @@ -2374,7 +2374,8 @@ class ComputeManager(manager.SchedulerDependentManager): 'volume_id': volume_id, 'volume_size': None, 'no_device': None} - self.db.block_device_mapping_update_or_create(context, values) + self.conductor_api.block_device_mapping_update_or_create(context, + values) def _detach_volume(self, context, instance, bdm): """Do the actual driver detach using block device mapping.""" diff --git a/nova/conductor/api.py b/nova/conductor/api.py index d811265ac..650849781 100644 --- a/nova/conductor/api.py +++ b/nova/conductor/api.py @@ -135,6 +135,21 @@ class LocalAPI(object): return self._manager.agent_build_get_by_triple(context, hypervisor, os, architecture) + def block_device_mapping_create(self, context, values): + return self._manager.block_device_mapping_update_or_create(context, + values, + create=True) + + def block_device_mapping_update(self, context, bdm_id, values): + values = dict(values) + values['id'] = bdm_id + return self._manager.block_device_mapping_update_or_create( + context, values, create=False) + + def block_device_mapping_update_or_create(self, context, values): + return self._manager.block_device_mapping_update_or_create(context, + values) + class API(object): """Conductor API that does updates via RPC to the ConductorManager""" @@ -220,3 +235,17 @@ class API(object): hypervisor, os, architecture) + + def block_device_mapping_create(self, context, values): + return self.conductor_rpcapi.block_device_mapping_update_or_create( + context, values, create=True) + + def block_device_mapping_update(self, context, bdm_id, values): + values = dict(values) + values['id'] = bdm_id + return self.conductor_rpcapi.block_device_mapping_update_or_create( + context, values, create=False) + + def block_device_mapping_update_or_create(self, context, values): + return self.conductor_rpcapi.block_device_mapping_update_or_create( + context, values) diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py index 92770cc84..6d346b0a4 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.11' + RPC_API_VERSION = '1.12' def __init__(self, *args, **kwargs): super(ConductorManager, self).__init__(service_name='conductor', @@ -155,3 +155,12 @@ class ConductorManager(manager.SchedulerDependentManager): info = self.db.agent_build_get_by_triple(context, hypervisor, os, architecture) return jsonutils.to_primitive(info) + + def block_device_mapping_update_or_create(self, context, values, + create=None): + if create is None: + self.db.block_device_mapping_update_or_create(context, values) + elif create is True: + self.db.block_device_mapping_create(context, values) + else: + self.db.block_device_mapping_update(context, values['id'], values) diff --git a/nova/conductor/rpcapi.py b/nova/conductor/rpcapi.py index e7484d91f..3e9aa44a2 100644 --- a/nova/conductor/rpcapi.py +++ b/nova/conductor/rpcapi.py @@ -40,6 +40,7 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy): 1.9 - Added provider_fw_rule_get_all 1.10 - Added agent_build_get_by_triple 1.11 - Added aggregate_get + 1.12 - Added block_device_mapping_update_or_create """ BASE_RPC_API_VERSION = '1.0' @@ -145,3 +146,9 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy): hypervisor=hypervisor, os=os, architecture=architecture) return self.call(context, msg, version='1.10') + + def block_device_mapping_update_or_create(self, context, values, + create=None): + msg = self.make_msg('block_device_mapping_update_or_create', + values=values, create=create) + return self.call(context, msg, version='1.12') diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py index 46ad730e6..0d1ff1d60 100644 --- a/nova/tests/conductor/test_conductor.py +++ b/nova/tests/conductor/test_conductor.py @@ -276,6 +276,24 @@ class ConductorTestCase(_BaseTestCase, test.TestCase): self.conductor = conductor_manager.ConductorManager() self.stub_out_client_exceptions() + def test_block_device_mapping_update_or_create(self): + fake_bdm = {'id': 'fake-id'} + self.mox.StubOutWithMock(db, 'block_device_mapping_create') + self.mox.StubOutWithMock(db, 'block_device_mapping_update') + self.mox.StubOutWithMock(db, 'block_device_mapping_update_or_create') + db.block_device_mapping_create(self.context, fake_bdm) + db.block_device_mapping_update(self.context, fake_bdm['id'], fake_bdm) + db.block_device_mapping_update_or_create(self.context, fake_bdm) + self.mox.ReplayAll() + self.conductor.block_device_mapping_update_or_create(self.context, + fake_bdm, + create=True) + self.conductor.block_device_mapping_update_or_create(self.context, + fake_bdm, + create=False) + self.conductor.block_device_mapping_update_or_create(self.context, + fake_bdm) + class ConductorRPCAPITestCase(_BaseTestCase, test.TestCase): """Conductor RPC API Tests""" @@ -285,6 +303,24 @@ class ConductorRPCAPITestCase(_BaseTestCase, test.TestCase): 'conductor', manager='nova.conductor.manager.ConductorManager') self.conductor = conductor_rpcapi.ConductorAPI() + def test_block_device_mapping_update_or_create(self): + fake_bdm = {'id': 'fake-id'} + self.mox.StubOutWithMock(db, 'block_device_mapping_create') + self.mox.StubOutWithMock(db, 'block_device_mapping_update') + self.mox.StubOutWithMock(db, 'block_device_mapping_update_or_create') + db.block_device_mapping_create(self.context, fake_bdm) + db.block_device_mapping_update(self.context, fake_bdm['id'], fake_bdm) + db.block_device_mapping_update_or_create(self.context, fake_bdm) + self.mox.ReplayAll() + self.conductor.block_device_mapping_update_or_create(self.context, + fake_bdm, + create=True) + self.conductor.block_device_mapping_update_or_create(self.context, + fake_bdm, + create=False) + self.conductor.block_device_mapping_update_or_create(self.context, + fake_bdm) + class ConductorAPITestCase(_BaseTestCase, test.TestCase): """Conductor API Tests""" @@ -313,6 +349,21 @@ class ConductorAPITestCase(_BaseTestCase, test.TestCase): result = self.conductor.bw_usage_get(*get_args) self.assertEqual(result, 'foo') + def test_block_device_mapping_update_or_create(self): + self.mox.StubOutWithMock(db, 'block_device_mapping_create') + self.mox.StubOutWithMock(db, 'block_device_mapping_update') + self.mox.StubOutWithMock(db, 'block_device_mapping_update_or_create') + db.block_device_mapping_create(self.context, 'fake-bdm') + db.block_device_mapping_update(self.context, + 'fake-id', {'id': 'fake-id'}) + db.block_device_mapping_update_or_create(self.context, 'fake-bdm') + + self.mox.ReplayAll() + self.conductor.block_device_mapping_create(self.context, 'fake-bdm') + self.conductor.block_device_mapping_update(self.context, 'fake-id', {}) + self.conductor.block_device_mapping_update_or_create(self.context, + 'fake-bdm') + class ConductorLocalAPITestCase(ConductorAPITestCase): """Conductor LocalAPI Tests""" |