summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorJustin Santa Barbara <justin@fathomdb.com>2010-07-22 12:28:47 -0700
committerJustin Santa Barbara <justin@fathomdb.com>2010-07-22 12:28:47 -0700
commitf5e19272844f2f0d2c72bf55a2bdf533f40d1ea5 (patch)
tree4bcc9933d2403748fb42c994404ea196e441fa20 /nova/utils.py
parent47d859a5720e3062f202a593fb2b6cb06c5beffc (diff)
downloadnova-f5e19272844f2f0d2c72bf55a2bdf533f40d1ea5.tar.gz
nova-f5e19272844f2f0d2c72bf55a2bdf533f40d1ea5.tar.xz
nova-f5e19272844f2f0d2c72bf55a2bdf533f40d1ea5.zip
Check exit codes when spawning processes by default
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 9ecceafe0..d01c33042 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -45,7 +45,7 @@ def fetchfile(url, target):
# fp.close()
execute("curl %s -o %s" % (url, target))
-def execute(cmd, input=None, addl_env=None):
+def execute(cmd, input=None, addl_env=None, check_exit_code=True):
env = os.environ.copy()
if addl_env:
env.update(addl_env)
@@ -59,6 +59,8 @@ def execute(cmd, input=None, addl_env=None):
obj.stdin.close()
if obj.returncode:
logging.debug("Result was %s" % (obj.returncode))
+ if check_exit_code and obj.returncode <> 0:
+ raise Exception("Unexpected exit code: %s. result=%s" % (obj.returncode, result))
return result
@@ -84,9 +86,12 @@ def debug(arg):
return arg
-def runthis(prompt, cmd):
+def runthis(prompt, cmd, check_exit_code = True):
logging.debug("Running %s" % (cmd))
- logging.debug(prompt % (subprocess.call(cmd.split(" "))))
+ exit_code = subprocess.call(cmd.split(" "))
+ logging.debug(prompt % (exit_code))
+ if check_exit_code and exit_code <> 0:
+ raise Exception("Unexpected exit code: %s from cmd: %s" % (exit_code, cmd))
def generate_uid(topic, size=8):