]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Clean CONF out of brick iser
authorWalter A. Boring IV <walter.boring@hp.com>
Wed, 25 Sep 2013 21:32:32 +0000 (14:32 -0700)
committerWalter A. Boring IV <walter.boring@hp.com>
Thu, 3 Oct 2013 16:33:34 +0000 (09:33 -0700)
This is part 2 of the work needed to
remove CONF from the brick subproject.

This patch removes CONF from the iser
portion of brick

Fixes Bug #1230066

Change-Id: Id165deffdf04fb064c425861dab284de377d2440

cinder/brick/iser/iser.py
cinder/tests/test_iser.py
cinder/volume/driver.py
cinder/volume/drivers/lvm.py
etc/cinder/cinder.conf.sample

index 8fe295959541c74392c8f7381aea90d3e1ce0ded..2522b8f66966a9be8ef88e382e027ed875253c58 100644 (file)
@@ -21,8 +21,6 @@ Helper code for the iSER volume driver.
 
 import os
 
-from oslo.config import cfg
-
 from cinder.brick import exception
 from cinder.brick import executor
 from cinder.openstack.common import fileutils
@@ -32,19 +30,6 @@ from cinder.openstack.common import processutils as putils
 
 LOG = logging.getLogger(__name__)
 
-iser_helper_opt = [cfg.StrOpt('iser_helper',
-                              default='tgtadm',
-                              help='iser target user-land tool to use'),
-                   cfg.StrOpt('volumes_dir',
-                              default='$state_path/volumes',
-                              help='Volume configuration file storage '
-                                   'directory'
-                              )
-                   ]
-
-CONF = cfg.CONF
-CONF.register_opts(iser_helper_opt)
-
 
 class TargetAdmin(executor.Executor):
     """iSER target administration.
@@ -92,8 +77,11 @@ class TargetAdmin(executor.Executor):
 class TgtAdm(TargetAdmin):
     """iSER target administration using tgtadm."""
 
-    def __init__(self, root_helper, execute=putils.execute):
+    def __init__(self, root_helper, volumes_dir, execute=putils.execute,
+                 target_prefix='iqn.2010-10.org.iser.openstack:'):
         super(TgtAdm, self).__init__('tgtadm', root_helper, execute)
+        self.volumes_dir = volumes_dir
+        self.iser_target_prefix = target_prefix
 
     def _get_target(self, iqn):
         (out, err) = self._execute('tgt-admin', '--show', run_as_root=True)
@@ -111,7 +99,7 @@ class TgtAdm(TargetAdmin):
         # Note(jdg) tid and lun aren't used by TgtAdm but remain for
         # compatibility
 
-        fileutils.ensure_tree(CONF.volumes_dir)
+        fileutils.ensure_tree(self.volumes_dir)
 
         vol_id = name.split(':')[1]
         if chap_auth is None:
@@ -131,8 +119,7 @@ class TgtAdm(TargetAdmin):
             """ % (name, path, chap_auth)
 
         LOG.info(_('Creating iser_target for: %s') % vol_id)
-        volumes_dir = CONF.volumes_dir
-        volume_path = os.path.join(volumes_dir, vol_id)
+        volume_path = os.path.join(self.volumes_dir, vol_id)
 
         f = open(volume_path, 'w+')
         f.write(volume_conf)
@@ -141,7 +128,7 @@ class TgtAdm(TargetAdmin):
         old_persist_file = None
         old_name = kwargs.get('old_name', None)
         if old_name is not None:
-            old_persist_file = os.path.join(volumes_dir, old_name)
+            old_persist_file = os.path.join(self.volumes_dir, old_name)
 
         try:
             (out, err) = self._execute('tgt-admin',
@@ -157,13 +144,13 @@ class TgtAdm(TargetAdmin):
             os.unlink(volume_path)
             raise exception.ISERTargetCreateFailed(volume_id=vol_id)
 
-        iqn = '%s%s' % (CONF.iser_target_prefix, vol_id)
+        iqn = '%s%s' % (self.iser_target_prefix, vol_id)
         tid = self._get_target(iqn)
         if tid is None:
             LOG.error(_("Failed to create iser target for volume "
                         "id:%(vol_id)s. Please ensure your tgtd config file "
                         "contains 'include %(volumes_dir)s/*'") %
-                      {'vol_id': vol_id, 'volumes_dir': volumes_dir})
+                      {'vol_id': vol_id, 'volumes_dir': self.volumes_dir})
             raise exception.NotFound()
 
         if old_persist_file is not None and os.path.exists(old_persist_file):
@@ -174,9 +161,9 @@ class TgtAdm(TargetAdmin):
     def remove_iser_target(self, tid, lun, vol_id, vol_name, **kwargs):
         LOG.info(_('Removing iser_target for: %s') % vol_id)
         vol_uuid_file = vol_name
-        volume_path = os.path.join(CONF.volumes_dir, vol_uuid_file)
+        volume_path = os.path.join(self.volumes_dir, vol_uuid_file)
         if os.path.isfile(volume_path):
