]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add unit test for commit 22abe9081
authorMatt Riedemann <mriedem@us.ibm.com>
Mon, 15 Dec 2014 19:23:42 +0000 (11:23 -0800)
committerMatt Riedemann <mriedem@us.ibm.com>
Mon, 15 Dec 2014 19:28:29 +0000 (11:28 -0800)
Commit 22abe9081 fixed a bug in commit d7bd65e8e which we could have
found the first time with a simple unit test.

This change adds the unit test to cover that new error handling block.

Related-Bug: #1398078

Change-Id: I86d2fd477f3ae5590c5f079a4c806d1f50eb96d0

cinder/tests/test_iscsi.py

index 3737e76af0133beb5a4f700f7d0cd69768b4f8a0..ac1ed5ea3505d6110e2545eaee5e0f93ec6215ac 100644 (file)
@@ -18,6 +18,7 @@ import shutil
 import string
 import tempfile
 
+from oslo.concurrency import processutils
 from oslo.config import cfg
 
 from cinder.brick.iscsi import iscsi
@@ -157,6 +158,16 @@ class TgtAdmTestCase(test.TestCase, TargetAdminTestCase):
         self.assertEqual(target_helper._get_target_chap_auth(self.target_name),
                          (self.chap_username, self.chap_password))
 
+    def fake_execute(self, *cmd, **kwargs):
+        self.cmds.append(string.join(cmd))
+        # Tests that if tgtadm --op show fails with 'target already exists',
+        # we handle it gracefully and continue.
+        if 'tgtadm' in cmd and '--op' in cmd and 'show' in cmd:
+            raise processutils.ProcessExecutionError(
+                stderr='tgtadm: this target already exists')
+        else:
+            return "", None
+
 
 class IetAdmTestCase(test.TestCase, TargetAdminTestCase):