Skip to content

Commit

Permalink
Clean CONF out of brick initiator
Browse files Browse the repository at this point in the history
This is part 1 of the work needed to
remove CONF from the brick subproject.
This patch removes the CONF usage
completely from the initiator portion of brick.

Change-Id: I62cf72214db9d4296ae4c5b09bd21fb53664c117
Partial-Bug: #1230066
  • Loading branch information
hemna authored and Chet Burgess committed Oct 1, 2013
1 parent a2673b0 commit 7018256
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 58 deletions.
81 changes: 47 additions & 34 deletions cinder/brick/initiator/connector.py
Expand Up @@ -19,8 +19,6 @@
import socket
import time

from oslo.config import cfg

from cinder.brick import exception
from cinder.brick import executor
from cinder.brick.initiator import host_driver
Expand All @@ -35,28 +33,18 @@

LOG = logging.getLogger(__name__)

connector_opts = [
cfg.IntOpt('num_volume_device_scan_tries',
deprecated_name='num_iscsi_scan_tries',
default=3,
help='The maximum number of times to rescan targets'
'to find volume'),
]

CONF = cfg.CONF
CONF.register_opts(connector_opts)

synchronized = lockutils.synchronized_with_prefix('brick-')
DEVICE_SCAN_ATTEMPTS_DEFAULT = 3


def get_connector_properties(root_helper):
def get_connector_properties(root_helper, my_ip):
"""Get the connection properties for all protocols."""

iscsi = ISCSIConnector(root_helper=root_helper)
fc = linuxfc.LinuxFibreChannel(root_helper=root_helper)

props = {}
props['ip'] = CONF.my_ip
props['ip'] = my_ip
props['host'] = socket.gethostname()
initiator = iscsi.get_initiator()
if initiator:
Expand All @@ -73,12 +61,15 @@ def get_connector_properties(root_helper):

class InitiatorConnector(executor.Executor):
def __init__(self, root_helper, driver=None,
execute=putils.execute, *args, **kwargs):
execute=putils.execute,
device_scan_attempts=DEVICE_SCAN_ATTEMPTS_DEFAULT,
*args, **kwargs):
super(InitiatorConnector, self).__init__(root_helper, execute=execute,
*args, **kwargs)
if not driver:
driver = host_driver.HostDriver()
self.set_driver(driver)
self.device_scan_attempts = device_scan_attempts

def set_driver(self, driver):
"""The driver is used to find used LUNs."""
Expand All @@ -87,34 +78,40 @@ def set_driver(self, driver):

@staticmethod
def factory(protocol, root_helper, driver=None,
execute=putils.execute, use_multipath=False):
execute=putils.execute, use_multipath=False,
device_scan_attempts=DEVICE_SCAN_ATTEMPTS_DEFAULT):
"""Build a Connector object based upon protocol."""
LOG.debug("Factory for %s" % protocol)
protocol = protocol.upper()
if protocol == "ISCSI":
return ISCSIConnector(root_helper=root_helper,
driver=driver,
execute=execute,
use_multipath=use_multipath)
use_multipath=use_multipath,
device_scan_attempts=device_scan_attempts)
elif protocol == "FIBRE_CHANNEL":
return FibreChannelConnector(root_helper=root_helper,
driver=driver,
execute=execute,
use_multipath=use_multipath)
use_multipath=use_multipath,
device_scan_attempts=
device_scan_attempts)
elif protocol == "AOE":
return AoEConnector(root_helper=root_helper,
driver=driver,
execute=execute)
execute=execute,
device_scan_attempts=device_scan_attempts)
elif protocol == "NFS" or protocol == "GLUSTERFS":
return RemoteFsConnector(mount_type=protocol.lower(),
root_helper=root_helper,
driver=driver,
execute=execute)

