You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2014/11/01 08:55:57 UTC
git commit: cloudmonkey: fix error handling and unicode string
conversions
Repository: cloudstack-cloudmonkey
Updated Branches:
refs/heads/5.3 d835341e9 -> eae19737f
cloudmonkey: fix error handling and unicode string conversions
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
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 <ro...@shapeblue.com>
Authored: Sat Nov 1 13:25:29 2014 +0530
Committer: Rohit Yadav <ro...@shapeblue.com>
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()