import os
-from oslo.config import cfg
-
from cinder.brick import exception
from cinder.brick import executor
from cinder.openstack.common import fileutils
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.
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)
# 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:
""" % (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)
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',
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):
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)
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)
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
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
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)
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
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'),
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):
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."""