import stat
import time
+import six
+
from cinder.brick import exception
from cinder.brick import executor
from cinder.i18n import _
def _run(self, *args, **kwargs):
self._execute(self._cmd, *args, run_as_root=True, **kwargs)
+ def _get_target_chap_auth(self, volume_id):
+ """Get the current chap auth username and password."""
+ return None
+
def create_iscsi_target(self, name, tid, lun, path,
chap_auth=None, **kwargs):
"""Create an iSCSI target and logical unit."""
"id:%(vol_id)s: %(e)s")
% {'vol_id': name, 'e': e})
+ def _get_target_chap_auth(self, name):
+ volumes_dir = self.volumes_dir
+ vol_id = name.split(':')[1]
+ volume_path = os.path.join(volumes_dir, vol_id)
+
+ try:
+ with open(volume_path, 'r') as f:
+ volume_conf = f.read()
+ except Exception as e:
+ LOG.debug('Failed to open config for %(vol_id)s: %(e)s'
+ % {'vol_id': vol_id, 'e': six.text_type(e)})
+ return None
+
+ m = re.search('incominguser (\w+) (\w+)', volume_conf)
+ if m:
+ return (m.group(1), m.group(2))
+ LOG.debug('Failed to find CHAP auth from config for %s' % vol_id)
+ return None
+
def create_iscsi_target(self, name, tid, lun, path,
chap_auth=None, **kwargs):
# Note(jdg) tid and lun aren't used by TgtAdm but remain for
LOG.info(_('Creating iscsi_target for volume: %s') % vol_id)
- # rtstool requires chap_auth, but unit tests don't provide it
- chap_auth_userid = 'test_id'
- chap_auth_password = 'test_pass'
-
if chap_auth is not None:
(chap_auth_userid, chap_auth_password) = chap_auth.split(' ')[1:]
self.path = '/foo'
self.vol_id = 'blaa'
self.vol_name = 'volume-blaa'
+ self.chap_username = 'test_id'
+ self.chap_password = 'test_pass'
self.write_cache = 'off'
self.db = {}
return {'tid': self.tid,
'target_name': self.target_name,
'lun': self.lun,
- 'path': self.path}
+ 'path': self.path,
+ 'username': self.chap_username,
+ 'password': self.chap_password}
def get_script(self):
return self.script_template % self.get_script_params()
def clear_cmds(self):
self.cmds = []
+ def verify_config(self):
+ pass
+
def verify_cmds(self, cmds):
self.assertEqual(len(cmds), len(self.cmds))
for cmd in self.cmds:
self.assertTrue(cmd in cmds)
+ self.verify_config()
def verify(self):
script = self.get_script()
def run_commands(self):
target_helper = self.driver.get_target_helper(self.db)
target_helper.set_execute(self.fake_execute)
+ chap_auth = target_helper._iscsi_authentication('IncomingUser',
+ self.chap_username,
+ self.chap_password)
target_helper.create_iscsi_target(self.target_name, self.tid,
- self.lun, self.path,
+ self.lun, self.path, chap_auth,
write_cache=self.write_cache)
target_helper.show_target(self.tid, iqn=self.target_name)
target_helper.remove_iscsi_target(self.tid, self.lun, self.vol_id,
'--delete %(target_name)s',
'tgtadm --lld iscsi --op show --mode target'])
+ def verify_config(self):
+ target_helper = self.driver.get_target_helper(self.db)
+ self.assertEqual(target_helper._get_target_chap_auth(self.target_name),
+ (self.chap_username, self.chap_password))
+
class IetAdmTestCase(test.TestCase, TargetAdminTestCase):
'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 new --tid=%(tid)s --user '
+ '--params=IncomingUser=%(username)s,Password=%(password)s',
'ietadm --op show --tid=%(tid)s',
'ietadm --op delete --tid=%(tid)s --lun=%(lun)s',
'ietadm --op delete --tid=%(tid)s'])
'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 new --tid=%(tid)s --user '
+ '--params=IncomingUser=%(username)s,Password=%(password)s',
'ietadm --op show --tid=%(tid)s',
'ietadm --op delete --tid=%(tid)s --lun=%(lun)s',
'ietadm --op delete --tid=%(tid)s'])
'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 new --tid=%(tid)s --user '
+ '--params=IncomingUser=%(username)s,Password=%(password)s',
'ietadm --op show --tid=%(tid)s',
'ietadm --op delete --tid=%(tid)s --lun=%(lun)s',
'ietadm --op delete --tid=%(tid)s'])
'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 new --tid=%(tid)s --user '
+ '--params=IncomingUser=%(username)s,Password=%(password)s',
'ietadm --op show --tid=%(tid)s',
'ietadm --op delete --tid=%(tid)s --lun=%(lun)s',
'ietadm --op delete --tid=%(tid)s'])
self.flags(iscsi_helper='lioadm')
self.script_template = "\n".join([
'cinder-rtstool create '
- '%(path)s %(target_name)s test_id test_pass',
+ '%(path)s %(target_name)s %(username)s %(password)s',
'cinder-rtstool delete %(target_name)s'])