execute=execute,
device_scan_attempts=device_scan_attempts)
elif protocol == "LOCAL":
return LocalConnector(root_helper=root_helper,
driver=driver,
execute=execute)
execute=execute,
device_scan_attempts=device_scan_attempts)
else:
msg = (_("Invalid InitiatorConnector protocol "
"specified %(protocol)s") %
Expand Down Expand Up @@ -161,10 +158,14 @@ class ISCSIConnector(InitiatorConnector):

def __init__(self, root_helper, driver=None,
execute=putils.execute, use_multipath=False,
device_scan_attempts=DEVICE_SCAN_ATTEMPTS_DEFAULT,
*args, **kwargs):
self._linuxscsi = linuxscsi.LinuxSCSI(root_helper, execute)
super(ISCSIConnector, self).__init__(root_helper, driver=driver,
execute=execute, *args, **kwargs)
execute=execute,
device_scan_attempts=
device_scan_attempts,
*args, **kwargs)
self.use_multipath = use_multipath

def set_execute(self, execute):
Expand Down Expand Up @@ -210,7 +211,7 @@ def connect_volume(self, connection_properties):
# TODO(justinsb): This retry-with-delay is a pattern, move to utils?
tries = 0
while not os.path.exists(host_device):
if tries >= CONF.num_volume_device_scan_tries:
if tries >= self.device_scan_attempts:
raise exception.VolumeDeviceNotFound(device=host_device)

LOG.warn(_("ISCSI volume not yet found at: %(host_device)s. "
Expand Down Expand Up @@ -499,12 +500,15 @@ class FibreChannelConnector(InitiatorConnector):

def __init__(self, root_helper, driver=None,
execute=putils.execute, use_multipath=False,
device_scan_attempts=DEVICE_SCAN_ATTEMPTS_DEFAULT,
*args, **kwargs):
self._linuxscsi = linuxscsi.LinuxSCSI(root_helper, execute)
self._linuxfc = linuxfc.LinuxFibreChannel(root_helper, execute)
super(FibreChannelConnector, self).__init__(root_helper, driver=driver,
execute=execute, *args,
**kwargs)
execute=execute,
device_scan_attempts=
device_scan_attempts,
*args, **kwargs)
self.use_multipath = use_multipath

def set_execute(self, execute):
Expand Down Expand Up @@ -570,7 +574,7 @@ def _wait_for_device_discovery(host_devices):
self.device_name = os.path.realpath(device)
raise loopingcall.LoopingCallDone()

if self.tries >= CONF.num_volume_device_scan_tries:
if self.tries >= self.device_scan_attempts:
msg = _("Fibre Channel volume device not found.")
LOG.error(msg)
raise exception.NoFibreChannelVolumeDeviceFound()
Expand Down Expand Up @@ -670,9 +674,14 @@ def _get_pci_num(self, hba):
class AoEConnector(InitiatorConnector):
"""Connector class to attach/detach AoE volumes."""
def __init__(self, root_helper, driver=None,
execute=putils.execute, *args, **kwargs):
execute=putils.execute,
device_scan_attempts=DEVICE_SCAN_ATTEMPTS_DEFAULT,
*args, **kwargs):
super(AoEConnector, self).__init__(root_helper, driver=driver,
execute=execute, *args, **kwargs)
execute=execute,
device_scan_attempts=
device_scan_attempts,
*args, **kwargs)

def _get_aoe_info(self, connection_properties):
shelf = connection_properties['target_shelf']
Expand Down Expand Up @@ -710,7 +719,7 @@ def _wait_for_discovery(aoe_path):
if os.path.exists(aoe_path):
raise loopingcall.LoopingCallDone

if waiting_status['tries'] >= CONF.num_volume_device_scan_tries:
if waiting_status['tries'] >= self.device_scan_attempts:
raise exception.VolumeDeviceNotFound(device=aoe_path)

