]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Raise an error if iSCSI is not supported
authorXavier Queralt <xqueralt@redhat.com>
Fri, 14 Jun 2013 13:18:23 +0000 (15:18 +0200)
committerXavier Queralt <xqueralt@redhat.com>
Fri, 14 Jun 2013 13:18:23 +0000 (15:18 +0200)
Since the compute nodes may not have iSCSI support, volume drivers
requiring it will raise an error if the connector's initiator attribute
is not set when initializing the connection.

bug #1007084

Related to: I5da472e5013fdc0c733ecb12b919c1068873bdc6

Change-Id: I95d859c11cf81bf57cecf7af8b224cdbb71592d5

cinder/tests/api/contrib/test_admin_actions.py
cinder/tests/test_volume.py
cinder/volume/driver.py
cinder/volume/manager.py

index 5d1f905908e0ed0409558499ca838d85ec8153c4..87725f18ca30259efb33611c1f9b7b8b356be5fb 100644 (file)
@@ -266,10 +266,11 @@ class AdminActionsTest(test.TestCase):
         # current status is available
         volume = db.volume_create(ctx, {'status': 'available', 'host': 'test',
                                         'provider_location': ''})
+        connector = {'initiator': 'iqn.2012-07.org.fake:01'}
         # start service to handle rpc messages for attach requests
         svc = self.start_service('volume', host='test')
         self.volume_api.reserve_volume(ctx, volume)
-        self.volume_api.initialize_connection(ctx, volume, {})
+        self.volume_api.initialize_connection(ctx, volume, connector)
         mountpoint = '/dev/vbd'
         self.volume_api.attach(ctx, volume, stubs.FAKE_UUID, mountpoint)
         # volume is attached
@@ -306,10 +307,11 @@ class AdminActionsTest(test.TestCase):
         # current status is available
         volume = db.volume_create(ctx, {'status': 'available', 'host': 'test',
                                         'provider_location': ''})
+        connector = {'initiator': 'iqn.2012-07.org.fake:01'}
         # start service to handle rpc messages for attach requests
         svc = self.start_service('volume', host='test')
         self.volume_api.reserve_volume(ctx, volume)
-        self.volume_api.initialize_connection(ctx, volume, {})
+        self.volume_api.initialize_connection(ctx, volume, connector)
         mountpoint = '/dev/vbd'
         self.volume_api.attach(ctx, volume, stubs.FAKE_UUID, mountpoint)
         self.assertRaises(exception.InvalidVolume,
@@ -321,6 +323,22 @@ class AdminActionsTest(test.TestCase):
         # cleanup
         svc.stop()
 
+    def test_invalid_iscsi_connector(self):
+        """Test connector without the initiator (required by iscsi driver)."""
+        # admin context
+        ctx = context.RequestContext('admin', 'fake', True)
+        # current status is available
+        volume = db.volume_create(ctx, {'status': 'available', 'host': 'test',
+                                        'provider_location': ''})
+        connector = {}
+        # start service to handle rpc messages for attach requests
+        svc = self.start_service('volume', host='test')
+        self.assertRaises(exception.VolumeBackendAPIException,
+                          self.volume_api.initialize_connection,
+                          ctx, volume, connector)
+        # cleanup
+        svc.stop()
+
     def test_attach_attaching_volume_with_different_instance(self):
         """Test that attaching volume reserved for another instance fails."""
         # admin context
@@ -328,9 +346,10 @@ class AdminActionsTest(test.TestCase):
         # current status is available
         volume = db.volume_create(ctx, {'status': 'available', 'host': 'test',
                                         'provider_location': ''})
+        connector = {'initiator': 'iqn.2012-07.org.fake:01'}
         # start service to handle rpc messages for attach requests
         svc = self.start_service('volume', host='test')
-        self.volume_api.initialize_connection(ctx, volume, {})
+        self.volume_api.initialize_connection(ctx, volume, connector)
         values = {'status': 'attaching',
                   'instance_uuid': fakes.get_fake_uuid()}
         db.volume_update(ctx, volume['id'], values)
index 64761e83100be3e2e3cd94fd7977c2606d9c11b3..c5180e385560747ca984bd04b467635ae20f6d9b 100644 (file)
@@ -1300,6 +1300,19 @@ class ISCSITestCase(DriverTestCase):
         self.assertEquals(stats['total_capacity_gb'], float('5.52'))
         self.assertEquals(stats['free_capacity_gb'], float('0.52'))
 
+    def test_validate_connector(self):
+        iscsi_driver = driver.ISCSIDriver()
+        # Validate a valid connector
+        connector = {'ip': '10.0.0.2',
+                     'host': 'fakehost',
+                     'initiator': 'iqn.2012-07.org.fake:01'}
+        iscsi_driver.validate_connector(connector)
+
+        # Validate a connector without the initiator
+        connector = {'ip': '10.0.0.2', 'host': 'fakehost'}
+        self.assertRaises(exception.VolumeBackendAPIException,
+                          iscsi_driver.validate_connector, connector)
+
 
 class FibreChannelTestCase(DriverTestCase):
     """Test Case for FibreChannelDriver"""
index a6b4455719eda63ac66b6d274e5a35cf625b1a5f..a296af6e66876790e6af283ce52f7deeb1411521 100644 (file)
@@ -164,6 +164,10 @@ class VolumeDriver(object):
         """Any initialization the volume driver does while starting"""
         pass
 
+    def validate_connector(self, connector):
+        """Fail if connector doesn't contain all the data needed by driver"""
+        pass
+
     def copy_image_to_volume(self, context, volume, image_service, image_id):
         """Fetch the image from image_service and write it to the volume."""
         raise NotImplementedError()
@@ -354,6 +358,14 @@ class ISCSIDriver(VolumeDriver):
             'data': iscsi_properties
         }
 
+    def validate_connector(self, connector):
+        # iSCSI drivers require the initiator information
+        if 'initiator' not in connector:
+            err_msg = (_('The volume driver requires the iSCSI initiator '
+                         'name in the connector.'))
+            LOG.error(err_msg)
+            raise exception.VolumeBackendAPIException(data=err_msg)
+
     def terminate_connection(self, volume, connector, **kwargs):
         pass
 
index e986b7cd0ee671690b8abe263cfca79deb52efb1..4555b4a713d563d22511e950a5fc1057535101b5 100644 (file)
@@ -694,6 +694,7 @@ class VolumeManager(manager.SchedulerDependentManager):
               data types.
         """
         volume_ref = self.db.volume_get(context, volume_id)
+        self.driver.validate_connector(connector)
         return self.driver.initialize_connection(volume_ref, connector)
 
     def terminate_connection(self, context, volume_id, connector, force=False):