Clean CONF out of brick initiator

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
This commit is contained in:
Walter A. Boring IV 2013-09-30 11:07:46 -07:00 committed by Chet Burgess
parent a2673b0feb
commit 7018256578
7 changed files with 87 additions and 58 deletions

View File

@ -19,8 +19,6 @@ import os
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
@ -35,28 +33,18 @@ from cinder.openstack.common import processutils as putils
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:
@ -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."""
@ -87,7 +78,8 @@ class InitiatorConnector(executor.Executor):
@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()
@ -95,26 +87,31 @@ class InitiatorConnector(executor.Executor):
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") %
@ -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):
@ -210,7 +211,7 @@ class ISCSIConnector(InitiatorConnector):
# 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. "
@ -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):
@ -570,7 +574,7 @@ class FibreChannelConnector(InitiatorConnector):
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()
@ -670,9 +674,14 @@ class FibreChannelConnector(InitiatorConnector):
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']
@ -710,7 +719,7 @@ class AoEConnector(InitiatorConnector):
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. "
@ -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)

View File

@ -18,6 +18,7 @@
import math
import mox
from oslo.config import cfg
from cinder.brick.initiator import connector
from cinder import exception
@ -32,6 +33,7 @@ from cinder.volume.drivers import coraid
from cinder.volume import volume_types
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
@ -242,6 +244,7 @@ class CoraidDriverTestCase(test.TestCase):
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)
@ -774,7 +777,8 @@ class CoraidDriverImageTestCases(CoraidDriverTestCase):
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')
@ -782,6 +786,7 @@ class CoraidDriverImageTestCases(CoraidDriverTestCase):
aoe_initiator = self.mox.CreateMockAnything()
utils.brick_get_connector('aoe',
device_scan_attempts=3,
use_multipath=False).\
AndReturn(aoe_initiator)

View File

@ -791,23 +791,27 @@ class BrickUtils(test.TestCase):
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')

View File

@ -2008,7 +2008,8 @@ class GenericVolumeDriverTestCase(DriverTestCase):
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()
@ -2040,7 +2041,8 @@ class GenericVolumeDriverTestCase(DriverTestCase):
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()

View File

@ -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.
@ -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):

View File

@ -57,6 +57,11 @@ volume_opts = [
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'
@ -341,9 +346,12 @@ class VolumeDriver(object):
# 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']
@ -386,8 +394,7 @@ class VolumeDriver(object):
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:
@ -407,8 +414,7 @@ class VolumeDriver(object):
{'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:

View File

@ -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
#
@ -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