Skip to content

Commit

Permalink
Remove cinder.exception from Brick
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hemna committed Aug 5, 2013
1 parent cb93100 commit 23b3a23
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
35 changes: 35 additions & 0 deletions 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)
25 changes: 16 additions & 9 deletions cinder/brick/initiator/connector.py
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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"),
Expand Down
7 changes: 4 additions & 3 deletions cinder/tests/brick/test_brick_connector.py
Expand Up @@ -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__)
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'])

0 comments on commit 23b3a23

Please sign in to comment.