]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove cinder.exception from Brick
authorWalter A. Boring IV <walter.boring@hp.com>
Mon, 29 Jul 2013 23:21:46 +0000 (16:21 -0700)
committerWalter A. Boring IV <walter.boring@hp.com>
Mon, 5 Aug 2013 20:30:16 +0000 (13:30 -0700)
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 [new file with mode: 0644]
cinder/brick/initiator/connector.py
cinder/tests/brick/test_brick_connector.py

diff --git a/cinder/brick/exceptions.py b/cinder/brick/exceptions.py
new file mode 100644 (file)
index 0000000..d046e3f
--- /dev/null
@@ -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)
index dfb50cb70514c33d996047916cb1e6e41db3d188..44d4698f9bbfbd1363c2b74fcba4aca66857146a 100644 (file)
@@ -25,7 +25,7 @@ import time
 
 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 @@ class InitiatorConnector(executor.Executor):
         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 @@ class ISCSIConnector(InitiatorConnector):
         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 @@ class ISCSIConnector(InitiatorConnector):
 
     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 @@ class FibreChannelConnector(InitiatorConnector):
         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 @@ class FibreChannelConnector(InitiatorConnector):
                     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"),
index d318b8fab2f41ed586aa417d67c431afa2d01a62..934c6c61886cd995043738ddf3096f60e6cae8f9 100644 (file)
 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 @@ class ISCSIConnectorTestCase(ConnectorTestCase):
 
     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 @@ class FibreChannelConnectorTestCase(ConnectorTestCase):
                        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'])