self.cxt_subdir = cxt.CxtAdm.cxt_subdir
self.target = cxt.CxtAdm(root_helper=utils.get_root_helper(),
configuration=self.configuration)
- self.fake_iscsi_scan =\
+ self.VG = 'stack-volumes-lvmdriver-1'
+ self.fake_iscsi_scan = \
('\n'
- 'TARGET: iqn.2010-10.org.openstack:%s, id=1, login_ip=0\n' # noqa
+ 'TARGET: iqn.2010-10.org.openstack:%(vol)s, id=1, login_ip=0\n'
' PortalGroup=1@10.9.8.7:3260,timeout=0\n'
- ' TargetDevice=/dev/stack-volumes-lvmdriver-1/%s,BLK,PROD=CHISCSI Target,SN=0N0743000000000,ID=0D074300000000000000000,WWN=:W00743000000000\n' # noqa
- % (self.volume_name, self.volume_name))
+ ' TargetDevice=/dev/%(vg)s/%(vol)s'
+ ',BLK,PROD=CHISCSI '
+ 'Target,SN=0N0743000000000,ID=0D074300000000000000000,'
+ 'WWN=:W00743000000000\n'
+ % {'vol': self.VOLUME_NAME, 'vg': self.VG})
def test_get_target(self):
with mock.patch.object(self.target, '_get_volumes_dir',
return_value=self.fake_volumes_dir),\
mock.patch('cinder.utils.execute',
return_value=(self.fake_iscsi_scan, None)) as m_exec:
- self.assertEqual('1',
- self.target._get_target(
- 'iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45' # noqa
- ))
+ self.assertEqual(
+ '1',
+ self.target._get_target(
+ 'iqn.2010-10.org.openstack:volume-%s' % self.VOLUME_ID
+ )
+ )
self.assertTrue(m_exec.called)
def test_get_target_chap_auth(self):
tmp_file = StringIO.StringIO()
tmp_file.write(
'target:\n'
- ' TargetName=iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa
- ' TargetDevice=/dev/stack-volumes-lvmdriver-1/volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa
+ ' TargetName=iqn.2010-10.org.openstack:volume-%(id)s\n'
+ ' TargetDevice=/dev/%(vg)s/volume-%(id)s\n'
' PortalGroup=1@10.9.8.7:3260\n'
' AuthMethod=CHAP\n'
' Auth_CHAP_Policy=Oneway\n'
- ' Auth_CHAP_Initiator="otzLy2UYbYfnP4zXLG5z":"234Zweo38VGBBvrpK9nt"\n' # noqa
+ ' Auth_CHAP_Initiator="otzL":"234Z"\n' %
+ {'id': self.VOLUME_ID, 'vg': self.VG}
)
tmp_file.seek(0)
- expected = ('otzLy2UYbYfnP4zXLG5z', '234Zweo38VGBBvrpK9nt')
+ expected = ('otzL', '234Z')
with mock.patch('__builtin__.open') as mock_open:
ctx = context.get_admin_context()
mock_open.return_value = contextlib.closing(tmp_file)
1,
0,
self.fake_volumes_dir))
- mpersist_cfg.assert_called_once_with(self.volume_name)
+ mpersist_cfg.assert_called_once_with(self.VOLUME_NAME)
mexecute.assert_called_once_with(
'cinder-rtstool',
'create',
@mock.patch.object(lio.LioAdm, '_get_target', return_value=1)
def test_create_iscsi_target_port_ip(self, mget_target, mexecute,
mpersist_cfg, mlock_exec):
- test_vol = 'iqn.2010-10.org.openstack:'\
- 'volume-83c2e877-feed-46be-8435-77884fe55b45'
ip = '10.0.0.15'
port = 3261
self.assertEqual(
1,
self.target.create_iscsi_target(
- name=test_vol,
+ name=self.test_vol,
tid=1,
lun=0,
path=self.fake_volumes_dir,
'cinder-rtstool',
'create',
self.fake_volumes_dir,
- test_vol,
+ self.test_vol,
'',
'',
self.target.iscsi_protocol == 'iser',
mlock_exec.assert_any_call(*expected_args, run_as_root=True)
mexecute.assert_any_call(*expected_args, run_as_root=True)
- mpersist_cfg.assert_called_once_with(self.volume_name)
+ mpersist_cfg.assert_called_once_with(self.VOLUME_NAME)
@mock.patch.object(lio.LioAdm, '_execute', side_effect=lio.LioAdm._execute)
@mock.patch.object(lio.LioAdm, '_persist_configuration')
@mock.patch.object(lio.LioAdm, '_get_target', return_value=1)
def test_create_iscsi_target_port_ips(self, mget_target, mexecute,
mpersist_cfg, mlock_exec):
- test_vol = 'iqn.2010-10.org.openstack:'\
- 'volume-83c2e877-feed-46be-8435-77884fe55b45'
+ test_vol = 'iqn.2010-10.org.openstack:' + self.VOLUME_NAME
ips = ['10.0.0.15', '127.0.0.1']
port = 3261
mlock_exec.assert_any_call(*expected_args, run_as_root=True)
mexecute.assert_any_call(*expected_args, run_as_root=True)
- mpersist_cfg.assert_called_once_with(self.volume_name)
+ mpersist_cfg.assert_called_once_with(self.VOLUME_NAME)
@mock.patch.object(lio.LioAdm, '_execute', side_effect=lio.LioAdm._execute)
@mock.patch.object(lio.LioAdm, '_persist_configuration')
self.target = tgt.TgtAdm(root_helper=utils.get_root_helper(),
configuration=self.configuration)
self.testvol_path = \
- '/dev/stack-volumes-lvmdriver-1/'\
- 'volume-83c2e877-feed-46be-8435-77884fe55b45'
+ '/dev/stack-volumes-lvmdriver-1/%s' % self.VOLUME_NAME
self.fake_iscsi_scan =\
- ('Target 1: iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa
+ ('Target 1: %(test_vol)s\n'
' System information:\n'
' Driver: iscsi\n'
' State: ready\n'
' SWP: No\n'
' Thin-provisioning: No\n'
' Backing store type: rdwr\n'
- ' Backing store path: /dev/stack-volumes-lvmdriver-1/volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa
+ ' Backing store path: %(bspath)s\n'
' Backing store flags:\n'
' Account information:\n'
' mDVpzk8cZesdahJC9h73\n'
' ACL information:\n'
- ' ALL"\n')
+ ' ALL"\n' % {'test_vol': self.test_vol,
+ 'bspath': self.testvol_path})
def test_iscsi_protocol(self):
self.assertEqual(self.target.iscsi_protocol, 'iscsi')
def test_get_target(self):
with mock.patch('cinder.utils.execute',
return_value=(self.fake_iscsi_scan, None)):
- self.assertEqual('1',
- self.target._get_target(
- 'iqn.2010-10.org.openstack:'
- 'volume-83c2e877-feed-46be-'
- '8435-77884fe55b45'))
+ iqn = self.test_vol
+ self.assertEqual('1', self.target._get_target(iqn))
def test_verify_backing_lun(self):
+ iqn = self.test_vol
+
with mock.patch('cinder.utils.execute',
return_value=(self.fake_iscsi_scan, None)):
-
- self.assertTrue(self.target._verify_backing_lun(
- 'iqn.2010-10.org.openstack:'
- 'volume-83c2e877-feed-46be-'
- '8435-77884fe55b45', '1'))
+ self.assertTrue(self.target._verify_backing_lun(iqn, '1'))
# Test the failure case
bad_scan = self.fake_iscsi_scan.replace('LUN: 1', 'LUN: 3')
with mock.patch('cinder.utils.execute',
return_value=(bad_scan, None)):
- self.assertFalse(self.target._verify_backing_lun(
- 'iqn.2010-10.org.openstack:'
- 'volume-83c2e877-feed-46be-'
- '8435-77884fe55b45', '1'))
+ self.assertFalse(self.target._verify_backing_lun(iqn, '1'))
@mock.patch.object(time, 'sleep')
@mock.patch('cinder.utils.execute')
expected_command = ('tgtadm', '--lld', 'iscsi', '--op', 'new',
'--mode', 'logicalunit', '--tid', '1',
'--lun', '1', '-b',
- '/dev/stack-volumes-lvmdriver-1/'
- 'volume-83c2e877-feed-46be-8435-77884fe55b45')
+ self.testvol_path)
mock_execute.assert_called_once_with(*expected_command,
run_as_root=True)
def test_get_target_chap_auth(self):
persist_file =\
- '<target iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45>\n'\
- ' backing-store /dev/stack-volumes-lvmdriver-1/volume-83c2e877-feed-46be-8435-77884fe55b45\n'\
+ '<target iqn.2010-10.org.openstack:volume-%(id)s>\n'\
+ ' backing-store %(bspath)s\n'\
' driver iscsi\n'\
- ' incominguser otzLy2UYbYfnP4zXLG5z 234Zweo38VGBBvrpK9nt\n'\
+ ' incominguser otzL 234Z\n'\
' write-cache on\n'\
- '</target>'
+ '</target>' % {'id': self.VOLUME_ID,
+ 'bspath': self.testvol_path}
with open(os.path.join(self.fake_volumes_dir,
self.test_vol.split(':')[1]),
'wb') as tmp_file:
tmp_file.write(persist_file)
ctxt = context.get_admin_context()
- expected = ('otzLy2UYbYfnP4zXLG5z', '234Zweo38VGBBvrpK9nt')
+ expected = ('otzL', '234Z')
self.assertEqual(expected,
self.target._get_target_chap_auth(ctxt,
self.test_vol))
mock_exec.side_effect = _fake_execute
- test_vol_id = '83c2e877-feed-46be-8435-77884fe55b45'
- test_vol_name = 'volume-83c2e877-feed-46be-8435-77884fe55b45'
-
with mock.patch.object(self.target, '_get_target', return_value=False):
self.assertEqual(
None,
self.target.remove_iscsi_target(
1,
0,
- test_vol_id,
- test_vol_name))
+ self.VOLUME_ID,
+ self.VOLUME_NAME))
mock_exec.side_effect = _fake_execute_wrong_message
self.assertRaises(exception.ISCSITargetRemoveFailed,
self.target.remove_iscsi_target,
1,
0,
- test_vol_id,
- test_vol_name)
+ self.VOLUME_ID,
+ self.VOLUME_NAME)
@mock.patch('os.path.isfile', return_value=True)
@mock.patch('os.path.exists', return_value=True)
mock_exec.side_effect = _fake_execute
- test_vol_id = '83c2e877-feed-46be-8435-77884fe55b45'
- test_vol_name = 'volume-83c2e877-feed-46be-8435-77884fe55b45'
-
with mock.patch.object(self.target, '_get_target', return_value=False):
self.assertEqual(
None,
self.target.remove_iscsi_target(
1,
0,
- test_vol_id,
- test_vol_name))
+ self.VOLUME_ID,
+ self.VOLUME_NAME))
mock_exec.side_effect = _fake_execute_wrong_message
self.assertRaises(exception.ISCSITargetRemoveFailed,
self.target.remove_iscsi_target,
1,
0,
- test_vol_id,
- test_vol_name)
+ self.VOLUME_ID,
+ self.VOLUME_NAME)
@mock.patch.object(tgt.TgtAdm, '_get_iscsi_properties')
def test_initialize_connection(self, mock_get_iscsi):
expected_result = {'location': '10.9.8.7:3260,1 ' +
self.iscsi_target_prefix +
self.testvol['name'] + ' 1',
- 'auth': 'CHAP '
- 'QZJbisG9AL954FNF4D P68eE7u9eFqDGexd28DQ'}
+ 'auth': 'CHAP QZJb P68e'}
with mock.patch('cinder.utils.execute', return_value=('', '')),\
mock.patch.object(self.target, '_get_target',
mock.patch.object(self.target, '_get_target_chap_auth',
side_effect=lambda x, y: None) as m_chap,\
mock.patch.object(vutils, 'generate_username',
- side_effect=lambda: 'QZJbisG9AL954FNF4D'),\
+ side_effect=lambda: 'QZJb'),\
mock.patch.object(vutils, 'generate_password',
- side_effect=lambda: 'P68eE7u9eFqDGexd28DQ'):
+ side_effect=lambda: 'P68e'):
ctxt = context.get_admin_context()
self.assertEqual(expected_result,
self.testvol,
self.fake_volumes_dir))
- m_chap.side_effect = lambda x, y: ('otzLy2UYbYfnP4zXLG5z',
- '234Zweo38VGBBvrpK9nt')
+ m_chap.side_effect = lambda x, y: ('otzL', '234Z')
- expected_result['auth'] = ('CHAP '
- 'otzLy2UYbYfnP4zXLG5z '
- '234Zweo38VGBBvrpK9nt')
+ expected_result['auth'] = ('CHAP otzL 234Z')
self.assertEqual(expected_result,
self.target.create_export(ctxt,