from cinder import test
from cinder.volume import iscsi
+from cinder.volume import utils as volume_utils
class TargetAdminTestCase(object):
'ietadm --op delete --tid=%(tid)s'])
+class IetAdmBlockIOTestCase(test.TestCase, TargetAdminTestCase):
+
+ def setUp(self):
+ super(IetAdmBlockIOTestCase, self).setUp()
+ TargetAdminTestCase.setUp(self)
+ self.flags(iscsi_helper='ietadm')
+ self.flags(iscsi_iotype='blockio')
+ self.script_template = "\n".join([
+ 'ietadm --op new --tid=%(tid)s --params Name=%(target_name)s',
+ 'ietadm --op new --tid=%(tid)s --lun=%(lun)s '
+ '--params Path=%(path)s,Type=blockio',
+ 'ietadm --op show --tid=%(tid)s',
+ 'ietadm --op delete --tid=%(tid)s --lun=%(lun)s',
+ 'ietadm --op delete --tid=%(tid)s'])
+
+
+class IetAdmFileIOTestCase(test.TestCase, TargetAdminTestCase):
+
+ def setUp(self):
+ super(IetAdmFileIOTestCase, self).setUp()
+ TargetAdminTestCase.setUp(self)
+ self.flags(iscsi_helper='ietadm')
+ self.flags(iscsi_iotype='fileio')
+ self.script_template = "\n".join([
+ 'ietadm --op new --tid=%(tid)s --params Name=%(target_name)s',
+ 'ietadm --op new --tid=%(tid)s --lun=%(lun)s '
+ '--params Path=%(path)s,Type=fileio',
+ 'ietadm --op show --tid=%(tid)s',
+ 'ietadm --op delete --tid=%(tid)s --lun=%(lun)s',
+ 'ietadm --op delete --tid=%(tid)s'])
+
+
+class IetAdmAutoIOTestCase(test.TestCase, TargetAdminTestCase):
+
+ def setUp(self):
+ super(IetAdmAutoIOTestCase, self).setUp()
+ TargetAdminTestCase.setUp(self)
+ self.stubs.Set(volume_utils, 'is_block', lambda _: True)
+ self.flags(iscsi_helper='ietadm')
+ self.flags(iscsi_iotype='auto')
+ self.script_template = "\n".join([
+ 'ietadm --op new --tid=%(tid)s --params Name=%(target_name)s',
+ 'ietadm --op new --tid=%(tid)s --lun=%(lun)s '
+ '--params Path=%(path)s,Type=blockio',
+ 'ietadm --op show --tid=%(tid)s',
+ 'ietadm --op delete --tid=%(tid)s --lun=%(lun)s',
+ 'ietadm --op delete --tid=%(tid)s'])
+
+
class LioAdmTestCase(test.TestCase, TargetAdminTestCase):
def setUp(self):
from cinder import flags
from cinder.openstack.common import log as logging
from cinder import utils
+from cinder.volume import utils as volume_utils
LOG = logging.getLogger(__name__)
'allowed to connect to the '
'iSCSI target. (From Nova compute nodes.)'
)
+ ),
+ cfg.StrOpt('iscsi_iotype',
+ default='fileio',
+ help=('Sets the behavior of the iSCSI target to'
+ 'either perform blockio or fileio'
+ 'optionally, auto can be set and Cinder'
+ 'will autodetect type of backing device')
)
]
def __init__(self, execute=utils.execute):
super(IetAdm, self).__init__('ietadm', execute)
+ def _iotype(self, path):
+ if FLAGS.iscsi_iotype == 'auto':
+ return 'blockio' if volume_utils.is_block(path) else 'fileio'
+ else:
+ return FLAGS.iscsi_iotype
+
def create_iscsi_target(self, name, tid, lun, path,
chap_auth=None, **kwargs):
self._new_target(name, tid, **kwargs)
volume_conf = """
Target %s
%s
- Lun 0 Path=%s,Type=fileio
- """ % (name, chap_auth, path)
+ Lun 0 Path=%s,Type=%s
+ """ % (name, chap_auth, path, self._iotype(path))
with utils.temporary_chown(conf_file):
f = open(conf_file, 'a+')
self._run('--op', 'new',
'--tid=%s' % tid,
'--lun=%d' % lun,
- '--params', 'Path=%s,Type=fileio' % path,
+ '--params', 'Path=%s,Type=%s' % (path, self._iotype(path)),
**kwargs)
def _delete_logicalunit(self, tid, lun, **kwargs):
"""Volume-related Utilities and helpers."""
+import os
+import stat
+
from cinder import flags
from cinder.openstack.common import log as logging
from cinder.openstack.common.notifier import api as notifier_api
notifier_api.notify(context, 'snapshot.%s' % host,
'snapshot.%s' % event_suffix,
notifier_api.INFO, usage_info)
+
+
+def is_block(path):
+ mode = os.stat(path).st_mode
+ return stat.S_ISBLK(mode)
# the iSCSI target. (From Nova compute nodes.) (string value)
#lio_initiator_iqns=
+# The type of IO the iSCSI target will issue to the backend storage.
+# This option only currently works with IET.
+# Valid settings are 'blockio','fileio' and 'auto' which will autodetect
+# the type of file provided to the target. (string value)
+# iscsi_iotype=fileio
#
# Options defined in cinder.volume.manager