cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject git commit: cloudmonkey: fix error handling and unicode string conversions
Date Sat, 01 Nov 2014 10:43:07 GMT
Repository: cloudstack-cloudmonkey
Updated Branches:
  refs/heads/master d835341e9 -> eae19737f


cloudmonkey: fix error handling and unicode string conversions

Signed-off-by: Rohit Yadav <rohit.yadav@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/master
Commit: eae19737f99d4236aa925744d41b605aa103ac38
Parents: d835341
Author: Rohit Yadav <rohit.yadav@shapeblue.com>
Authored: Sat Nov 1 13:25:29 2014 +0530
Committer: Rohit Yadav <rohit.yadav@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()


Mime
View raw message