]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Clean CONF out of brick initiator
authorWalter A. Boring IV <walter.boring@hp.com>
Mon, 30 Sep 2013 18:07:46 +0000 (11:07 -0700)
committerChet Burgess <cfb@metacloud.com>
Tue, 1 Oct 2013 23:24:16 +0000 (16:24 -0700)
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
cinder/tests/test_coraid.py
cinder/tests/test_utils.py
cinder/tests/test_volume.py
cinder/utils.py
cinder/volume/driver.py
etc/cinder/cinder.conf.sample

index 646bb0780ad1f207b83eb39fbb97677790ada82a..d950575d0822404c90aa357395d3a7fcace6813a 100644 (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)
index d646c0b9af3e4a4828a083160fbcb2df781be4ac..9b3fe215599cd2242d54d30ab3a66b52d1024277 100644 (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)
 
index 5880e597ddba29c6a20faefb8c7651da636b883c..5408bb30354d37ae59dbede2986816f00b156e13 100644 (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')
index a9cef11e11a175ebe1d754933cf701adfbf5cc14..295dcb18cce56c2c7aef75128111320d934fba69 100644 (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()
index 0ecf06426ec44071e86179640c14bd9368dddf93..f20f653736b1377dfbddafac16beb09431f11e0f 100644 (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):
index c05be46dec947ddf1260e5660b411e6f55511d30..ff3d5de4126b1c442f63d7a5bfe7a502a044606b 100644 (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:
index a839c283fe0a8927bdea5bb7abc6f4cb98b7f8ac..801af9744009c3c3ed17940b9546aa2479203620 100644 (file)
 #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
 #
 # 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