move netapp exception

This patch moves the netapp exception to the netapp/utils.py
for common use among all the netapp drivers.

Change-Id: I4bed2917bdb7d9929c0fbfa2dcfe4067cb3d963f
This commit is contained in:
Walter A. Boring IV 2019-05-08 21:22:09 +00:00
parent 22e09a4bf3
commit b260260779
13 changed files with 43 additions and 44 deletions

View File

@ -1072,10 +1072,6 @@ class CiscoZoningCliException(CinderException):
message = _("Cisco Fibre Channel Zoning CLI error: %(reason)s")
class NetAppDriverException(VolumeDriverException):
message = _("NetApp Cinder Driver exception.")
# ConsistencyGroup
class ConsistencyGroupNotFound(NotFound):
message = _("ConsistencyGroup %(consistencygroup_id)s could not be found.")

View File

@ -101,7 +101,7 @@ class NetAppCmodeClientTestCase(test.TestCase):
api_response = netapp_api.NaElement(
fake_client.INVALID_GET_ITER_RESPONSE_NO_RECORDS)
self.assertRaises(exception.NetAppDriverException,
self.assertRaises(netapp_utils.NetAppDriverException,
self.client._get_record_count,
api_response)
@ -210,7 +210,7 @@ class NetAppCmodeClientTestCase(test.TestCase):
'send_request',
return_value=api_response)
self.assertRaises(exception.NetAppDriverException,
self.assertRaises(netapp_utils.NetAppDriverException,
self.client.send_iter_request,
'storage-disk-get-iter')
@ -1432,7 +1432,7 @@ class NetAppCmodeClientTestCase(test.TestCase):
self.mock_send_request.return_value = netapp_api.NaElement(
fake_client.NO_RECORDS_RESPONSE)
self.assertRaises(exception.NetAppDriverException,
self.assertRaises(netapp_utils.NetAppDriverException,
self.client.get_flexvol_capacity,
flexvol_path='fake_path')
@ -2966,7 +2966,7 @@ class NetAppCmodeClientTestCase(test.TestCase):
self.client.features.add_feature('SNAPMIRROR_V2', supported=False)
self.assertRaises(exception.NetAppDriverException,
self.assertRaises(netapp_utils.NetAppDriverException,
self.client._ensure_snapmirror_v2)
@ddt.data({'schedule': 'fake_schedule', 'policy': 'fake_policy'},

View File

@ -844,7 +844,7 @@ class NetAppBlockStorageLibraryTestCase(test.TestCase):
self.library.configuration.netapp_lun_ostype = 'unknown'
self.library.do_setup(mock.Mock())
self.assertRaises(exception.NetAppDriverException,
self.assertRaises(na_utils.NetAppDriverException,
self.library.check_for_setup_error)
block_base.LOG.error.assert_called_once_with(mock.ANY)
@ -856,7 +856,7 @@ class NetAppBlockStorageLibraryTestCase(test.TestCase):
self.library.configuration.netapp_host_type = 'future_os'
self.library.do_setup(mock.Mock())
self.assertRaises(exception.NetAppDriverException,
self.assertRaises(na_utils.NetAppDriverException,
self.library.check_for_setup_error)
block_base.LOG.error.assert_called_once_with(mock.ANY)
@ -955,7 +955,7 @@ class NetAppBlockStorageLibraryTestCase(test.TestCase):
self.mock_object(self.library.zapi_client, 'destroy_lun',
side_effect=netapp_api.NaApiError)
self.assertRaises(exception.NetAppDriverException,
self.assertRaises(na_utils.NetAppDriverException,
self.library._delete_lun,
fake.LUN_NAME)

View File

@ -130,7 +130,7 @@ class NetAppBlockStorageCmodeLibraryTestCase(test.TestCase):
self.mock_object(
self.library, '_get_flexvol_to_pool_map', return_value={})
self.assertRaises(exception.NetAppDriverException,
self.assertRaises(na_utils.NetAppDriverException,
self.library.check_for_setup_error)
@ddt.data({'replication_enabled': True, 'failed_over': False,
@ -686,7 +686,7 @@ class NetAppBlockStorageCmodeLibraryTestCase(test.TestCase):
self.library.backend_name = 'dev0'
self.mock_object(
data_motion.DataMotionMixin, '_complete_failover',
side_effect=exception.NetAppDriverException)
side_effect=na_utils.NetAppDriverException)
self.mock_object(data_motion.DataMotionMixin,
'get_replication_backend_names',
return_value=['dev1', 'dev2'])
@ -804,7 +804,7 @@ class NetAppBlockStorageCmodeLibraryTestCase(test.TestCase):
self.mock_object(self.zapi_client, 'create_cg_snapshot',
side_effect=netapp_api.NaApiError)
self.assertRaises(exception.NetAppDriverException,
self.assertRaises(na_utils.NetAppDriverException,
self.library.create_group_snapshot,
fake.VOLUME_GROUP,
[fake.VG_SNAPSHOT])

View File

@ -517,7 +517,7 @@ class NetAppCmodeNfsDriverTestCase(test.TestCase):
self.mock_object(
self.driver.zapi_client,
'mark_qos_policy_group_for_deletion',
side_effect=exception.NetAppDriverException)
side_effect=na_utils.NetAppDriverException)
self.driver.delete_volume(fake_volume)
@ -1366,7 +1366,7 @@ class NetAppCmodeNfsDriverTestCase(test.TestCase):
"""This tests executes a method in the DataMotionMixin."""
self.driver.backend_name = 'dev0'
self.mock_object(data_motion.DataMotionMixin, '_complete_failover',
side_effect=exception.NetAppDriverException)
side_effect=na_utils.NetAppDriverException)
self.mock_object(data_motion.DataMotionMixin,
'get_replication_backend_names',
return_value=['dev1', 'dev2'])
@ -1548,7 +1548,7 @@ class NetAppCmodeNfsDriverTestCase(test.TestCase):
self.mock_object(self.driver.zapi_client, 'create_cg_snapshot',
side_effect=netapp_api.NaApiError)
self.assertRaises(exception.NetAppDriverException,
self.assertRaises(na_utils.NetAppDriverException,
self.driver.create_group_snapshot,
fake.VG_CONTEXT,
fake.VOLUME_GROUP,

View File

@ -17,7 +17,6 @@ import ddt
import mock
from oslo_config import cfg
from cinder import exception
from cinder import test
from cinder.tests.unit.volume.drivers.netapp.dataontap.utils import fakes
from cinder.volume import configuration
@ -27,6 +26,7 @@ from cinder.volume.drivers.netapp.dataontap.client import client_cmode
from cinder.volume.drivers.netapp.dataontap.utils import data_motion
from cinder.volume.drivers.netapp.dataontap.utils import utils
from cinder.volume.drivers.netapp import options as na_opts
from cinder.volume.drivers.netapp import utils as na_utils
CONF = cfg.CONF
@ -517,7 +517,7 @@ class NetAppCDOTDataMotionMixinTestCase(test.TestCase):
mock_client_call = self.mock_object(
self.mock_dest_client, 'create_flexvol')
self.assertRaises(exception.NetAppDriverException,
self.assertRaises(na_utils.NetAppDriverException,
self.dm_mixin.create_destination_flexvol,
self.src_backend, self.dest_backend,
self.src_flexvol_name, self.dest_flexvol_name)
@ -734,7 +734,7 @@ class NetAppCDOTDataMotionMixinTestCase(test.TestCase):
self.mock_object(self.dm_mixin, 'update_snapmirrors')
self.mock_object(self.dm_mixin, 'break_snapmirrors')
self.assertRaises(exception.NetAppDriverException,
self.assertRaises(na_utils.NetAppDriverException,
self.dm_mixin._complete_failover,
self.src_backend, replication_backends, flexvols,
[], failover_target=None)

View File

@ -582,7 +582,7 @@ class NetAppDriverUtilsTestCase(test.TestCase):
"2001:db8::1:/wrong_export",
"[2001:db8::1:/wrong_export", "2001:db8::1]:/wrong_export")
def test_get_export_host_junction_path_with_invalid_exports(self, share):
self.assertRaises(exception.NetAppDriverException,
self.assertRaises(na_utils.NetAppDriverException,
na_utils.get_export_host_junction_path,
share)

View File

@ -163,12 +163,12 @@ class NetAppBlockStorageLibrary(object):
msg = _("Invalid value for NetApp configuration"
" option netapp_lun_ostype.")
LOG.error(msg)
raise exception.NetAppDriverException(msg)
raise na_utils.NetAppDriverException(msg)
if self.host_type not in self.ALLOWED_IGROUP_HOST_TYPES:
msg = _("Invalid value for NetApp configuration"
" option netapp_host_type.")
LOG.error(msg)
raise exception.NetAppDriverException(msg)
raise na_utils.NetAppDriverException(msg)
lun_list = self.zapi_client.get_lun_list()
self._extract_and_populate_luns(lun_list)
LOG.debug("Success getting list of LUNs from server.")
@ -289,7 +289,7 @@ class NetAppBlockStorageLibrary(object):
{'name': lun_name, 'message': e})
else:
error_message = (_('A NetApp Api Error occurred: %s') % e)
raise exception.NetAppDriverException(error_message)
raise na_utils.NetAppDriverException(error_message)
self.lun_table.pop(lun_name)
else:
LOG.warning("No entry in LUN table for volume/snapshot"

View File

@ -106,7 +106,7 @@ class NetAppBlockStorageCmodeLibrary(block_base.NetAppBlockStorageLibrary,
msg = _('No pools are available for provisioning volumes. '
'Ensure that the configuration option '
'netapp_pool_name_search_pattern is set correctly.')
raise exception.NetAppDriverException(msg)
raise na_utils.NetAppDriverException(msg)
self._add_looping_tasks()
super(NetAppBlockStorageCmodeLibrary, self).check_for_setup_error()
@ -506,7 +506,7 @@ class NetAppBlockStorageCmodeLibrary(block_base.NetAppBlockStorageLibrary,
except Exception as ex:
err_msg = (_("Create group snapshot failed (%s).") % ex)
LOG.exception(err_msg, resource=group_snapshot)
raise exception.NetAppDriverException(err_msg)
raise na_utils.NetAppDriverException(err_msg)
return None, None

View File

@ -95,7 +95,7 @@ class Client(client_base.Client):
return int(api_result_element.get_child_content('num-records'))
except TypeError:
msg = _('Missing record count for NetApp iterator API invocation.')
raise exception.NetAppDriverException(msg)
raise na_utils.NetAppDriverException(msg)
def set_vserver(self, vserver):
self.vserver = vserver
@ -124,7 +124,7 @@ class Client(client_base.Client):
attributes_list = result.get_child_by_name('attributes-list')
if not attributes_list:
msg = _('Missing attributes list for API %s.') % api_name
raise exception.NetAppDriverException(msg)
raise na_utils.NetAppDriverException(msg)
# Get remaining pages, saving data into first page
while next_tag is not None:
@ -895,7 +895,7 @@ class Client(client_base.Client):
if self._get_record_count(result) != 1:
msg = _('Volume %s not found.')
msg_args = flexvol_path or flexvol_name
raise exception.NetAppDriverException(msg % msg_args)
raise na_utils.NetAppDriverException(msg % msg_args)
attributes_list = result.get_child_by_name('attributes-list')
volume_attributes = attributes_list.get_child_by_name(
@ -1946,7 +1946,7 @@ class Client(client_base.Client):
"""Verify support for SnapMirror control plane v2."""
if not self.features.SNAPMIRROR_V2:
msg = _('SnapMirror features require Data ONTAP 8.2 or later.')
raise exception.NetAppDriverException(msg)
raise na_utils.NetAppDriverException(msg)
def create_snapmirror(self, source_vserver, source_volume,
destination_vserver, destination_volume,

View File

@ -790,7 +790,7 @@ class NetAppCmodeNfsDriver(nfs_base.NetAppNfsDriver,
except Exception as ex:
err_msg = (_("Create group snapshot failed (%s).") % ex)
LOG.exception(err_msg, resource=group_snapshot)
raise exception.NetAppDriverException(err_msg)
raise na_utils.NetAppDriverException(err_msg)
return None, None

View File

@ -29,6 +29,7 @@ from cinder.objects import fields
from cinder import utils
from cinder.volume.drivers.netapp.dataontap.client import api as netapp_api
from cinder.volume.drivers.netapp.dataontap.utils import utils as config_utils
from cinder.volume.drivers.netapp import utils as na_utils
from cinder.volume import utils as volume_utils
LOG = log.getLogger(__name__)
@ -308,7 +309,7 @@ class DataMotionMixin(object):
retries = (source_backend_config.netapp_snapmirror_quiesce_timeout /
QUIESCE_RETRY_INTERVAL)
@utils.retry(exception.NetAppDriverException,
@utils.retry(na_utils.NetAppDriverException,
interval=QUIESCE_RETRY_INTERVAL,
retries=retries, backoff_rate=1)
def wait_for_quiesced():
@ -318,11 +319,11 @@ class DataMotionMixin(object):
desired_attributes=['relationship-status', 'mirror-state'])[0]
if snapmirror.get('relationship-status') != 'quiesced':
msg = _("SnapMirror relationship is not quiesced.")
raise exception.NetAppDriverException(reason=msg)
raise na_utils.NetAppDriverException(reason=msg)
try:
wait_for_quiesced()
except exception.NetAppDriverException:
except na_utils.NetAppDriverException:
dest_client.abort_snapmirror(src_vserver,
src_flexvol_name,
dest_vserver,
@ -428,7 +429,7 @@ class DataMotionMixin(object):
if not size:
msg = _("Unable to read the size of the source FlexVol (%s) "
"to create a SnapMirror destination.")
raise exception.NetAppDriverException(msg % src_flexvol_name)
raise na_utils.NetAppDriverException(msg % src_flexvol_name)
provisioning_options.pop('volume_type', None)
source_aggregate = provisioning_options.pop('aggregate')
@ -439,7 +440,7 @@ class DataMotionMixin(object):
msg = _("Unable to find configuration matching the source "
"aggregate (%s) and the destination aggregate. Option "
"netapp_replication_aggregate_map may be incorrect.")
raise exception.NetAppDriverException(
raise na_utils.NetAppDriverException(
message=msg % source_aggregate)
destination_aggregate = aggregate_map[source_aggregate]
@ -571,7 +572,7 @@ class DataMotionMixin(object):
if active_backend_name is None:
msg = _("No suitable host was found to failover.")
raise exception.NetAppDriverException(msg)
raise na_utils.NetAppDriverException(msg)
source_backend_config = config_utils.get_backend_configuration(
source_backend_name)
@ -631,7 +632,7 @@ class DataMotionMixin(object):
active_backend_name, volume_updates = self._complete_failover(
self.backend_name, replication_targets, flexvols, volumes,
failover_target=secondary_id)
except exception.NetAppDriverException as e:
except na_utils.NetAppDriverException as e:
msg = _("Could not complete failover: %s") % e
raise exception.UnableToFailOver(reason=msg)

View File

@ -60,6 +60,10 @@ DEFAULT_CHAP_USER_NAME = 'NetApp_iSCSI_CHAP_Username'
API_TRACE_PATTERN = '(.*)'
class NetAppDriverException(exception.VolumeDriverException):
message = _("NetApp Cinder Driver exception.")
def validate_instantiation(**kwargs):
"""Checks if a driver is instantiated other than by the unified driver.
@ -375,9 +379,8 @@ def get_export_host_junction_path(share):
host = re.search(r'\[(.*)\]', share).group(1)
junction_path = share.split(':')[-1]
except AttributeError:
raise exception.NetAppDriverException(_("Share '%s' is "
"not in a valid "
"format.") % share)
raise NetAppDriverException(_("Share '%s' is not in a valid "
"format.") % share)
else:
# ipv4
path = share.split(':')
@ -385,9 +388,8 @@ def get_export_host_junction_path(share):
host = path[0]
junction_path = path[1]
else:
raise exception.NetAppDriverException(_("Share '%s' is "
"not in a valid "
"format.") % share)
raise NetAppDriverException(_("Share '%s' is not in a valid "
"format.") % share)
return host, junction_path