summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@yahoo.com>2010-08-23 14:36:14 -0700
committerVishvananda Ishaya <vishvananda@yahoo.com>2010-08-23 14:36:14 -0700
commit157ef10b3048f0bb26ce0909d77698ffb37e45df (patch)
tree9e9c608678d7828526b93a0ac8a6b9d9ee0eea8a /nova/utils.py
parent78c2175898a468ae734e27dfbc8f5b70f90fd477 (diff)
parentcfe3b2a6dd73e56652f99a573c1bb0abe5a648d4 (diff)
downloadnova-157ef10b3048f0bb26ce0909d77698ffb37e45df.tar.gz
nova-157ef10b3048f0bb26ce0909d77698ffb37e45df.tar.xz
nova-157ef10b3048f0bb26ce0909d77698ffb37e45df.zip
merged trunk and fixed merge errors
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 9e12a5301..c4a8f17e9 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):