TgtAdm: Don't change CHAP username/password on live migration

This fixes TgtAdm Target Objects not to regenerate random
username/password every time initialize_connection is called,
as TgtAdm doesn't accept the change while the initiator is
connected. This fixes the live-migration of nova instances which
have volumes attached.

Change-Id: I1b48a66da5a0d8726490f50c2ee58352c42d9587
Closes-Bug: #1408162
Related-Bug: #1383509
This commit is contained in:
Tomoki Sekiyama 2015-01-06 19:58:13 -05:00
parent 29f9fa9f2a
commit 9df3bcead5
5 changed files with 34 additions and 2 deletions

View File

@ -49,6 +49,9 @@ class TestLioAdmDriver(test_tgt.TestTgtAdmDriver):
def test_verify_backing_lun(self):
pass
def test_get_target_chap_auth(self):
pass
def test_create_iscsi_target_already_exists(self):
def _fake_execute(*args, **kwargs):
raise putils.ProcessExecutionError(exit_code=1)

View File

@ -249,6 +249,9 @@ class TestTgtAdmDriver(test.TestCase):
'_verify_backing_lun',
lambda x, y: True)
self.stubs.Set(self.target,
'_get_target_chap_auth',
lambda x: None)
self.stubs.Set(vutils,
'generate_username',
lambda: 'QZJbisGmn9AL954FNF4D')
@ -267,6 +270,19 @@ class TestTgtAdmDriver(test.TestCase):
self.testvol_1,
self.fake_volumes_dir))
self.stubs.Set(self.target,
'_get_target_chap_auth',
lambda x: ('otzLy2UYbYfnP4zXLG5z',
'234Zweo38VGBBvrpK9nt'))
expected_result['auth'] = ('CHAP '
'otzLy2UYbYfnP4zXLG5z 234Zweo38VGBBvrpK9nt')
self.assertEqual(expected_result,
self.target.create_export(ctxt,
self.testvol_1,
self.fake_volumes_dir))
def test_ensure_export(self):
ctxt = context.get_admin_context()
with mock.patch.object(self.target, 'create_iscsi_target'):

View File

@ -17,6 +17,9 @@ class IetAdm(object):
def __init__(self, *args, **kwargs):
super(IetAdm, self).__init__(*args, **kwargs)
def _get_target_chap_auth(self, name):
pass
def ensure_export(self, context, volume, volume_path):
pass

View File

@ -38,6 +38,9 @@ class LioAdm(TgtAdm):
self._verify_rtstool()
def _get_target_chap_auth(self, name):
pass
def remove_export(self, context, volume):
try:
iscsi_target = self.db.volume_get_iscsi_target_num(context,

View File

@ -306,8 +306,15 @@ class TgtAdm(iscsi.ISCSITarget):
iscsi_name = "%s%s" % (self.configuration.iscsi_target_prefix,
volume['name'])
iscsi_target, lun = self._get_target_and_lun(context, volume)
chap_username = vutils.generate_username()
chap_password = vutils.generate_password()
# Verify we haven't setup a CHAP creds file already
# if DNE no big deal, we'll just create it
current_chap_auth = self._get_target_chap_auth(iscsi_name)
if current_chap_auth:
(chap_username, chap_password) = current_chap_auth
else:
chap_username = vutils.generate_username()
chap_password = vutils.generate_password()
chap_auth = self._iscsi_authentication('IncomingUser', chap_username,
chap_password)
# NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need