Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8CC7A17A3E for ; Sat, 1 Nov 2014 07:55:58 +0000 (UTC) Received: (qmail 81879 invoked by uid 500); 1 Nov 2014 07:55:58 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 81847 invoked by uid 500); 1 Nov 2014 07:55:58 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 81836 invoked by uid 99); 1 Nov 2014 07:55:58 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Nov 2014 07:55:58 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id F4031993972; Sat, 1 Nov 2014 07:55:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bhaisaab@apache.org To: commits@cloudstack.apache.org Message-Id: <647bebe8c19a4a09aa10c3842065aee3@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: cloudmonkey: fix error handling and unicode string conversions Date: Sat, 1 Nov 2014 07:55:57 +0000 (UTC) Repository: cloudstack-cloudmonkey Updated Branches: refs/heads/5.3 d835341e9 -> eae19737f cloudmonkey: fix error handling and unicode string conversions Signed-off-by: Rohit Yadav Project: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/commit/eae19737 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/eae19737 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/eae19737 Branch: refs/heads/5.3 Commit: eae19737f99d4236aa925744d41b605aa103ac38 Parents: d835341 Author: Rohit Yadav Authored: Sat Nov 1 13:25:29 2014 +0530 Committer: Rohit Yadav Committed: Sat Nov 1 13:25:29 2014 +0530 ---------------------------------------------------------------------- cloudmonkey/cloudmonkey.py | 7 ++++++- cloudmonkey/requester.py | 13 ++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/eae19737/cloudmonkey/cloudmonkey.py ---------------------------------------------------------------------- diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py index 2c48af7..0f46c72 100644 --- a/cloudmonkey/cloudmonkey.py +++ b/cloudmonkey/cloudmonkey.py @@ -181,6 +181,8 @@ class CloudMonkeyShell(cmd.Cmd, object): for arg in args: if isinstance(type(arg), types.NoneType) or not arg: continue + if not (isinstance(arg, str) or isinstance(arg, unicode)): + arg = unicode(arg) output += arg except Exception, e: print(str(e)) @@ -388,7 +390,10 @@ class CloudMonkeyShell(cmd.Cmd, object): result = self.make_request(apiname, args_dict, isasync) - if not result: + if not result or not isinstance(result, dict): + if isinstance(result, unicode): + result = result.decode("utf-8") + logger.debug("Invalid command result: %s" % result) return try: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/eae19737/cloudmonkey/requester.py ---------------------------------------------------------------------- diff --git a/cloudmonkey/requester.py b/cloudmonkey/requester.py index 3c06250..ad243a3 100644 --- a/cloudmonkey/requester.py +++ b/cloudmonkey/requester.py @@ -93,6 +93,7 @@ def logout(url, session): def make_request_with_password(command, args, logger, url, credentials): error = None + args = args.copy() username = credentials['username'] password = credentials['password'] @@ -153,6 +154,7 @@ def make_request(command, args, logger, url, credentials, expires): if not args: args = {} + args = args.copy() args["command"] = command args["response"] = "json" args["signatureversion"] = "3" @@ -241,7 +243,7 @@ def monkeyrequest(command, args, isasync, asyncblock, logger, url, return response response = process_json(response) - if not response: + if not response or not isinstance(response, dict): return response, error isasync = isasync and (asyncblock == "true") @@ -266,7 +268,7 @@ def monkeyrequest(command, args, isasync, asyncblock, logger, url, response, error = make_request(command, request, logger, url, credentials, expires) - if error is not None: + if error and not response: return response, error response = process_json(response) @@ -276,6 +278,9 @@ def monkeyrequest(command, args, isasync, asyncblock, logger, url, continue result = response[responsekeys[0]] + if "errorcode" in result or "errortext" in result: + return response, error + jobstatus = result['jobstatus'] if jobstatus == 2: jobresult = result["jobresult"] @@ -283,8 +288,10 @@ def monkeyrequest(command, args, isasync, asyncblock, logger, url, jobid, jobresult["errorcode"], jobresult["errortext"]) return response, error elif jobstatus == 1: - print "\r" + " " * progress, + print "\r" + " " * progress return response, error + elif jobstatus == 0: + pass # Job in progress else: logger_debug(logger, "We should not arrive here!") sys.stdout.flush()