-            iqn = '%s%s' % (CONF.iser_target_prefix,
+            iqn = '%s%s' % (self.iser_target_prefix,
                             vol_uuid_file)
         else:
             raise exception.ISERTargetRemoveFailed(volume_id=vol_id)
@@ -217,10 +204,3 @@ class FakeIserHelper(object):
     def create_iser_target(self, *args, **kwargs):
         self.tid += 1
         return self.tid
-
-
-def get_target_admin(root_helper):
-    if CONF.iser_helper == 'fake':
-        return FakeIserHelper()
-    else:
-        return TgtAdm(root_helper)
index c958448e7ad00744aabfc4f25d13c190a92d5b87..79863712b740dff8c6cd666ae11ac294d4d51bf0 100644 (file)
@@ -20,7 +20,9 @@ import string
 import tempfile
 
 from cinder.brick.iser import iser
+from cinder.openstack.common import fileutils
 from cinder import test
+from cinder.volume import driver
 from cinder.volume import utils as volume_utils
 
 
@@ -40,6 +42,8 @@ class TargetAdminTestCase(object):
         self.stubs.Set(os.path, 'isfile', lambda _: True)
         self.stubs.Set(os, 'unlink', lambda _: '')
         self.stubs.Set(iser.TgtAdm, '_get_target', self.fake_get_target)
+        self.persist_tempdir = tempfile.mkdtemp()
+        self.driver = driver.ISERDriver()
 
     def fake_init(obj):
         return
@@ -78,7 +82,7 @@ class TargetAdminTestCase(object):
         self.verify_cmds(cmds)
 
     def run_commands(self):
-        tgtadm = iser.get_target_admin(None)
+        tgtadm = self.driver.get_target_admin()
         tgtadm.set_execute(self.fake_execute)
         tgtadm.create_iser_target(self.target_name, self.tid,
                                   self.lun, self.path)
index b31e7edf4981de7cb73752b186d9f7249c04d9e4..9fc9f85344434b6cd7ba4a2d50337b9e6239ccf1 100644 (file)
@@ -27,6 +27,7 @@ from oslo.config import cfg
 
 from cinder.brick.initiator import connector as initiator
 from cinder.brick.iscsi import iscsi
+from cinder.brick.iser import iser
 from cinder import exception
 from cinder.image import image_utils
 from cinder.openstack.common import excutils
@@ -79,6 +80,9 @@ volume_opts = [
     cfg.IntOpt('iser_port',
                default=3260,
                help='The port that the iSER daemon is listening on'),
+    cfg.StrOpt('iser_helper',
+               default='tgtadm',
+               help='iser target user-land tool to use'),
     cfg.StrOpt('volume_backend_name',
                default=None,
                help='The backend name for a given driver implementation'),
@@ -118,8 +122,6 @@ volume_opts = [
 
 CONF = cfg.CONF
 CONF.register_opts(volume_opts)
-CONF.import_opt('iscsi_helper', 'cinder.brick.iscsi.iscsi')
-CONF.import_opt('iser_helper', 'cinder.brick.iser.iser')
 
 
 class VolumeDriver(object):
@@ -988,6 +990,15 @@ class ISERDriver(ISCSIDriver):
         data['QoS_support'] = False
         self._stats = data
 
+    def get_target_admin(self):
+        root_helper = utils.get_root_helper()
+
+        if CONF.iser_helper == 'fake':
+            return iser.FakeIserHelper()
+        else:
+            return iser.TgtAdm(root_helper,
+                               CONF.volumes_dir)
+
 
 class FakeISERDriver(FakeISCSIDriver):
     """Logs calls instead of executing."""
index 905543dd628a6dd35f705716d8015b171c7c968a..862fe238f118995f069b21a04c7274d8fdad969a 100644 (file)
@@ -56,7 +56,6 @@ volume_opts = [
     cfg.StrOpt('lvm_type',
                default='default',
                help='Type of LVM volumes to deploy; (default or thin)'),
-
 ]
 
 CONF = cfg.CONF
@@ -748,12 +747,12 @@ class LVMISERDriver(LVMISCSIDriver, driver.ISERDriver):
     """
 
     def __init__(self, *args, **kwargs):
-        root_helper = utils.get_root_helper()
-        self.tgtadm = iser.get_target_admin(root_helper)
+        self.tgtadm = self.get_target_admin()
         LVMVolumeDriver.__init__(self, *args, **kwargs)
         self.backend_name =\
             self.configuration.safe_get('volume_backend_name') or 'LVM_iSER'
         self.protocol = 'iSER'
+        self.tgtadm.set_execute(self._execute)
 
     def set_execute(self, execute):
         LVMVolumeDriver.set_execute(self, execute)
index b43424b203975882cfd28dc92be4920365c20297..df1d31f109d3b834551c588ac6ecb950140e81b7 100644 (file)
 #backup_driver=cinder.backup.drivers.swift
 
 
-#
-# Options defined in cinder.brick.iser.iser
-#
-
-# iser target user-land tool to use (string value)
-#iser_helper=tgtadm
-
-# Volume configuration file storage directory (string value)
-#volumes_dir=$state_path/volumes
-
-
 #
 # Options defined in cinder.common.config
 #
 # value)
 #iser_port=3260
 
+# iser target user-land tool to use (string value)
+#iser_helper=tgtadm
+
 # The backend name for a given driver implementation (string
 # value)
 #volume_backend_name=<None>
 #volume_dd_blocksize=1M
 
 
-# Total option count: 382
+# Total option count: 381