Merge "move datera exception"

This commit is contained in:
Zuul 2019-05-10 08:41:53 +00:00 committed by Gerrit Code Review
commit 1bee9f4fc0
3 changed files with 32 additions and 33 deletions

View File

@ -1146,11 +1146,6 @@ class InvalidGroupSnapshotStatus(Invalid):
message = _("Invalid GroupSnapshot Status: %(reason)s") message = _("Invalid GroupSnapshot Status: %(reason)s")
# Datera driver
class DateraAPIException(VolumeBackendAPIException):
message = _("Bad response from Datera API")
# Target drivers # Target drivers
class ISCSITargetCreateFailed(CinderException): class ISCSITargetCreateFailed(CinderException):
message = _("Failed to create iscsi target for volume %(volume_id)s.") message = _("Failed to create iscsi target for volume %(volume_id)s.")

View File

@ -80,8 +80,8 @@ class DateraVolumeTestCasev2(test.TestCase):
self.assertIsNone(self.driver.create_volume(self.volume)) self.assertIsNone(self.driver.create_volume(self.volume))
def test_volume_create_fails(self): def test_volume_create_fails(self):
self.mock_api.side_effect = exception.DateraAPIException self.mock_api.side_effect = datc.DateraAPIException
self.assertRaises(exception.DateraAPIException, self.assertRaises(datc.DateraAPIException,
self.driver.create_volume, self.volume) self.driver.create_volume, self.volume)
def test_volume_create_delay(self): def test_volume_create_delay(self):
@ -157,12 +157,12 @@ class DateraVolumeTestCasev2(test.TestCase):
cloned_volume, cloned_volume['size']) cloned_volume, cloned_volume['size'])
def test_create_cloned_volume_fails(self): def test_create_cloned_volume_fails(self):
self.mock_api.side_effect = exception.DateraAPIException self.mock_api.side_effect = datc.DateraAPIException
source_volume = _stub_volume( source_volume = _stub_volume(
id='7f91abfa-7964-41ed-88fc-207c3a290b4f', id='7f91abfa-7964-41ed-88fc-207c3a290b4f',
display_name='foo' display_name='foo'
) )
self.assertRaises(exception.DateraAPIException, self.assertRaises(datc.DateraAPIException,
self.driver.create_cloned_volume, self.volume, self.driver.create_cloned_volume, self.volume,
source_volume) source_volume)
@ -214,8 +214,8 @@ class DateraVolumeTestCasev2(test.TestCase):
self.assertIsNone(self.driver.delete_volume(self.volume)) self.assertIsNone(self.driver.delete_volume(self.volume))
def test_delete_volume_fails(self): def test_delete_volume_fails(self):
self.mock_api.side_effect = exception.DateraAPIException self.mock_api.side_effect = datc.DateraAPIException
self.assertRaises(exception.DateraAPIException, self.assertRaises(datc.DateraAPIException,
self.driver.delete_volume, self.volume) self.driver.delete_volume, self.volume)
def test_ensure_export_success(self): def test_ensure_export_success(self):
@ -226,9 +226,9 @@ class DateraVolumeTestCasev2(test.TestCase):
None)) None))
def test_ensure_export_fails(self): def test_ensure_export_fails(self):
self.mock_api.side_effect = exception.DateraAPIException self.mock_api.side_effect = datc.DateraAPIException
ctxt = context.get_admin_context() ctxt = context.get_admin_context()
self.assertRaises(exception.DateraAPIException, self.assertRaises(datc.DateraAPIException,
self.driver.ensure_export, ctxt, self.volume, None) self.driver.ensure_export, ctxt, self.volume, None)
def test_create_export_target_does_not_exist_success(self): def test_create_export_target_does_not_exist_success(self):
@ -240,9 +240,9 @@ class DateraVolumeTestCasev2(test.TestCase):
None)) None))
def test_create_export_fails(self): def test_create_export_fails(self):
self.mock_api.side_effect = exception.DateraAPIException self.mock_api.side_effect = datc.DateraAPIException
ctxt = context.get_admin_context() ctxt = context.get_admin_context()
self.assertRaises(exception.DateraAPIException, self.assertRaises(datc.DateraAPIException,
self.driver.create_export, self.driver.create_export,
ctxt, ctxt,
self.volume, self.volume,
@ -267,9 +267,9 @@ class DateraVolumeTestCasev2(test.TestCase):
connector)) connector))
def test_initialize_connection_fails(self): def test_initialize_connection_fails(self):
self.mock_api.side_effect = exception.DateraAPIException self.mock_api.side_effect = datc.DateraAPIException
connector = {} connector = {}
self.assertRaises(exception.DateraAPIException, self.assertRaises(datc.DateraAPIException,
self.driver.initialize_connection, self.driver.initialize_connection,
self.volume, self.volume,
connector) connector)
@ -303,10 +303,10 @@ class DateraVolumeTestCasev2(test.TestCase):
self.assertIsNone(self.driver.detach_volume(ctxt, volume)) self.assertIsNone(self.driver.detach_volume(ctxt, volume))
def test_detach_volume_fails(self): def test_detach_volume_fails(self):
self.mock_api.side_effect = exception.DateraAPIException self.mock_api.side_effect = datc.DateraAPIException
ctxt = context.get_admin_context() ctxt = context.get_admin_context()
volume = _stub_volume(status='in-use') volume = _stub_volume(status='in-use')
self.assertRaises(exception.DateraAPIException, self.assertRaises(datc.DateraAPIException,
self.driver.detach_volume, ctxt, volume) self.driver.detach_volume, ctxt, volume)
def test_detach_volume_not_found(self): def test_detach_volume_not_found(self):
@ -334,9 +334,9 @@ class DateraVolumeTestCasev2(test.TestCase):
self.assertIsNone(self.driver.create_snapshot(snapshot)) self.assertIsNone(self.driver.create_snapshot(snapshot))
def test_create_snapshot_fails(self): def test_create_snapshot_fails(self):
self.mock_api.side_effect = exception.DateraAPIException self.mock_api.side_effect = datc.DateraAPIException
snapshot = _stub_snapshot(volume_id=self.volume['id']) snapshot = _stub_snapshot(volume_id=self.volume['id'])
self.assertRaises(exception.DateraAPIException, self.assertRaises(datc.DateraAPIException,
self.driver.create_snapshot, snapshot) self.driver.create_snapshot, snapshot)
def test_delete_snapshot_success(self): def test_delete_snapshot_success(self):
@ -361,9 +361,9 @@ class DateraVolumeTestCasev2(test.TestCase):
self.assertIsNone(self.driver.delete_snapshot(snapshot)) self.assertIsNone(self.driver.delete_snapshot(snapshot))
def test_delete_snapshot_fails(self): def test_delete_snapshot_fails(self):
self.mock_api.side_effect = exception.DateraAPIException self.mock_api.side_effect = datc.DateraAPIException
snapshot = _stub_snapshot(volume_id=self.volume['id']) snapshot = _stub_snapshot(volume_id=self.volume['id'])
self.assertRaises(exception.DateraAPIException, self.assertRaises(datc.DateraAPIException,
self.driver.delete_snapshot, snapshot) self.driver.delete_snapshot, snapshot)
def test_create_volume_from_snapshot_success(self): def test_create_volume_from_snapshot_success(self):
@ -409,9 +409,9 @@ class DateraVolumeTestCasev2(test.TestCase):
extend_volume['size']) extend_volume['size'])
def test_create_volume_from_snapshot_fails(self): def test_create_volume_from_snapshot_fails(self):
self.mock_api.side_effect = exception.DateraAPIException self.mock_api.side_effect = datc.DateraAPIException
snapshot = _stub_snapshot(volume_id=self.volume['id']) snapshot = _stub_snapshot(volume_id=self.volume['id'])
self.assertRaises(exception.DateraAPIException, self.assertRaises(datc.DateraAPIException,
self.driver.create_volume_from_snapshot, self.volume, self.driver.create_volume_from_snapshot, self.volume,
snapshot) snapshot)
@ -431,9 +431,9 @@ class DateraVolumeTestCasev2(test.TestCase):
self.assertIsNone(self.driver.extend_volume(volume, 2)) self.assertIsNone(self.driver.extend_volume(volume, 2))
def test_extend_volume_fails(self): def test_extend_volume_fails(self):
self.mock_api.side_effect = exception.DateraAPIException self.mock_api.side_effect = datc.DateraAPIException
volume = _stub_volume(size=1) volume = _stub_volume(size=1)
self.assertRaises(exception.DateraAPIException, self.assertRaises(datc.DateraAPIException,
self.driver.extend_volume, volume, 2) self.driver.extend_volume, volume, 2)
def test_login_successful(self): def test_login_successful(self):

