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."""
"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,
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:
'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].",