summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorJustin Santa Barbara <justin@fathomdb.com>2010-08-20 01:24:59 +0000
committerTarmac <>2010-08-20 01:24:59 +0000
commitcfe3b2a6dd73e56652f99a573c1bb0abe5a648d4 (patch)
treee2d169de490742905798f87c47202b59c3c6e0d7 /nova/utils.py
parent49ef2b293429c9f9b3d7444402e3f7d3d0570d48 (diff)
parente5a448a616173cd391aaf458f5e0e5ff94a42c89 (diff)
downloadnova-cfe3b2a6dd73e56652f99a573c1bb0abe5a648d4.tar.gz
nova-cfe3b2a6dd73e56652f99a573c1bb0abe5a648d4.tar.xz
nova-cfe3b2a6dd73e56652f99a573c1bb0abe5a648d4.zip
Check exit codes when spawning processes by default
Also pass --fail to curl so that it sets exit code when download fails
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/nova/utils.py b/nova/utils.py
index e826f9b71..dc3c626ec 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -56,23 +56,25 @@ def fetchfile(url, target):
# c.perform()
# c.close()
# fp.close()
- execute("curl %s -o %s" % (url, target))
+ execute("curl --fail %s -o %s" % (url, target))
-
-def execute(cmd, input=None, addl_env=None):
+def execute(cmd, process_input=None, addl_env=None, check_exit_code=True):
env = os.environ.copy()
if addl_env:
env.update(addl_env)
obj = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
result = None
- if input != None:
- result = obj.communicate(input)
+ if process_input != None:
+ result = obj.communicate(process_input)
else:
result = obj.communicate()
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
@@ -98,9 +100,13 @@ 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):