From 9df3bcead5e9ba89fc8a4130729679fb17a27133 Mon Sep 17 00:00:00 2001 From: Tomoki Sekiyama Date: Tue, 6 Jan 2015 19:58:13 -0500 Subject: [PATCH] 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 --- cinder/tests/targets/test_lio_driver.py | 3 +++ cinder/tests/targets/test_tgt_driver.py | 16 ++++++++++++++++ cinder/volume/targets/iet.py | 3 +++ cinder/volume/targets/lio.py | 3 +++ cinder/volume/targets/tgt.py | 11 +++++++++-- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/cinder/tests/targets/test_lio_driver.py b/cinder/tests/targets/test_lio_driver.py index 3210572ec..ccee85b48 100644 --- a/cinder/tests/targets/test_lio_driver.py +++ b/cinder/tests/targets/test_lio_driver.py @@ -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) diff --git a/cinder/tests/targets/test_tgt_driver.py b/cinder/tests/targets/test_tgt_driver.py index b88720b34..bc9c10db6 100644 --- a/cinder/tests/targets/test_tgt_driver.py +++ b/cinder/tests/targets/test_tgt_driver.py @@ -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'): diff --git a/cinder/volume/targets/iet.py b/cinder/volume/targets/iet.py index 80f04334d..3e3a2ff80 100644 --- a/cinder/volume/targets/iet.py +++ b/cinder/volume/targets/iet.py @@ -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 diff --git a/cinder/volume/targets/lio.py b/cinder/volume/targets/lio.py index 90bb964ce..ebe193264 100644 --- a/cinder/volume/targets/lio.py +++ b/cinder/volume/targets/lio.py @@ -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, diff --git a/cinder/volume/targets/tgt.py b/cinder/volume/targets/tgt.py index a0991045a..87fb98599 100644 --- a/cinder/volume/targets/tgt.py +++ b/cinder/volume/targets/tgt.py @@ -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 -- 2.45.2