From f5e19272844f2f0d2c72bf55a2bdf533f40d1ea5 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Thu, 22 Jul 2010 12:28:47 -0700 Subject: Check exit codes when spawning processes by default --- nova/utils.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'nova/utils.py') 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): -- cgit From 93aee19fa2f24c4f9c1fd59c0666e024c6891565 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Thu, 29 Jul 2010 14:48:10 -0700 Subject: Added --fail argument to curl invocations, so that HTTP request fails get surfaced as non-zero exit codes --- nova/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index fd30f1f2d..74c7c021c 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -53,7 +53,7 @@ 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, check_exit_code=True): env = os.environ.copy() -- cgit From 0ee7d2f74a959bcf1cf611f63842302866774475 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Sun, 8 Aug 2010 12:57:33 -0700 Subject: Greater compliance with pep8/pylint style checks --- nova/utils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index 74c7c021c..1acc205b5 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -55,22 +55,23 @@ def fetchfile(url, target): # fp.close() execute("curl --fail %s -o %s" % (url, target)) -def execute(cmd, input=None, addl_env=None, check_exit_code=True): +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)) + raise Exception( "Unexpected exit code: %s. result=%s" + % (obj.returncode, result)) return result @@ -101,7 +102,8 @@ def runthis(prompt, cmd, check_exit_code = True): 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)) + raise Exception( "Unexpected exit code: %s from cmd: %s" + % (exit_code, cmd)) def generate_uid(topic, size=8): -- cgit