From: Ralf Haferkamp Date: Thu, 9 Jul 2015 12:07:49 +0000 (+0200) Subject: Fix block_device driver to behave as documented X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=d7f7e0b45f44ddf8ef215215394714ff00bff2e2;p=openstack-build%2Fcinder-build.git Fix block_device driver to behave as documented According to the original blueprint (https://blueprints.launchpad.net/cinder/+spec/block-device-driver) the intended behavior of the "BlockDeviceDriver" was to directly attach the block device to the instances using virtio (without LVM and iSCSI involved) when the volume's underlying device is located on the same host as the instance that it is going to be attached to. This is also how it worked through Juno. It got broken during the Kilo cycle as part of this change: https://review.openstack.org/#/c/135139/ It seems that the change in behavior was not intended by that patch as it addressed something completely different. And it was neither mentioned in the commit message nor anywhere in the review comments. This patch restores the original behavior. Change-Id: Ic22f03860a43b767e9097ce6dc5b397cf9f3f076 Closes-Bug: 1473001 --- diff --git a/cinder/tests/unit/test_block_device.py b/cinder/tests/unit/test_block_device.py index 2cdddb89f..d7a486a0b 100644 --- a/cinder/tests/unit/test_block_device.py +++ b/cinder/tests/unit/test_block_device.py @@ -49,16 +49,8 @@ class TestBlockDeviceDriver(cinder.test.TestCase): TEST_CONNECTOR = {'host': 'localhost1'} data = self.drv.initialize_connection(TEST_VOLUME1, TEST_CONNECTOR) - expected_data = {'data': {'auth_method': 'a', - 'auth_password': 'c', - 'auth_username': 'b', - 'encrypted': False, - 'target_discovered': False, - 'target_iqn': '2', - 'target_lun': 3, - 'target_portal': '1', - 'volume_id': 'fake-uuid'}, - 'driver_volume_type': 'iscsi'} + expected_data = {'data': {'device_path': '/dev/loop1'}, + 'driver_volume_type': 'local'} self.assertEqual(expected_data, data) diff --git a/cinder/volume/drivers/block_device.py b/cinder/volume/drivers/block_device.py index bed0c5867..4fe9608e2 100644 --- a/cinder/volume/drivers/block_device.py +++ b/cinder/volume/drivers/block_device.py @@ -204,14 +204,22 @@ class BlockDeviceDriver(driver.BaseVD, driver.LocalVD, driver.CloneableVD, export_info = self.target_driver.create_export(context, volume, volume_path) - return {'provider_location': export_info['location'], - 'provider_auth': export_info['auth'], } + return { + 'provider_location': export_info['location'] + ' ' + volume_path, + 'provider_auth': export_info['auth'], + } def remove_export(self, context, volume): self.target_driver.remove_export(context, volume) def initialize_connection(self, volume, connector): - return self.target_driver.initialize_connection(volume, connector) + if connector['host'] != volutils.extract_host(volume['host'], 'host'): + return self.target_driver.initialize_connection(volume, connector) + else: + return { + 'driver_volume_type': 'local', + 'data': {'device_path': self.local_path(volume)}, + } def validate_connector(self, connector): return self.target_driver.validate_connector(connector)