From 7018256578e69e33ed9dee47bb72ea6011a2ce7a Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Mon, 30 Sep 2013 11:07:46 -0700 Subject: [PATCH] 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 --- cinder/brick/initiator/connector.py | 81 +++++++++++++++++------------ cinder/tests/test_coraid.py | 7 ++- cinder/tests/test_utils.py | 12 +++-- cinder/tests/test_volume.py | 6 ++- cinder/utils.py | 10 ++-- cinder/volume/driver.py | 16 ++++-- etc/cinder/cinder.conf.sample | 13 ++--- 7 files changed, 87 insertions(+), 58 deletions(-) diff --git a/cinder/brick/initiator/connector.py b/cinder/brick/initiator/connector.py index 646bb0780ad..d950575d082 100644 --- a/cinder/brick/initiator/connector.py +++ b/cinder/brick/initiator/connector.py @@ -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 @@ -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: @@ -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 @@ 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() @@ -95,26 +87,31 @@ def factory(protocol, root_helper, driver=None, 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 @@ 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. " @@ -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 @@ 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() @@ -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'] @@ -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. " @@ -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) diff --git a/cinder/tests/test_coraid.py b/cinder/tests/test_coraid.py index d646c0b9af3..9b3fe215599 100644 --- a/cinder/tests/test_coraid.py +++ b/cinder/tests/test_coraid.py @@ -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 import volume_types +CONF = cfg.CONF LOG = logging.getLogger(__name__) @@ -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) @@ -774,7 +777,8 @@ 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') @@ -782,6 +786,7 @@ def setUp(self): aoe_initiator = self.mox.CreateMockAnything() utils.brick_get_connector('aoe', + device_scan_attempts=3, use_multipath=False).\ AndReturn(aoe_initiator) diff --git a/cinder/tests/test_utils.py b/cinder/tests/test_utils.py index 5880e597ddb..5408bb30354 100644 --- a/cinder/tests/test_utils.py +++ b/cinder/tests/test_utils.py @@ -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') diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index a9cef11e11a..295dcb18cce 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -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() @@ -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() diff --git a/cinder/utils.py b/cinder/utils.py index 0ecf06426ec..f20f653736b 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -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): diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index c05be46dec9..ff3d5de4126 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -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' @@ -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'] @@ -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: @@ -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: diff --git a/etc/cinder/cinder.conf.sample b/etc/cinder/cinder.conf.sample index a839c283fe0..801af974400 100644 --- a/etc/cinder/cinder.conf.sample +++ b/etc/cinder/cinder.conf.sample @@ -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