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