--- /dev/null
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
+#
+# 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.
+
+"""Exceptions for the Brick library."""
+
+import sys
+
+from oslo.config import cfg
+
+from cinder.openstack.common import log as logging
+
+
+LOG = logging.getLogger(__name__)
+
+exc_log_opts = [
+ cfg.BoolOpt('fatal_exception_format_errors',
+ default=False,
+ help='make exception message format errors fatal'),
+]
+
+CONF = cfg.CONF
+CONF.register_opts(exc_log_opts)
+
+
+class BrickException(Exception):
+ """Base Brick Exception
+
+ To correctly use this class, inherit from it and define
+ a 'msg_fmt' property. That msg_fmt will get printf'd
+ with the keyword arguments provided to the constructor.
+ """
+ msg_fmt = _("An unknown exception occurred.")
+ code = 500
+ headers = {}
+ safe = False
+
+ def __init__(self, message=None, **kwargs):
+ self.kwargs = kwargs
+
+ if 'code' not in self.kwargs:
+ try:
+ self.kwargs['code'] = self.code
+ except AttributeError:
+ pass
+
+ if not message:
+ try:
+ message = self.msg_fmt % kwargs
+
+ except Exception:
+ exc_info = sys.exc_info()
+ # kwargs doesn't match a variable in the message
+ # log the issue and the kwargs
+ LOG.exception(_('Exception in string format operation'))
+ for name, value in kwargs.iteritems():
+ LOG.error("%s: %s" % (name, value))
+
+ if CONF.fatal_exception_format_errors:
+ raise exc_info[0], exc_info[1], exc_info[2]
+ else:
+ # at least get the core message out if something happened
+ message = self.msg_fmt
+
+ super(BrickException, self).__init__(message)
+
+
+class NotFound(BrickException):
+ message = _("Resource could not be found.")
+ code = 404
+ safe = True
+
+
+class Invalid(BrickException):
+ message = _("Unacceptable parameters.")
+ code = 400
+
+
+# Cannot be templated as the error syntax varies.
+# msg needs to be constructed when raised.
+class InvalidParameterValue(Invalid):
+ message = _("%(err)s")
+
+
+class NoFibreChannelHostsFound(BrickException):
+ message = _("We are unable to locate any Fibre Channel devices.")
+
+
+class NoFibreChannelVolumeDeviceFound(BrickException):
+ message = _("Unable to find a Fibre Channel volume device.")
+
+
+class VolumeDeviceNotFound(BrickException):
+ message = _("Volume device not found at %(device)s.")
+
+
+class ISERTargetCreateFailed(BrickException):
+ message = _("Failed to create iser target for volume %(volume_id)s.")
+
+
+class ISERTargetRemoveFailed(BrickException):
+ message = _("Failed to remove iser target for volume %(volume_id)s.")
+++ /dev/null
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
-#
-# 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.
-
-"""Exceptions for the Brick library."""
-
-
-class NoFibreChannelHostsFound(Exception):
- def __init__(self):
- message = _("We are unable to locate any Fibre Channel devices")
- super(NoFibreChannelHostsFound, self).__init__(message)
-
-
-class NoFibreChannelVolumeDeviceFound(Exception):
- def __init__(self):
- message = _("Unable to find a Fibre Channel volume device")
- super(NoFibreChannelVolumeDeviceFound, self).__init__(message)
-
-
-class VolumeDeviceNotFound(Exception):
- def __init__(self, device):
- message = _("Volume device not found at %s") % device
- super(VolumeDeviceNotFound, self).__init__(message)
from oslo.config import cfg
-from cinder.brick import exceptions
+from cinder.brick import exception
from cinder.openstack.common.gettextutils import _
from cinder.openstack.common import lockutils
from cinder.openstack.common import log as logging
tries = 0
while not os.path.exists(host_device):
if tries >= CONF.num_iscsi_scan_tries:
- raise exceptions.VolumeDeviceNotFound(host_device)
+ raise exception.VolumeDeviceNotFound(device=host_device)
LOG.warn(_("ISCSI volume not yet found at: %(host_device)s. "
"Will rescan & retry. Try number: %(tries)s"),
# this is empty because we don't have any FC HBAs
msg = _("We are unable to locate any Fibre Channel devices")
LOG.warn(msg)
- raise exceptions.NoFibreChannelHostsFound()
+ raise exception.NoFibreChannelHostsFound()
# The /dev/disk/by-path/... node is not always present immediately
# We only need to find the first device. Once we see the first device
if self.tries >= CONF.num_iscsi_scan_tries:
msg = _("Fibre Channel volume device not found.")
LOG.error(msg)
- raise exceptions.NoFibreChannelVolumeDeviceFound()
+ raise exception.NoFibreChannelVolumeDeviceFound()
LOG.warn(_("Fibre volume not yet found. "
"Will rescan & retry. Try number: %(tries)s"),
import os
-import re
from oslo.config import cfg
-from cinder import exception
+from cinder.brick import exception
from cinder.openstack.common import fileutils
from cinder.openstack.common import log as logging
-from cinder import utils
-from cinder.volume import utils as volume_utils
-
+from cinder.openstack.common import processutils as putils
LOG = logging.getLogger(__name__)
class TgtAdm(TargetAdmin):
"""iSER target administration using tgtadm."""
- def __init__(self, execute=utils.execute):
+ def __init__(self, execute=putils.execute):
super(TgtAdm, self).__init__('tgtadm', execute)
def _get_target(self, iqn):
'--update',
name,
run_as_root=True)
- except exception.ProcessExecutionError as e:
+ except putils.ProcessExecutionError as e:
LOG.error(_("Failed to create iser target for volume "
"id:%(vol_id)s: %(e)s")
% {'vol_id': vol_id, 'e': str(e)})
'--delete',
iqn,
run_as_root=True)
- except exception.ProcessExecutionError as e:
+ except putils.ProcessExecutionError as e:
LOG.error(_("Failed to remove iser target for volume "
"id:%(vol_id)s: %(e)s")
% {'vol_id': vol_id, 'e': str(e)})
message = _("Failed to remove iscsi target for volume %(volume_id)s.")
-class ISERTargetNotFoundForVolume(NotFound):
- message = _("No target id found for volume %(volume_id)s.")
-
-
-class ISERTargetCreateFailed(CinderException):
- message = _("Failed to create iser target for volume %(volume_id)s.")
-
-
-class ISERTargetAttachFailed(CinderException):
- message = _("Failed to attach iser target for volume %(volume_id)s.")
-
-
-class ISERTargetRemoveFailed(CinderException):
- message = _("Failed to remove iser target for volume %(volume_id)s.")
-
-
class DiskNotFound(NotFound):
message = _("No disk at %(location)s")
import os.path
import string
-from cinder.brick import exceptions
+from cinder.brick import exception
from cinder.brick.initiator import connector
from cinder.brick.initiator import host_driver
from cinder.brick.initiator import linuxfc
lambda: [])
self.stubs.Set(self.connector._linuxfc, 'get_fc_hbas_info',
lambda: [])
- self.assertRaises(exceptions.NoFibreChannelHostsFound,
+ self.assertRaises(exception.NoFibreChannelHostsFound,
self.connector.connect_volume,
connection_info['data'])