From 23b3a2391a2f55fdd7781df2f696bbf86dda08db Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Mon, 29 Jul 2013 16:21:46 -0700 Subject: [PATCH] Remove cinder.exception from Brick This patch fixes an issue that made Brick's connector module dependent on cinder's exception module. Adds a new brick exceptions module to store brick wide exceptions. fixes bug #1206288 Change-Id: I070d08f07c7bc488b24b0d68531bb2e0a5461422 --- cinder/brick/exceptions.py | 35 ++++++++++++++++++++++ cinder/brick/initiator/connector.py | 25 ++++++++++------ cinder/tests/brick/test_brick_connector.py | 7 +++-- 3 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 cinder/brick/exceptions.py diff --git a/cinder/brick/exceptions.py b/cinder/brick/exceptions.py new file mode 100644 index 00000000000..d046e3f9c05 --- /dev/null +++ b/cinder/brick/exceptions.py @@ -0,0 +1,35 @@ +# 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) diff --git a/cinder/brick/initiator/connector.py b/cinder/brick/initiator/connector.py index dfb50cb7051..44d4698f9bb 100644 --- a/cinder/brick/initiator/connector.py +++ b/cinder/brick/initiator/connector.py @@ -25,7 +25,7 @@ from oslo.config import cfg -from cinder import exception +from cinder.brick import exceptions from cinder.openstack.common.gettextutils import _ from cinder.openstack.common import lockutils from cinder.openstack.common import log as logging @@ -52,6 +52,9 @@ def get_connector_properties(): wwpns = fc.get_fc_wwpns() if wwpns: props['wwpns'] = wwpns + wwnns = fc.get_fc_wwnns() + if wwnns: + props['wwnns'] = wwnns return props @@ -97,7 +100,7 @@ def check_valid_device(self, path): try: out, info = self._execute(*cmd, run_as_root=True, root_helper=self._root_helper) - except exception.ProcessExecutionError as e: + except putils.ProcessExecutionError as e: LOG.error(_("Failed to access the device on the path " "%(path)s: %(error)s %(info)s.") % {"path": path, "error": e.stderr, @@ -174,8 +177,7 @@ def connect_volume(self, connection_properties): tries = 0 while not os.path.exists(host_device): if tries >= CONF.num_iscsi_scan_tries: - raise exception.CinderException( - _("iSCSI device not found at %s") % (host_device)) + raise exceptions.VolumeDeviceNotFound(host_device) LOG.warn(_("ISCSI volume not yet found at: %(host_device)s. " "Will rescan & retry. Try number: %(tries)s"), @@ -248,15 +250,18 @@ def _get_device_path(self, connection_properties): def get_initiator(self): """Secure helper to read file as root.""" + file_path = '/etc/iscsi/initiatorname.iscsi' try: - file_path = '/etc/iscsi/initiatorname.iscsi' lines, _err = self._execute('cat', file_path, run_as_root=True, root_helper=self._root_helper) for l in lines.split('\n'): if l.startswith('InitiatorName='): return l[l.index('=') + 1:].strip() - except exception.ProcessExecutionError: + except putils.ProcessExecutionError: + msg = (_("Could not find the iSCSI Initiator File %s") + % file_path) + LOG.warn(msg) return None def _run_iscsiadm(self, connection_properties, iscsi_command, **kwargs): @@ -508,7 +513,8 @@ def connect_volume(self, connection_properties): if len(host_devices) == 0: # this is empty because we don't have any FC HBAs msg = _("We are unable to locate any Fibre Channel devices") - raise exception.CinderException(msg) + LOG.warn(msg) + raise exceptions.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 @@ -526,8 +532,9 @@ def _wait_for_device_discovery(host_devices): raise loopingcall.LoopingCallDone() if self.tries >= CONF.num_iscsi_scan_tries: - msg = _("Fibre Channel device not found.") - raise exception.CinderException(msg) + msg = _("Fibre Channel volume device not found.") + LOG.error(msg) + raise exceptions.NoFibreChannelVolumeDeviceFound() LOG.warn(_("Fibre volume not yet found. " "Will rescan & retry. Try number: %(tries)s"), diff --git a/cinder/tests/brick/test_brick_connector.py b/cinder/tests/brick/test_brick_connector.py index d318b8fab2f..934c6c61886 100644 --- a/cinder/tests/brick/test_brick_connector.py +++ b/cinder/tests/brick/test_brick_connector.py @@ -17,12 +17,13 @@ import os.path import string +from cinder.brick import exceptions from cinder.brick.initiator import connector from cinder.brick.initiator import host_driver from cinder.brick.initiator import linuxfc from cinder.brick.initiator import linuxscsi -from cinder import exception from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils as putils from cinder import test LOG = logging.getLogger(__name__) @@ -102,7 +103,7 @@ def iscsi_connection(self, volume, location, iqn): def test_get_initiator(self): def initiator_no_file(*args, **kwargs): - raise exception.ProcessExecutionError('No file') + raise putils.ProcessExecutionError('No file') def initiator_get_text(*arg, **kwargs): text = ('## DO NOT EDIT OR REMOVE THIS FILE!\n' @@ -250,6 +251,6 @@ def test_connect_volume(self): lambda: []) self.stubs.Set(self.connector._linuxfc, 'get_fc_hbas_info', lambda: []) - self.assertRaises(exception.CinderException, + self.assertRaises(exceptions.NoFibreChannelHostsFound, self.connector.connect_volume, connection_info['data'])