LOG.warn(_("AoE volume not yet found at: %(path)s. "
Expand Down Expand Up @@ -779,12 +788,16 @@ class RemoteFsConnector(InitiatorConnector):
"""Connector class to attach/detach NFS and GlusterFS volumes."""

def __init__(self, mount_type, root_helper, driver=None,
execute=putils.execute, *args, **kwargs):
execute=putils.execute,
device_scan_attempts=DEVICE_SCAN_ATTEMPTS_DEFAULT,
*args, **kwargs):
self._remotefsclient = remotefs.RemoteFsClient(mount_type, root_helper,
execute=execute)
super(RemoteFsConnector, self).__init__(root_helper, driver=driver,
execute=execute, *args,
**kwargs)
execute=execute,
device_scan_attempts=
device_scan_attempts,
*args, **kwargs)

def set_execute(self, execute):
super(RemoteFsConnector, self).set_execute(execute)
Expand Down
7 changes: 6 additions & 1 deletion cinder/tests/test_coraid.py
Expand Up @@ -18,6 +18,7 @@
import math

import mox
from oslo.config import cfg

from cinder.brick.initiator import connector
from cinder import exception
Expand All @@ -32,6 +33,7 @@
from cinder.volume import volume_types


CONF = cfg.CONF
LOG = logging.getLogger(__name__)


Expand Down Expand Up @@ -242,6 +244,7 @@ def setUp(self):
configuration.snapshot_name_template = "snapshot-%s"
configuration.coraid_repository_key = fake_coraid_repository_key
configuration.use_multipath_for_image_xfer = False
configuration.num_volume_device_scan_tries = 3
self.fake_rpc = FakeRpc()

self.stubs.Set(coraid.CoraidRESTClient, 'rpc', self.fake_rpc)
Expand Down Expand Up @@ -774,14 +777,16 @@ def setUp(self):
root_helper = 'sudo cinder-rootwrap /etc/cinder/rootwrap.conf'

self.mox.StubOutWithMock(connector, 'get_connector_properties')
connector.get_connector_properties(root_helper).\
connector.get_connector_properties(root_helper,
CONF.my_ip).\
AndReturn({})

self.mox.StubOutWithMock(utils, 'brick_get_connector')

aoe_initiator = self.mox.CreateMockAnything()

utils.brick_get_connector('aoe',
device_scan_attempts=3,
use_multipath=False).\
AndReturn(aoe_initiator)

Expand Down
12 changes: 8 additions & 4 deletions cinder/tests/test_utils.py
Expand Up @@ -791,23 +791,27 @@ def test_brick_get_connector(self):
connector.ISCSIConnector(execute=putils.execute,
driver=None,
root_helper=root_helper,
use_multipath=False)
use_multipath=False,
device_scan_attempts=3)

self.mox.StubOutClassWithMocks(connector, 'FibreChannelConnector')
connector.FibreChannelConnector(execute=putils.execute,
driver=None,
root_helper=root_helper,
use_multipath=False)
use_multipath=False,
device_scan_attempts=3)

self.mox.StubOutClassWithMocks(connector, 'AoEConnector')
connector.AoEConnector(execute=putils.execute,
driver=None,
root_helper=root_helper)
root_helper=root_helper,
device_scan_attempts=3)

self.mox.StubOutClassWithMocks(connector, 'LocalConnector')
connector.LocalConnector(execute=putils.execute,
driver=None,
root_helper=root_helper)
root_helper=root_helper,
device_scan_attempts=3)

self.mox.ReplayAll()
utils.brick_get_connector('iscsi')
Expand Down
6 changes: 4 additions & 2 deletions cinder/tests/test_volume.py
Expand Up @@ -2008,7 +2008,8 @@ def test_backup_volume(self):
self.volume.driver.db.volume_get(self.context, vol['id']).\
AndReturn(vol)
cinder.brick.initiator.connector.\
get_connector_properties(root_helper).AndReturn(properties)
get_connector_properties(root_helper, CONF.my_ip).\
AndReturn(properties)
self.volume.driver._attach_volume(self.context, vol, properties).\
AndReturn(attach_info)
os.getuid()
Expand Down Expand Up @@ -2040,7 +2041,8 @@ def test_restore_backup(self):
self.mox.StubOutWithMock(self.volume.driver, 'terminate_connection')

