]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix block_device driver to behave as documented
authorRalf Haferkamp <rhafer@suse.de>
Thu, 9 Jul 2015 12:07:49 +0000 (14:07 +0200)
committerRalf Haferkamp <rhafer@suse.de>
Thu, 9 Jul 2015 15:21:12 +0000 (17:21 +0200)
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

cinder/tests/unit/test_block_device.py
cinder/volume/drivers/block_device.py

index 2cdddb89f57576745d599cdc17b6013ed45426bc..d7a486a0b15a29c4e5d8235aa5ee87fb6baadb31 100644 (file)
@@ -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)
 
index bed0c5867bc4433c7b9d41bf076af13d5e818aae..4fe9608e20eb4b4ac212f97f3c46d902a9e85c67 100644 (file)
@@ -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)