info = self.volume_api.initialize_connection(context,
volume,
connector)
+ except exception.InvalidInput as err:
+ raise webob.exc.HTTPBadRequest(
+ explanation=err)
except exception.VolumeBackendAPIException as error:
msg = _("Unable to fetch connection information from backend.")
raise webob.exc.HTTPInternalServerError(explanation=msg)
message = _("Operation failed with status=%(status)s. Full dump: %(data)s")
+class InvalidConnectorException(VolumeDriverException):
+ message = _("Connector doesn't have required information: %(missing)s")
+
+
class GlanceMetadataExists(Invalid):
message = _("Glance metadata cannot be updated, key %(key)s"
" exists for volume id %(volume_id)s")
connector = {}
# start service to handle rpc messages for attach requests
svc = self.start_service('volume', host='test')
- self.assertRaises(exception.VolumeBackendAPIException,
+ self.assertRaises(exception.InvalidInput,
self.volume_api.initialize_connection,
ctx, volume, connector)
# cleanup
def test_validate_connector(self):
bad_connector = {'no_initiator': 'nada'}
- self.assertRaises(exception.VolumeBackendAPIException,
+ self.assertRaises(exception.InvalidConnectorException,
self.target.validate_connector,
bad_connector)
def test_validate_connector_failed(self):
invalid_connector = {'host': 'testhost'}
- self.assertRaises(exception.VolumeBackendAPIException,
+ self.assertRaises(exception.InvalidConnectorException,
self.driver.validate_connector,
invalid_connector)
self.driver._protocol = 'FC'
self.driver.validate_connector(conn_fc)
self.driver.validate_connector(conn_both)
- self.assertRaises(exception.VolumeDriverException,
+ self.assertRaises(exception.InvalidConnectorException,
self.driver.validate_connector, conn_iscsi)
- self.assertRaises(exception.VolumeDriverException,
+ self.assertRaises(exception.InvalidConnectorException,
self.driver.validate_connector, conn_neither)
# clear environment
self.driver._state['enabled_protocols'] = set(['iSCSI'])
self.driver.validate_connector(conn_iscsi)
self.driver.validate_connector(conn_both)
- self.assertRaises(exception.VolumeDriverException,
+ self.assertRaises(exception.InvalidConnectorException,
self.driver.validate_connector, conn_fc)
- self.assertRaises(exception.VolumeDriverException,
+ self.assertRaises(exception.InvalidConnectorException,
self.driver.validate_connector, conn_neither)
self.driver._state['enabled_protocols'] = set(['FC'])
self.driver.validate_connector(conn_fc)
self.driver.validate_connector(conn_both)
- self.assertRaises(exception.VolumeDriverException,
+ self.assertRaises(exception.InvalidConnectorException,
self.driver.validate_connector, conn_iscsi)
- self.assertRaises(exception.VolumeDriverException,
+ self.assertRaises(exception.InvalidConnectorException,
self.driver.validate_connector, conn_neither)
self.driver._state['enabled_protocols'] = set(['iSCSI', 'FC'])
self.driver.validate_connector(conn_iscsi)
self.driver.validate_connector(conn_fc)
self.driver.validate_connector(conn_both)
- self.assertRaises(exception.VolumeDriverException,
+ self.assertRaises(exception.InvalidConnectorException,
self.driver.validate_connector, conn_neither)
def test_storwize_svc_host_maps(self):
# Validate a connector without the initiator
connector = {'ip': '10.0.0.2', 'host': 'fakehost'}
- self.assertRaises(exception.VolumeBackendAPIException,
+ self.assertRaises(exception.InvalidConnectorException,
iscsi_driver.validate_connector, connector)
def test_validate_connector_no_wwpns(self):
"""validate_connector() throws exception when it has no wwpns."""
connector = {'wwnns': ["not empty"]}
- self.assertRaises(exception.VolumeDriverException,
+ self.assertRaises(exception.InvalidConnectorException,
self.volume.driver.validate_connector, connector)
def test_validate_connector_empty_wwpns(self):
"""validate_connector() throws exception when it has empty wwpns."""
connector = {'wwpns': [],
'wwnns': ["not empty"]}
- self.assertRaises(exception.VolumeDriverException,
+ self.assertRaises(exception.InvalidConnectorException,
self.volume.driver.validate_connector, connector)
def test_validate_connector_no_wwnns(self):
"""validate_connector() throws exception when it has no wwnns."""
connector = {'wwpns': ["not empty"]}
- self.assertRaises(exception.VolumeDriverException,
+ self.assertRaises(exception.InvalidConnectorException,
self.volume.driver.validate_connector, connector)
def test_validate_connector_empty_wwnns(self):
"""validate_connector() throws exception when it has empty wwnns."""
connector = {'wwnns': [],
'wwpns': ["not empty"]}
- self.assertRaises(exception.VolumeDriverException,
+ self.assertRaises(exception.InvalidConnectorException,
self.volume.driver.validate_connector, connector)
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)
+ required = 'initiator'
+ if required not in connector:
+ err_msg = (_LE('The volume driver requires %(data)s '
+ 'in the connector.'), {'data': required})
+ LOG.error(*err_msg)
+ raise exception.InvalidConnectorException(missing=required)
def terminate_connection(self, volume, connector, **kwargs):
pass
def validate_connector_has_setting(connector, setting):
"""Test for non-empty setting in connector."""
if setting not in connector or not connector[setting]:
- msg = (_(
+ msg = (_LE(
"FibreChannelDriver validate_connector failed. "
- "No '%s'. Make sure HBA state is Online.") % setting)
- LOG.error(msg)
- raise exception.VolumeDriverException(message=msg)
+ "No '%(setting)s'. Make sure HBA state is Online."),
+ {'setting': setting})
+ LOG.error(*msg)
+ raise exception.InvalidConnectorException(missing=setting)
import time
from cinder import exception
-from cinder.i18n import _, _LW
+from cinder.i18n import _, _LE, _LW
from cinder.openstack.common import log as logging
from cinder.volume import driver
from cinder.volume.drivers.huawei import huawei_utils
def validate_connector(self, connector):
"""Check for wwpns in connector."""
if 'wwpns' not in connector:
- err_msg = (_('validate_connector: The FC driver requires the'
- ' wwpns in the connector.'))
+ err_msg = (_LE('validate_connector: The FC driver requires the'
+ ' wwpns in the connector.'))
LOG.error(err_msg)
- raise exception.VolumeBackendAPIException(data=err_msg)
+ raise exception.InvalidConnectorException(missing='wwpns')
@fczm_utils.AddFCZone
def initialize_connection(self, volume, connector):
def validate_connector(self, connector):
"""Check connector."""
- if 'FC' != self._protocol or 'wwpns' not in connector:
- msg = (_('The connector does not contain the '
- 'required information.'))
+ if 'FC' == self._protocol and 'wwpns' not in connector:
+ msg = (_LE('The connector does not contain the '
+ 'required information: wwpns is missing'))
LOG.error(msg)
- raise exception.VolumeDriverException(data=msg)
+ raise exception.InvalidConnectorException(missing='wwpns')
def create_volume(self, volume):
"""Create volume."""
if 'FC' in self._state['enabled_protocols'] and 'wwpns' in connector:
valid = True
if not valid:
- msg = (_('The connector does not contain the required '
- 'information.'))
+ msg = (_LE('The connector does not contain the required '
+ 'information.'))
LOG.error(msg)
- raise exception.VolumeDriverException(message=msg)
+ raise exception.InvalidConnectorException(
+ missing='initiator or wwpns')
def _get_vdisk_params(self, type_id, volume_type=None,
volume_metadata=None):
utils.require_driver_initialized(self.driver)
try:
self.driver.validate_connector(connector)
+ except exception.InvalidConnectorException as err:
+ raise exception.InvalidInput(reason=err)
except Exception as err:
- err_msg = (_('Unable to fetch connection information from '
+ err_msg = (_('Unable to validate connector information in '
'backend: %(err)s') % {'err': err})
LOG.error(err_msg)
raise exception.VolumeBackendAPIException(data=err_msg)
def validate_connector(self, connector):
# NOTE(jdg): api passes in connector which is initiator info
if 'initiator' not in connector:
- err_msg = (_('The volume driver requires the iSCSI initiator '
- 'name in the connector.'))
+ err_msg = (_LE('The volume driver requires the iSCSI initiator '
+ 'name in the connector.'))
LOG.error(err_msg)
- raise exception.VolumeBackendAPIException(data=err_msg)
+ raise exception.InvalidConnectorException(missing='initiator')
return True