summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2012-11-19 12:52:37 +0100
committerBrian C. Lane <bcl@redhat.com>2012-11-20 11:50:11 -0800
commit2478b31ac36b5c4397016290d81ba0d894f41896 (patch)
tree199344bfe350b35041438e9204d81b153de427ae
parentf2b9ed9c309a15da5c3d2402f69260c683426ea1 (diff)
downloadanaconda-2478b31ac36b5c4397016290d81ba0d894f41896.tar.gz
anaconda-2478b31ac36b5c4397016290d81ba0d894f41896.tar.xz
anaconda-2478b31ac36b5c4397016290d81ba0d894f41896.zip
Fix error in iutil.execCapture when fatal and non-zero exit
Fix the TypeError problem with iutil.execWithCapture() when fatal and process returns a non-zero exit code.
-rw-r--r--pyanaconda/iutil.py6
-rw-r--r--tests/pyanaconda_test/iutil_test.py11
2 files changed, 14 insertions, 3 deletions
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index ece4e8597..9ac0da784 100644
--- a/pyanaconda/iutil.py
+++ b/pyanaconda/iutil.py
@@ -263,13 +263,13 @@ def execWithCapture(command, argv, stdin = None, stderr = None, root='/',
# if we have anything other than a clean exit, and we get the fatal
# option, raise the OSError.
if proc.returncode and fatal:
- raise OSError('Non-zero return code: %s' % proc.returncode)
+ raise RuntimeError('Error running ' + command + ': Non-zero return code: %s' % proc.returncode)
except OSError as e:
log.error ("Error running " + command + ": " + e.strerror)
- closefds()
raise RuntimeError, "Error running " + command + ": " + e.strerror
+ finally:
+ closefds()
- closefds()
return rc
def execWithCallback(command, argv, stdin = None, stdout = None,
diff --git a/tests/pyanaconda_test/iutil_test.py b/tests/pyanaconda_test/iutil_test.py
index d772255b3..2f143ec9e 100644
--- a/tests/pyanaconda_test/iutil_test.py
+++ b/tests/pyanaconda_test/iutil_test.py
@@ -1,4 +1,5 @@
import mock
+import sys
class IutilTest(mock.TestCase):
def setUp(self):
@@ -24,3 +25,13 @@ class IutilTest(mock.TestCase):
iutil.os.makedirs.assert_called_with("/mnt/sysimage/etc")
iutil.shutil.copy.assert_called_with("/etc/securetty",
"/mnt/sysimage/etc/securetty")
+
+ def testExecCaptureNonZeroFatal (self):
+ import iutil
+ try:
+ argv = ["-c", "import sys; sys.exit(3);"]
+ iutil.execWithCapture(sys.executable, argv, root=None, fatal=True)
+ except RuntimeError, ex:
+ self.assertIn("return code: 3", str(ex))
+ else:
+ self.fail("RuntimeError not raised")