]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix HNAS iSCSI driver error on LUN creation
authorErlon R. Cruz <erlon.cruz@fit-tecnologia.org.br>
Wed, 11 Mar 2015 14:30:28 +0000 (11:30 -0300)
committerErlon R. Cruz <erlon.cruz@fit-tecnologia.org.br>
Thu, 12 Mar 2015 10:57:59 +0000 (07:57 -0300)
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
cinder/volume/drivers/hds/hnas_backend.py

index 2688c69ee74a9dda398006135dbaa5a83e9ef3bc..138ed544f8e708d8d1b51468d15fbf56b3df9c89 100644 (file)
@@ -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):
index c548ef62f30622137c84c05d4a32eec76b72f12d..65e3f8ff284dc7e0c06631b52e92030dc751de6d 100644 (file)
@@ -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