]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove unused variables from ensure_export()
authorMitsuhiro Tanino <mitsuhiro.tanino@hds.com>
Sat, 10 Jan 2015 01:11:43 +0000 (20:11 -0500)
committerMitsuhiro Tanino <mitsuhiro.tanino@hds.com>
Sat, 10 Jan 2015 01:11:43 +0000 (20:11 -0500)
After introducing commit 9651f547147188645942466602c92cce06666483,
these three variables are obsolete in ensure_export().
By remaining these variable, ensure_export() fails to export
volumes after c-vol service is restart because the caller of
ensure_export() in lvm driver does not pass these variables.

- iscsi_name, volume_group, config

Main clean up is done by commit Ibfd1feefd72c43ef316b267e9d6645f2e67e2558.
This patch adds some tests for tgt, lio, and iser targets.
And also adds initialization of chap_auth_userid and chap_auth_password
in create_iscsi_target() because these variables might be referred
before definition.

Closes-bug: 1408121
Related-bug: 1408171
Change-Id: I8766eee33ae07fea71873809bfec37b8352c3a89

cinder/tests/targets/test_base_iscsi_driver.py
cinder/tests/targets/test_iser_driver.py [new file with mode: 0644]
cinder/tests/targets/test_lio_driver.py [new file with mode: 0644]
cinder/tests/targets/test_tgt_driver.py
cinder/volume/targets/lio.py

index 23dec8158d427b8bf83e0963667efc6ec0e74f0d..78de70a34be1af1d1649d3dfe0a50ca8372537d7 100644 (file)
@@ -27,9 +27,7 @@ class FakeDriver(iscsi.ISCSITarget):
     def create_export(self, context, vref):
         pass
 
-    def ensure_export(self, context, vref,
-                      iscsi_name, vol_path,
-                      vol_group, cfg):
+    def ensure_export(self, context, vref, vol_path):
         pass
 
     def remove_export(self, context, vref):
diff --git a/cinder/tests/targets/test_iser_driver.py b/cinder/tests/targets/test_iser_driver.py
new file mode 100644 (file)
index 0000000..aaa6ca7
--- /dev/null
@@ -0,0 +1,25 @@
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+from cinder.tests.targets import test_tgt_driver as test_tgt
+from cinder import utils
+from cinder.volume.targets import iser
+
+
+class TestIserAdmDriver(test_tgt.TestTgtAdmDriver):
+
+    def setUp(self):
+        super(TestIserAdmDriver, self).setUp()
+        self.configuration.iser_ip_address = '10.9.8.7'
+        self.configuration.iser_target_prefix = 'iqn.2010-10.org.openstack:'
+        self.target = iser.ISERTgtAdm(root_helper=utils.get_root_helper(),
+                                      configuration=self.configuration)
diff --git a/cinder/tests/targets/test_lio_driver.py b/cinder/tests/targets/test_lio_driver.py
new file mode 100644 (file)
index 0000000..3210572
--- /dev/null
@@ -0,0 +1,89 @@
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+import mock
+from oslo_concurrency import processutils as putils
+
+from cinder import context
+from cinder import exception
+from cinder.tests.targets import test_tgt_driver as test_tgt
+from cinder import utils
+from cinder.volume.targets import lio
+
+
+class TestLioAdmDriver(test_tgt.TestTgtAdmDriver):
+
+    def setUp(self):
+        super(TestLioAdmDriver, self).setUp()
+        self.target = lio.LioAdm(root_helper=utils.get_root_helper(),
+                                 configuration=self.configuration)
+        self.fake_iscsi_scan = ('iqn.2010-10.org.openstack:'
+                                'volume-83c2e877-feed-46be-8435-77884fe55b45')
+        self.target.db = mock.MagicMock(
+            volume_get=lambda x, y: {'provider_auth': 'IncomingUser foo bar'})
+
+    def test_get_target(self):
+
+        def _fake_execute(*args, **kwargs):
+            return self.fake_iscsi_scan, None
+
+        self.stubs.Set(utils,
+                       'execute',
+                       _fake_execute)
+
+        self.assertEqual('iqn.2010-10.org.openstack:'
+                         'volume-83c2e877-feed-46be-8435-77884fe55b45',
+                         self.target._get_target('iqn.2010-10.org.openstack:'
+                                                 'volume-83c2e877-feed-46be-'
+                                                 '8435-77884fe55b45'))
+
+    def test_verify_backing_lun(self):
+        pass
+
+    def test_create_iscsi_target_already_exists(self):
+        def _fake_execute(*args, **kwargs):
+            raise putils.ProcessExecutionError(exit_code=1)
+
+        self.stubs.Set(utils,
+                       'execute',
+                       _fake_execute)
+
+        self.stubs.Set(self.target,
+                       '_get_target',
+                       lambda x: 1)
+
+        self.stubs.Set(self.target,
+                       '_verify_backing_lun',
+                       lambda x, y: True)
+
+        test_vol = 'iqn.2010-10.org.openstack:'\
+                   'volume-83c2e877-feed-46be-8435-77884fe55b45'
+        chap_auth = 'chap foo bar'
+        self.assertRaises(exception.ISCSITargetCreateFailed,
+                          self.target.create_iscsi_target,
+                          test_vol,
+                          1,
+                          0,
+                          self.fake_volumes_dir,
+                          chap_auth)
+
+    @mock.patch.object(lio.LioAdm, 'create_iscsi_target')
+    def test_ensure_export(self, _mock_create):
+
+        ctxt = context.get_admin_context()
+        self.target.ensure_export(ctxt,
+                                  self.testvol_1,
+                                  self.fake_volumes_dir)
+        self.target.create_iscsi_target.assert_called_once_with(
+            'iqn.2010-10.org.openstack:testvol',
+            1, 0, self.fake_volumes_dir, 'IncomingUser foo bar',
+            check_exit_code=False)
index 72bee11abb7cd878befaa8504ed568ad0436a9cb..293d346aef7a82cc4294c8e2407d03b14315b8ee 100644 (file)
@@ -9,6 +9,7 @@
 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #    License for the specific language governing permissions and limitations
 #    under the License.
+
 import os
 import tempfile
 
@@ -228,7 +229,7 @@ class TestTgtAdmDriver(test.TestCase):
                 0,
                 self.fake_volumes_dir))
 
-    def test_create_create_export(self):
+    def test_create_export(self):
 
         def _fake_execute(*args, **kwargs):
             return '', ''
@@ -262,3 +263,16 @@ class TestTgtAdmDriver(test.TestCase):
                          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'):
+            self.target.ensure_export(ctxt,
+                                      self.testvol_1,
+                                      self.fake_volumes_dir)
+            self.target.create_iscsi_target.assert_called_once_with(
+                'iqn.2010-10.org.openstack:testvol',
+                1, 0, self.fake_volumes_dir, None,
+                iscsi_write_cache='on',
+                check_exit_code=False,
+                old_name=None)
index 6a8c71eba639cbaf10b7d35d21522e23bc4f703a..90bb964ce2d8e3281f4ede2b0302399c72823bfd 100644 (file)
@@ -95,6 +95,8 @@ class LioAdm(TgtAdm):
 
         LOG.info(_LI('Creating iscsi_target for volume: %s') % vol_id)
 
+        chap_auth_userid = ""
+        chap_auth_password = ""
         if chap_auth is not None:
             (chap_auth_userid, chap_auth_password) = chap_auth.split(' ')[1:]