cinder.brick.initiator.connector.\
get_connector_properties(root_helper).AndReturn(properties)
get_connector_properties(root_helper, CONF.my_ip).\
AndReturn(properties)
self.volume.driver._attach_volume(self.context, vol, properties).\
AndReturn(attach_info)
os.getuid()
Expand Down
10 changes: 7 additions & 3 deletions cinder/utils.py
Expand Up @@ -776,12 +776,14 @@ def brick_get_connector_properties():
"""

root_helper = get_root_helper()
return connector.get_connector_properties(root_helper)
return connector.get_connector_properties(root_helper,
CONF.my_ip)


def brick_get_connector(protocol, driver=None,
execute=processutils.execute,
use_multipath=False):
use_multipath=False,
device_scan_attempts=3):
"""Wrapper to get a brick connector object.
This automatically populates the required protocol as well
as the root_helper needed to execute commands.
Expand All @@ -791,7 +793,9 @@ def brick_get_connector(protocol, driver=None,
return connector.InitiatorConnector.factory(protocol, root_helper,
driver=driver,
execute=execute,
use_multipath=use_multipath)
use_multipath=use_multipath,
device_scan_attempts=
device_scan_attempts)


def require_driver_initialized(func):
Expand Down
16 changes: 11 additions & 5 deletions cinder/volume/driver.py
Expand Up @@ -57,6 +57,11 @@
cfg.IntOpt('iscsi_port',
default=3260,
help='The port that the iSCSI daemon is listening on'),
cfg.IntOpt('num_volume_device_scan_tries',
deprecated_name='num_iscsi_scan_tries',
default=3,
help='The maximum number of times to rescan targets'
' to find volume'),
cfg.IntOpt('num_iser_scan_tries',
default=3,
help='The maximum number of times to rescan iSER target'
Expand Down Expand Up @@ -341,9 +346,12 @@ def _attach_volume(self, context, volume, properties, remote=False):

# Use Brick's code to do attach/detach
use_multipath = self.configuration.use_multipath_for_image_xfer
device_scan_attempts = self.configuration.num_volume_device_scan_tries
protocol = conn['driver_volume_type']
connector = utils.brick_get_connector(protocol,
use_multipath=use_multipath)
use_multipath=use_multipath,
device_scan_attempts=
device_scan_attempts)
device = connector.connect_volume(conn['data'])
host_device = device['path']

Expand Down Expand Up @@ -386,8 +394,7 @@ def backup_volume(self, context, backup, backup_service):
LOG.debug(_('Creating a new backup for volume %s.') %
volume['name'])

root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
properties = initiator.get_connector_properties(root_helper)
properties = utils.brick_get_connector_properties()
attach_info = self._attach_volume(context, volume, properties)

try:
Expand All @@ -407,8 +414,7 @@ def restore_backup(self, context, backup, volume, backup_service):
{'backup': backup['id'],
'volume': volume['name']})

root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
properties = initiator.get_connector_properties(root_helper)
properties = utils.brick_get_connector_properties()
attach_info = self._attach_volume(context, volume, properties)

try:
Expand Down
13 changes: 4 additions & 9 deletions etc/cinder/cinder.conf.sample
Expand Up @@ -234,15 +234,6 @@
#backup_driver=cinder.backup.drivers.swift


#
# Options defined in cinder.brick.initiator.connector
#

# The maximum number of times to rescan targetsto find volume
# (integer value)
#num_volume_device_scan_tries=3


#
# Options defined in cinder.brick.iscsi.iscsi
#
Expand Down Expand Up @@ -1084,6 +1075,10 @@
# value)
#iscsi_port=3260

# The maximum number of times to rescan targets to find volume
# (integer value)
#num_volume_device_scan_tries=3

# The maximum number of times to rescan iSER targetto find
# volume (integer value)
#num_iser_scan_tries=3
Expand Down

0 comments on commit 7018256

Please sign in to comment.