]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix the KeyError in CloudByte iSCSI cinder driver
authoryogeshprasad <yogesh.prasad@cloudbyte.com>
Thu, 7 May 2015 11:17:12 +0000 (16:47 +0530)
committeryogeshprasad <yogesh.prasad@cloudbyte.com>
Thu, 7 May 2015 14:47:01 +0000 (20:17 +0530)
Driver returns KeyError during list TSM if there is no TSM
found in CloudByte Storage.
This patch will make driver to return proper message.

Change-Id: I77f137afc87b63c0b491e010a1b8ccf63e9e89c2
Closes-Bug: 1452642

cinder/tests/unit/test_cloudbyte.py
cinder/volume/drivers/cloudbyte/cloudbyte.py

index 051ec2c210428d02fc8537790b64ed27908e6aba..a1ba649efac35aa8132d49915f3bdf5494d075a2 100644 (file)
@@ -674,6 +674,13 @@ class CloudByteISCSIDriverTestCase(testtools.TestCase):
 
         return MAP_COMMAND_TO_FAKE_RESPONSE[cmd]
 
+    def _none_response_to_list_tsm(self, cmd, params, version='1.0'):
+        """This is a side effect function."""
+        if cmd == 'listTsm':
+            return {"listTsmResponse": {}}
+
+        return MAP_COMMAND_TO_FAKE_RESPONSE[cmd]
+
     def _side_effect_api_req_to_list_filesystem(
             self, cmd, params, version='1.0'):
         """This is a side effect function."""
@@ -1036,6 +1043,27 @@ class CloudByteISCSIDriverTestCase(testtools.TestCase):
                 "list iscsi initiators."):
             self.driver.create_volume(volume)
 
+        # Test - VIII
+
+        volume['id'] = fake_volume_id
+        volume['size'] = 22
+
+        # reconfigure the dependencies
+        # reset the mocks
+        mock_api_req.reset_mock()
+
+        # configure or re-configure the mocks
+        mock_api_req.side_effect = (
+            self._none_response_to_list_tsm)
+
+        # now run the test
+        with testtools.ExpectedException(
+                exception.VolumeBackendAPIException,
+                "Bad or unexpected response from the storage volume "
+                "backend API: TSM \[openstack\] was not found in CloudByte "
+                "storage for account \[CustomerA\]."):
+            self.driver.create_volume(volume)
+
     @mock.patch.object(cloudbyte.CloudByteISCSIDriver,
                        '_api_request_for_cloudbyte')
     @mock.patch.object(cloudbyte.CloudByteISCSIDriver,
index cff37f458dc83ceac2e528fa7dc59fedf7947f49..436fefc657979da489ba999b6913df819586a47d 100644 (file)
@@ -236,9 +236,16 @@ class CloudByteISCSIDriver(san.SanISCSIDriver):
         data = self._api_request_for_cloudbyte(async_cmd, params)
         return data
 
-    def _get_tsm_details(self, data, tsm_name):
+    def _get_tsm_details(self, data, tsm_name, account_name):
         # Filter required tsm's details
-        tsms = data['listTsmResponse']['listTsm']
+        tsms = data['listTsmResponse'].get('listTsm')
+
+        if tsms is None:
+            msg = (_("TSM [%(tsm)s] was not found in CloudByte storage "
+                   "for account [%(account)s].") %
+                   {'tsm': tsm_name, 'account': account_name})
+            raise exception.VolumeBackendAPIException(data=msg)
+
         tsmdetails = {}
         for tsm in tsms:
             if tsm['name'] == tsm_name:
@@ -582,7 +589,7 @@ class CloudByteISCSIDriver(san.SanISCSIDriver):
                    'tsm': tsm_name})
 
         tsm_data = self._request_tsm_details(account_id)
-        tsm_details = self._get_tsm_details(tsm_data, tsm_name)
+        tsm_details = self._get_tsm_details(tsm_data, tsm_name, account_name)
 
         # Send request to create a qos group before creating a volume
         LOG.debug("Creating qos group for CloudByte volume [%s].",