From d03c94f2b0e3a6d15e404d245fdfa895ca6430de Mon Sep 17 00:00:00 2001 From: John Griffith Date: Tue, 4 Jun 2013 13:02:37 -0600 Subject: [PATCH] Add call to vol driver when accepting a transfer Some back-ends have the notion of tenancy on volumes and set ownership in the driver. The update of the DB alone when doing volume transfers isn't enough, we need to be able to propogate the update info all the way down to the driver level. This patch introduces the volume api/manger/rpc calls and implements a stub in the base driver that can be over-ridden for those that need to take some action. Change-Id: Ica6ae368084c44b32af5d08df14bb3745f3a37ee --- cinder/tests/test_volume_rpcapi.py | 6 ++++++ cinder/transfer/api.py | 3 ++- cinder/volume/api.py | 4 ++++ cinder/volume/driver.py | 3 +++ cinder/volume/manager.py | 4 ++++ cinder/volume/rpcapi.py | 8 ++++++++ 6 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cinder/tests/test_volume_rpcapi.py b/cinder/tests/test_volume_rpcapi.py index 7a75224b819..70735243d71 100644 --- a/cinder/tests/test_volume_rpcapi.py +++ b/cinder/tests/test_volume_rpcapi.py @@ -170,3 +170,9 @@ class VolumeRpcAPITestCase(test.TestCase): volume=self.fake_volume, connector='fake_connector', force=False) + + def test_accept_transfer(self): + self._test_volume_api('accept_transfer', + rpc_method='cast', + volume=self.fake_volume, + version='1.5') diff --git a/cinder/transfer/api.py b/cinder/transfer/api.py index e139951a228..0ae5d2325f0 100644 --- a/cinder/transfer/api.py +++ b/cinder/transfer/api.py @@ -36,7 +36,7 @@ volume_transfer_opts = [ help='The number of characters in the salt.'), cfg.IntOpt('volume_transfer_key_length', default=16, help='The number of characters in the ' - 'autogenerated auth key.'), ] + 'autogenerated auth key.'), ] FLAGS = flags.FLAGS FLAGS.register_opts(volume_transfer_opts) @@ -178,6 +178,7 @@ class API(base.Base): try: # Transfer ownership of the volume now, must use an elevated # context. + self.volume_api.accept_transfer(context, vol_ref) self.db.transfer_accept(context.elevated(), transfer_id, context.user_id, diff --git a/cinder/volume/api.py b/cinder/volume/api.py index d24e8a0e766..05c22388c40 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -518,6 +518,10 @@ class API(base.Base): connector, force) + def accept_transfer(self, context, volume): + return self.volume_rpcapi.accept_transfer(context, + volume) + def _create_snapshot(self, context, volume, name, description, force=False, metadata=None): diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index 275ced42fd2..7240ad2f6be 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -480,6 +480,9 @@ class ISCSIDriver(VolumeDriver): data['QoS_support'] = False self._stats = data + def accept_transfer(self, volume): + pass + class FakeISCSIDriver(ISCSIDriver): """Logs calls instead of executing.""" diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index f465e53ba17..8effaf1b6a6 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -701,6 +701,10 @@ class VolumeManager(manager.SchedulerDependentManager): volume_ref = self.db.volume_get(context, volume_id) self.driver.terminate_connection(volume_ref, connector, force=force) + def accept_transfer(self, context, volume_id): + volume_ref = self.db.volume_get(context, volume_id) + self.driver.accept_transfer(volume_ref) + @manager.periodic_task def _report_driver_status(self, context): LOG.info(_("Updating volume status")) diff --git a/cinder/volume/rpcapi.py b/cinder/volume/rpcapi.py index 1788873d5df..adb9e4d0fc8 100644 --- a/cinder/volume/rpcapi.py +++ b/cinder/volume/rpcapi.py @@ -38,6 +38,7 @@ class VolumeAPI(cinder.openstack.common.rpc.proxy.RpcProxy): 1.3 - Pass all image metadata (not just ID) in copy_volume_to_image 1.4 - Add request_spec, filter_properties and allow_reschedule arguments to create_volume(). + 1.5 - Add accept_transfer ''' BASE_RPC_API_VERSION = '1.0' @@ -128,3 +129,10 @@ class VolumeAPI(cinder.openstack.common.rpc.proxy.RpcProxy): def publish_service_capabilities(self, ctxt): self.fanout_cast(ctxt, self.make_msg('publish_service_capabilities'), version='1.2') + + def accept_transfer(self, ctxt, volume): + self.cast(ctxt, + self.make_msg('accept_transfer', + volume_id=volume['id']), + topic=rpc.queue_get_for(ctxt, self.topic, volume['host']), + version='1.5')