From eb20e9e5009541ea0037588a43443c74e8968c9c Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 15 Dec 2014 11:23:42 -0800 Subject: [PATCH] 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 --- cinder/tests/test_iscsi.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cinder/tests/test_iscsi.py b/cinder/tests/test_iscsi.py index 3737e76af01..ac1ed5ea350 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):