Merge "move Hyperscale exceptions to driver"

This commit is contained in:
Zuul 2019-05-23 21:10:10 +00:00 committed by Gerrit Code Review
commit 35e350fc5b
5 changed files with 81 additions and 65 deletions

View File

@ -1143,28 +1143,6 @@ class AttachmentSpecsNotFound(NotFound):
"key %(specs_key)s.")
# Veritas driver
class UnableToExecuteHyperScaleCmd(VolumeDriverException):
message = _("Failed HyperScale command for '%(command)s'")
class UnableToProcessHyperScaleCmdOutput(VolumeDriverException):
message = _("Failed processing command output '%(cmd_out)s'"
" for HyperScale command")
class ErrorInFetchingConfiguration(VolumeDriverException):
message = _("Error in fetching configuration for '%(persona)s'")
class ErrorInSendingMsg(VolumeDriverException):
message = _("Error in sending message '%(cmd_error)s'")
class ErrorInHyperScaleVersion(VolumeDriverException):
message = _("Error in getting HyperScale version '%(cmd_error)s'")
class InvalidName(Invalid):
message = _("An invalid 'name' value was provided. %(reason)s")

View File

@ -20,6 +20,7 @@ from cinder import test
from cinder.tests.unit import fake_snapshot
from cinder.tests.unit import fake_volume
from cinder.volume import configuration as conf
from cinder.volume.drivers.veritas import exception as v_exception
from cinder.volume.drivers.veritas import vrtshyperscale as vrts
@ -170,7 +171,7 @@ class VRTSHyperScaleDriverTestCase(test.TestCase):
The test case checks happy path execution when driver version 1.0.0
is installed.
"""
mock_ghv.side_effect = exception.ErrorInHyperScaleVersion(
mock_ghv.side_effect = v_exception.ErrorInHyperScaleVersion(
cmd_error="mock error")
# check the driver for setup errors
@ -223,7 +224,7 @@ class VRTSHyperScaleDriverTestCase(test.TestCase):
"""Failure case for delete_volume one node in data plane."""
mock_gvmv.side_effect = None
self.driver.delete_volume(self.volume)
mock_mdp.side_effect = exception.UnableToProcessHyperScaleCmdOutput(
mock_mdp.side_effect = v_exception.UnableToProcessHyperScaleCmdOutput(
cmd_out='mock error')
self.assertRaises(exception.VolumeIsBusy, self.driver.delete_volume,
self.volume)
@ -237,7 +238,7 @@ class VRTSHyperScaleDriverTestCase(test.TestCase):
"""failure case for delete_volume with more than one data nodes."""
mock_gvmv.side_effect = VRTSHyperScaleDriverTestCase.gvmv_side_effect
mock_mdp.side_effect = exception.UnableToProcessHyperScaleCmdOutput(
mock_mdp.side_effect = v_exception.UnableToProcessHyperScaleCmdOutput(
cmd_out='mock error')
self.assertRaises(exception.VolumeIsBusy, self.driver.delete_volume,
@ -340,9 +341,9 @@ class VRTSHyperScaleDriverTestCase(test.TestCase):
"""Test case throws exception when command failed to execute."""
vol_a = _stub_volume()
vol_b = _stub_volume()
mock_mdp.side_effect = exception.UnableToExecuteHyperScaleCmd(
mock_mdp.side_effect = v_exception.UnableToExecuteHyperScaleCmd(
command='mock error')
self.assertRaises(exception.UnableToExecuteHyperScaleCmd,
self.assertRaises(v_exception.UnableToExecuteHyperScaleCmd,
self.driver.create_cloned_volume, vol_b, vol_a)
@mock.patch('cinder.volume.drivers.veritas.utils'
@ -393,7 +394,7 @@ class VRTSHyperScaleDriverTestCase(test.TestCase):
'.message_data_plane')
def test_extend_volume_with_exception(self, mock_mdp):
"""Test case extend volume to the given size in GB."""
mock_mdp.side_effect = exception.UnableToProcessHyperScaleCmdOutput(
mock_mdp.side_effect = v_exception.UnableToProcessHyperScaleCmdOutput(
cmd_out='mock error')
self.assertRaises(exception.VolumeDriverException,
self.driver.extend_volume, _stub_volume(), 256)
@ -410,9 +411,9 @@ class VRTSHyperScaleDriverTestCase(test.TestCase):
def test_create_volume_from_snapshot_with_exception(self, mock_mdp):
"""Test case create volume from snapshot thorws exception."""
fake_volume, fake_snapshot = _stub_volume(), _stub_snapshot()
mock_mdp.side_effect = exception.UnableToExecuteHyperScaleCmd(
mock_mdp.side_effect = v_exception.UnableToExecuteHyperScaleCmd(
command='mock error')
self.assertRaises(exception.UnableToExecuteHyperScaleCmd,
self.assertRaises(v_exception.UnableToExecuteHyperScaleCmd,
self.driver.create_volume_from_snapshot, fake_volume,
fake_snapshot)
@ -484,10 +485,10 @@ class VRTSHyperScaleDriverTestCase(test.TestCase):
mock_gvmv.side_effect = VRTSHyperScaleDriverTestCase.gvmv_side_effect
mock_es_obj = {'payload': {'update': False}}
mock_es.return_value = mock_es_obj
mock_mcp.side_effect = exception.UnableToExecuteHyperScaleCmd(
mock_mcp.side_effect = v_exception.UnableToExecuteHyperScaleCmd(
command='mock error')
fake_snapshot = _stub_snapshot()
self.assertRaises(exception.UnableToExecuteHyperScaleCmd,
self.assertRaises(v_exception.UnableToExecuteHyperScaleCmd,
self.driver.create_snapshot, fake_snapshot)
@mock.patch('cinder.volume.drivers.veritas.utils'

View File

@ -0,0 +1,36 @@
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from cinder import exception
from cinder.i18n import _
class UnableToExecuteHyperScaleCmd(exception.VolumeDriverException):
message = _("Failed HyperScale command for '%(command)s'")
class UnableToProcessHyperScaleCmdOutput(exception.VolumeDriverException):
message = _("Failed processing command output '%(cmd_out)s'"
" for HyperScale command")
class ErrorInFetchingConfiguration(exception.VolumeDriverException):
message = _("Error in fetching configuration for '%(persona)s'")
class ErrorInSendingMsg(exception.VolumeDriverException):
message = _("Error in sending message '%(cmd_error)s'")
class ErrorInHyperScaleVersion(exception.VolumeDriverException):
message = _("Error in getting HyperScale version '%(cmd_error)s'")

View File

@ -19,8 +19,8 @@ from oslo_log import log as logging
from oslo_utils import excutils
import six
from cinder import exception
from cinder.privsep import hscli
from cinder.volume.drivers.veritas import exception
from cinder.volume.drivers.veritas import hs_constants as constants
LOG = logging.getLogger(__name__)

View File

@ -28,6 +28,7 @@ from cinder.image import image_utils
from cinder import interface
from cinder import utils
from cinder.volume import driver
from cinder.volume.drivers.veritas import exception as v_exception
from cinder.volume.drivers.veritas import hs_constants as constants
from cinder.volume.drivers.veritas import utils as util
@ -103,8 +104,8 @@ class HyperScaleDriver(driver.VolumeDriver):
if version != HYPERSCALE_VERSION:
raise exception.VolumeBackendAPIException(
data=(_("Unsupported version: %s") % version))
except (exception.ErrorInHyperScaleVersion,
exception.UnableToExecuteHyperScaleCmd):
except (v_exception.ErrorInHyperScaleVersion,
v_exception.UnableToExecuteHyperScaleCmd):
err_msg = _('Exception in getting HyperScale version')
LOG.exception(err_msg)
raise exception.VolumeBackendAPIException(data=err_msg)
@ -172,8 +173,8 @@ class HyperScaleDriver(driver.VolumeDriver):
LOG.debug("In init vsa_map %s", self.vsa_map)
LOG.debug("In init compute_meta_map %s", self.compute_meta_map)
except (exception.UnableToProcessHyperScaleCmdOutput,
exception.ErrorInFetchingConfiguration):
except (v_exception.UnableToProcessHyperScaleCmdOutput,
v_exception.ErrorInFetchingConfiguration):
err_msg = _("Unable to initialise the Veritas cinder driver")
LOG.exception(err_msg)
raise exception.VolumeBackendAPIException(data=err_msg)
@ -246,8 +247,8 @@ class HyperScaleDriver(driver.VolumeDriver):
metadata_update['Potential_secondary_key'] = rt_key
metadata_update['Potential_secondary_ip'] = rt_dn_ip
except (exception.UnableToExecuteHyperScaleCmd,
exception.UnableToProcessHyperScaleCmdOutput):
except (v_exception.UnableToExecuteHyperScaleCmd,
v_exception.UnableToProcessHyperScaleCmdOutput):
with excutils.save_and_reraise_exception():
LOG.exception('Exception in clone volume', exc_info=True)
except exception.InvalidMetadataType:
@ -278,8 +279,8 @@ class HyperScaleDriver(driver.VolumeDriver):
payload = cmd_out.get('payload')
data = payload.get('of_membership')
except (exception.UnableToExecuteHyperScaleCmd,
exception.UnableToProcessHyperScaleCmdOutput):
except (v_exception.UnableToExecuteHyperScaleCmd,
v_exception.UnableToProcessHyperScaleCmdOutput):
with excutils.save_and_reraise_exception():
LOG.exception("Failed to get datanode config "
"information from controller")
@ -372,8 +373,8 @@ class HyperScaleDriver(driver.VolumeDriver):
LOG.debug("Create volume sent to reflection target data node")
except (exception.VolumeNotFound,
exception.UnableToProcessHyperScaleCmdOutput,
exception.ErrorInSendingMsg):
v_exception.UnableToProcessHyperScaleCmdOutput,
v_exception.ErrorInSendingMsg):
LOG.error("Exception in creating replica", exc_info=True)
metadata_update['Secondary_datanode_key'] = 'NA'
metadata_update['Secondary_datanode_ip'] = 'NA'
@ -472,8 +473,8 @@ class HyperScaleDriver(driver.VolumeDriver):
model_update = {'provider_location': volume['provider_location'],
'metadata': volume_metadata}
except (exception.UnableToProcessHyperScaleCmdOutput,
exception.ErrorInSendingMsg):
except (v_exception.UnableToProcessHyperScaleCmdOutput,
v_exception.ErrorInSendingMsg):
with excutils.save_and_reraise_exception():
LOG.exception('Unable to create hyperscale volume')
@ -524,8 +525,8 @@ class HyperScaleDriver(driver.VolumeDriver):
'hyperscale.storage.dm.volume.delete',
**message_body)
except (exception.UnableToProcessHyperScaleCmdOutput,
exception.ErrorInSendingMsg):
except (v_exception.UnableToProcessHyperScaleCmdOutput,
v_exception.ErrorInSendingMsg):
LOG.error('Exception while deleting volume', exc_info=True)
raise exception.VolumeIsBusy(volume_name=volume['name'])
@ -582,8 +583,8 @@ class HyperScaleDriver(driver.VolumeDriver):
meta['datanode_ip'] = self.datanode_ip
except (exception.VolumeNotFound,
exception.UnableToExecuteHyperScaleCmd,
exception.UnableToProcessHyperScaleCmdOutput):
v_exception.UnableToExecuteHyperScaleCmd,
v_exception.UnableToProcessHyperScaleCmdOutput):
with excutils.save_and_reraise_exception():
LOG.exception('Exception in create snapshot')
@ -675,8 +676,8 @@ class HyperScaleDriver(driver.VolumeDriver):
**message_body)
except (exception.VolumeNotFound,
exception.UnableToExecuteHyperScaleCmd,
exception.UnableToProcessHyperScaleCmdOutput):
v_exception.UnableToExecuteHyperScaleCmd,
v_exception.UnableToProcessHyperScaleCmdOutput):
with excutils.save_and_reraise_exception():
LOG.exception('Exception in create snapshot')
@ -728,8 +729,8 @@ class HyperScaleDriver(driver.VolumeDriver):
'hyperscale.storage.dm.version.delete',
**message_body)
except (exception.UnableToExecuteHyperScaleCmd,
exception.UnableToProcessHyperScaleCmdOutput):
except (v_exception.UnableToExecuteHyperScaleCmd,
v_exception.UnableToProcessHyperScaleCmdOutput):
with excutils.save_and_reraise_exception():
LOG.exception('Exception in delete snapshot')
@ -802,8 +803,8 @@ class HyperScaleDriver(driver.VolumeDriver):
metadata_update['Potential_secondary_key'] = rt_key
metadata_update['Potential_secondary_ip'] = rt_dn_ip
except (exception.UnableToExecuteHyperScaleCmd,
exception.UnableToProcessHyperScaleCmdOutput):
except (v_exception.UnableToExecuteHyperScaleCmd,
v_exception.UnableToProcessHyperScaleCmdOutput):
with excutils.save_and_reraise_exception():
LOG.exception('Exception in creating volume from snapshot')
except exception.InvalidMetadataType:
@ -847,8 +848,8 @@ class HyperScaleDriver(driver.VolumeDriver):
LOG.debug("Response Message from Controller: %s",
cmd_out)
except (exception.UnableToExecuteHyperScaleCmd,
exception.UnableToProcessHyperScaleCmdOutput):
except (v_exception.UnableToExecuteHyperScaleCmd,
v_exception.UnableToProcessHyperScaleCmdOutput):
with excutils.save_and_reraise_exception():
LOG.exception('Exception during fetch stats')
@ -871,8 +872,8 @@ class HyperScaleDriver(driver.VolumeDriver):
'hyperscale.storage.dm.volume.extend',
**message_body)
except (exception.UnableToProcessHyperScaleCmdOutput,
exception.ErrorInSendingMsg):
except (v_exception.UnableToProcessHyperScaleCmdOutput,
v_exception.ErrorInSendingMsg):
msg = _('Exception in extend volume %s') % volume['name']
LOG.exception(msg)
raise exception.VolumeDriverException(message=msg)
@ -917,8 +918,8 @@ class HyperScaleDriver(driver.VolumeDriver):
data['total_capacity_gb'] = float(total_capacity)
data['free_capacity_gb'] = float(free_capacity)
except (exception.UnableToExecuteHyperScaleCmd,
exception.UnableToProcessHyperScaleCmdOutput):
except (v_exception.UnableToExecuteHyperScaleCmd,
v_exception.UnableToProcessHyperScaleCmdOutput):
with excutils.save_and_reraise_exception():
LOG.exception('Exception during fetch stats')
@ -977,8 +978,8 @@ class HyperScaleDriver(driver.VolumeDriver):
'hs_image_id')
util.update_image(path, volume['id'], hs_img_id)
except (exception.UnableToExecuteHyperScaleCmd,
exception.UnableToProcessHyperScaleCmdOutput):
except (v_exception.UnableToExecuteHyperScaleCmd,
v_exception.UnableToProcessHyperScaleCmdOutput):
with excutils.save_and_reraise_exception():
LOG.exception('Failed to copy_image_to_volume')
@ -1002,7 +1003,7 @@ class HyperScaleDriver(driver.VolumeDriver):
image_meta,
path)
except (exception.UnableToExecuteHyperScaleCmd,
exception.UnableToProcessHyperScaleCmdOutput):
except (v_exception.UnableToExecuteHyperScaleCmd,
v_exception.UnableToProcessHyperScaleCmdOutput):
with excutils.save_and_reraise_exception():
LOG.exception('Failed to copy_volume_to_image')