From: Walter A. Boring IV Date: Wed, 25 Sep 2013 21:32:32 +0000 (-0700) Subject: Clean CONF out of brick iser X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=e01eba47b94c3cbb41491acdbcabd9ba14936be6;p=openstack-build%2Fcinder-build.git Clean CONF out of brick iser 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 --- diff --git a/cinder/brick/iser/iser.py b/cinder/brick/iser/iser.py index 8fe295959..2522b8f66 100644 --- a/cinder/brick/iser/iser.py +++ b/cinder/brick/iser/iser.py @@ -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) diff --git a/cinder/tests/test_iser.py b/cinder/tests/test_iser.py index c958448e7..79863712b 100644 --- a/cinder/tests/test_iser.py +++ b/cinder/tests/test_iser.py @@ -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) diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index b31e7edf4..9fc9f8534 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -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.""" diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py index 905543dd6..862fe238f 100644 --- a/cinder/volume/drivers/lvm.py +++ b/cinder/volume/drivers/lvm.py @@ -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) diff --git a/etc/cinder/cinder.conf.sample b/etc/cinder/cinder.conf.sample index b43424b20..df1d31f10 100644 --- a/etc/cinder/cinder.conf.sample +++ b/etc/cinder/cinder.conf.sample @@ -234,17 +234,6 @@ #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 # @@ -1067,6 +1056,9 @@ # 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= @@ -1778,4 +1770,4 @@ #volume_dd_blocksize=1M -# Total option count: 382 +# Total option count: 381