From: Matt Riedemann Date: Mon, 15 Dec 2014 19:23:42 +0000 (-0800) Subject: Add unit test for commit 22abe9081 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=eb20e9e5009541ea0037588a43443c74e8968c9c;p=openstack-build%2Fcinder-build.git Add unit test for commit 22abe9081 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 --- diff --git a/cinder/tests/test_iscsi.py b/cinder/tests/test_iscsi.py index 3737e76af..ac1ed5ea3 100644 --- a/cinder/tests/test_iscsi.py +++ b/cinder/tests/test_iscsi.py @@ -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):