From: Erlon R. Cruz Date: Thu, 27 Nov 2014 18:44:23 +0000 (-0200) Subject: Fix HNAS driver parsing errors X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6abbd6bf81ff5640d900d2417479c5def9b3cf1e;p=openstack-build%2Fcinder-build.git Fix HNAS driver parsing errors Depending on some configurations of HNAS array, the driver returns an error during volume creation or driver initialization. This patch adds some checks to fix those parsing errors. Closes-Bug: #1402771 Change-Id: I1700782153dfb780b9228de6e575dd2b32af6922 --- diff --git a/cinder/tests/test_hds_hnas_backend.py b/cinder/tests/test_hds_hnas_backend.py index 8da2439a9..160fe1d3f 100644 --- a/cinder/tests/test_hds_hnas_backend.py +++ b/cinder/tests/test_hds_hnas_backend.py @@ -143,6 +143,25 @@ x86_64_linux-bart_libc-2.7_release\n\ Date: Feb 22 2013, 04:10:09\n\ \n" +HNAS_RESULT19 = " ID Label Size Used Snapshots \ +Deduped Avail Thin ThinSize ThinAvail FS Type\n\ +---- ------------- ------- ------------- --------- ------- -------------\ +---- -------- --------- -------------------\n\ +1025 fs01-husvm 250 GB 47.1 GB (19%) 0 B (0%) NA 203 GB (81%)\ + No 4 KB,WFS-2,128 DSBs\n\ +1047 manage_test02 19.9 GB 9.29 GB (47%) 0 B (0%) NA 10.6 GB (53%)\ + No 4 KB,WFS-2,128 DSBs\n\ +\n" + +HNAS_RESULT20 = "\n\ +Alias : test_iqn \n\ +Globally unique name: iqn.2014-12.10.10.10.10:evstest1.cinder-silver \n\ +Comment : \n\ +Secret : \n\ +Authentication : Enabled \n\ +Logical units : No logical units. \n\ +\n" + HNAS_CMDS = { ('ssc', '-u', 'supervisor', '-p', 'supervisor', '0.0.0.0', 'evsfs', u'list'): ["%s" % HNAS_RESULT1, ""], @@ -226,9 +245,11 @@ class HDSHNASBendTest(test.TestCase): self.assertIn('11.1.3225.01', out) self.assertIn('83-68-96-AA-DA-5D', out) - @mock.patch.object(utils, 'execute', side_effect=m_execute) - def test_get_hdp_info(self, m_execute): - out = self.hnas_bend.get_hdp_info("ssc", "0.0.0.0", "supervisor", + @mock.patch.object(utils, 'execute') + def test_get_hdp_info(self, m_exec): + # tests when there is two or more evs + m_exec.return_value = (HNAS_RESULT5, "") + out = self.hnas_bend.get_hdp_info("ssh", "0.0.0.0", "supervisor", "supervisor") self.assertEqual(len(out.split('\n')), 10) @@ -237,6 +258,16 @@ class HDSHNASBendTest(test.TestCase): line1 = out.split('\n')[0] self.assertEqual(len(line1.split()), 12) + # test when there is only one evs + m_exec.return_value = (HNAS_RESULT19, "") + out = self.hnas_bend.get_hdp_info("ssh", "0.0.0.0", "supervisor", + "supervisor") + self.assertEqual(len(out.split('\n')), 3) + self.assertIn('fs01-husvm', out) + self.assertIn('manage_test02', out) + line1 = out.split('\n')[0] + self.assertEqual(len(line1.split()), 12) + @mock.patch.object(utils, 'execute', side_effect=m_execute) def test_get_nfs_info(self, m_execute): out = self.hnas_bend.get_nfs_info("ssc", "0.0.0.0", "supervisor", @@ -315,10 +346,19 @@ class HDSHNASBendTest(test.TestCase): "supervisor", "test_iqn", "test_hdp", "test_secret") - @mock.patch.object(utils, 'execute', side_effect=m_execute) - def test_get_targetsecret(self, m_execute): - out = self.hnas_bend.get_targetsecret("ssc", "0.0.0.0", "supervisor", + @mock.patch.object(utils, 'execute') + def test_get_targetsecret(self, m_exec): + # test when target has secret + m_exec.return_value = (HNAS_RESULT12, "") + out = self.hnas_bend.get_targetsecret("ssh", "0.0.0.0", "supervisor", "supervisor", "test_iqn", "test_hdp") self.assertEqual('test_secret', out) + + # test when target don't have secret + m_exec.return_value = (HNAS_RESULT20, "") + out = self.hnas_bend.get_targetsecret("ssh", "0.0.0.0", "supervisor", + "supervisor", "test_iqn", + "test_hdp") + self.assertEqual('', out) diff --git a/cinder/volume/drivers/hds/hnas_backend.py b/cinder/volume/drivers/hds/hnas_backend.py index e935199d8..7ac2fb8ec 100644 --- a/cinder/volume/drivers/hds/hnas_backend.py +++ b/cinder/volume/drivers/hds/hnas_backend.py @@ -107,16 +107,26 @@ class HnasBackend(): ip0, 'df', '-a', check_exit_code=True) lines = out.split('\n') + single_evs = True newout = "" for line in lines: if 'Not mounted' in line: continue + if 'not' not in line and 'EVS' in line: + single_evs = False if 'GB' in line or 'TB' in line: inf = line.split() - (fsid, fslabel, capacity, used, perstr) = \ - (inf[0], inf[1], inf[3], inf[5], inf[7]) - (availunit, usedunit) = (inf[4], inf[6]) + + if not single_evs: + (fsid, fslabel, capacity) = (inf[0], inf[1], inf[3]) + (used, perstr) = (inf[5], inf[7]) + (availunit, usedunit) = (inf[4], inf[6]) + else: + (fsid, fslabel, capacity) = (inf[0], inf[1], inf[2]) + (used, perstr) = (inf[4], inf[6]) + (availunit, usedunit) = (inf[3], inf[5]) + if usedunit == 'GB': usedmultiplier = units.Ki else: @@ -605,9 +615,12 @@ class HnasBackend(): lines = out.split('\n') for line in lines: if 'Secret' in line: - secret = line.split()[2] + if len(line.split()) > 2: + secret = line.split()[2] if 'Authentication' in line: enabled = line.split()[2] if enabled == 'Enabled': return secret + else: + return ""