View File

@ -81,6 +81,10 @@ M_MANAGED = 'cinder_managed'
M_KEYS = [M_TYPE, M_CALL, M_CLONE, M_MANAGED] M_KEYS = [M_TYPE, M_CALL, M_CLONE, M_MANAGED]
class DateraAPIException(exception.VolumeBackendAPIException):
message = _("Bad response from Datera API")
def _get_name(name): def _get_name(name):
return "".join((OS_PREFIX, name)) return "".join((OS_PREFIX, name))
@ -157,7 +161,7 @@ def _api_lookup(func):
msg = _("No compatible API version found for this product: " msg = _("No compatible API version found for this product: "
"api_versions -> %(api_version)s, %(func)s") "api_versions -> %(api_version)s, %(func)s")
LOG.error(msg, api_version=api_version, func=func) LOG.error(msg, api_version=api_version, func=func)
raise exception.DateraAPIException(msg % { raise DateraAPIException(msg % {
'api_version': api_version, 'func': func}) 'api_version': api_version, 'func': func})
# Py27 # Py27
try: try:
@ -190,7 +194,7 @@ def _api_lookup(func):
else: else:
LOG.info(e) LOG.info(e)
index -= 1 index -= 1
except exception.DateraAPIException as e: except DateraAPIException as e:
if "UnsupportedVersionError" in six.text_type(e): if "UnsupportedVersionError" in six.text_type(e):
index -= 1 index -= 1
else: else:
@ -221,7 +225,7 @@ def _get_supported_api_versions(driver):
resp = driver._request(url, "get", None, header, cert_data) resp = driver._request(url, "get", None, header, cert_data)
data = resp.json() data = resp.json()
results = [elem.strip("v") for elem in data['api_versions']] results = [elem.strip("v") for elem in data['api_versions']]
except (exception.DateraAPIException, KeyError): except (DateraAPIException, KeyError):
# Fallback to pre-endpoint logic # Fallback to pre-endpoint logic
for version in API_VERSIONS[0:-1]: for version in API_VERSIONS[0:-1]:
url = '%s://%s:%s/v%s' % (protocol, host, port, version) url = '%s://%s:%s/v%s' % (protocol, host, port, version)
@ -311,7 +315,7 @@ def _request(driver, connection_string, method, payload, header, cert_data):
'to the following reason: %s') % six.text_type( 'to the following reason: %s') % six.text_type(
ex.message) ex.message)
LOG.error(msg) LOG.error(msg)
raise exception.DateraAPIException(msg) raise DateraAPIException(msg)
def _raise_response(driver, response): def _raise_response(driver, response):
@ -320,7 +324,7 @@ def _raise_response(driver, response):
'status': response.status_code, 'status': response.status_code,
'reason': response.reason} 'reason': response.reason}
LOG.error(msg) LOG.error(msg)
raise exception.DateraAPIException(msg) raise DateraAPIException(msg)
def _handle_bad_status(driver, def _handle_bad_status(driver,
@ -337,7 +341,7 @@ def _handle_bad_status(driver,
# Raise the exception, but don't log any error. We'll just fall # Raise the exception, but don't log any error. We'll just fall
# back to the old style of determining API version. We make this # back to the old style of determining API version. We make this
# request a lot, so logging it is just noise # request a lot, so logging it is just noise
raise exception.DateraAPIException raise DateraAPIException
if response.status_code == http_client.NOT_FOUND: if response.status_code == http_client.NOT_FOUND:
raise exception.NotFound(response.json()['message']) raise exception.NotFound(response.json()['message'])
elif response.status_code in [http_client.FORBIDDEN, elif response.status_code in [http_client.FORBIDDEN,