From ef27c6beb7410d7007b867b8895178245fe4b7a4 Mon Sep 17 00:00:00 2001 From: "Erlon R. Cruz" Date: Wed, 11 Mar 2015 11:30:28 -0300 Subject: [PATCH] Fix HNAS iSCSI driver error on LUN creation If chap_enabled is 'False', in the first initialization of the driver (before the target is created on HNAS) the driver fails to create volumes. This patch fix that by returning the right value when 'get_targetiqn' is called in this situation. Change-Id: I899717c0e7e4ff800cecc8ffa6e3a81a47e96e9f Closes-Bug: #1430782 --- cinder/tests/test_hds_hnas_backend.py | 26 ++++++++++++++++++++--- cinder/volume/drivers/hds/hnas_backend.py | 2 ++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/cinder/tests/test_hds_hnas_backend.py b/cinder/tests/test_hds_hnas_backend.py index 2688c69ee..138ed544f 100644 --- a/cinder/tests/test_hds_hnas_backend.py +++ b/cinder/tests/test_hds_hnas_backend.py @@ -184,6 +184,10 @@ Authentication : Enabled \n\ Logical units : No logical units. \n\ \n" +HNAS_RESULT20 = "Target does not exist." + +HNAS_RESULT21 = "Target created successfully." + HNAS_CMDS = { ('ssh', '0.0.0.0', 'supervisor', 'supervisor', 'evsfs', 'list'): ["%s" % HNAS_RESULT1, ""], @@ -412,15 +416,31 @@ class HDSHNASBendTest(test.TestCase): self.assertIn('already deleted', out) - @mock.patch.object(hnas_backend.HnasBackend, 'run_cmd', - side_effect=m_run_cmd) - def test_get_targetiqn(self, m_cmd): + @mock.patch.object(hnas_backend.HnasBackend, '_get_evs', return_value=0) + @mock.patch.object(hnas_backend.HnasBackend, 'run_cmd') + def test_get_targetiqn(self, m_cmd, m_get_evs): + + m_cmd.side_effect = [[HNAS_RESULT12, '']] out = self.hnas_bend.get_targetiqn("ssh", "0.0.0.0", "supervisor", "supervisor", "test_iqn", "test_hdp", "test_secret") self.assertEqual('test_iqn', out) + m_cmd.side_effect = [[HNAS_RESULT20, ''], [HNAS_RESULT21, '']] + out = self.hnas_bend.get_targetiqn("ssh", "0.0.0.0", "supervisor", + "supervisor", "test_iqn2", + "test_hdp", "test_secret") + + self.assertEqual('test_iqn2', out) + + m_cmd.side_effect = [[HNAS_RESULT20, ''], [HNAS_RESULT21, '']] + out = self.hnas_bend.get_targetiqn("ssh", "0.0.0.0", "supervisor", + "supervisor", "test_iqn3", + "test_hdp", "") + + self.assertEqual('test_iqn3', out) + @mock.patch.object(hnas_backend.HnasBackend, 'run_cmd', side_effect=m_run_cmd) def test_set_targetsecret(self, m_execute): diff --git a/cinder/volume/drivers/hds/hnas_backend.py b/cinder/volume/drivers/hds/hnas_backend.py index c548ef62f..65e3f8ff2 100644 --- a/cinder/volume/drivers/hds/hnas_backend.py +++ b/cinder/volume/drivers/hds/hnas_backend.py @@ -593,6 +593,8 @@ class HnasBackend(object): 'iscsi-target', 'add', targetalias, secret, check_exit_code=True) + if "success" in out: + return targetalias lines = out.split('\n') # returns the first iqn -- 2.45.2