cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject [20/26] git commit: updated refs/heads/affinity_groups to 90172c3
Date Tue, 09 Apr 2013 22:49:00 GMT
Cloudmonkey requester.py change to return clearer errors and implement a logic change for async
calls.

Applied from review request:
https://reviews.apache.org/r/10151/

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6e22843a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6e22843a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6e22843a

Branch: refs/heads/affinity_groups
Commit: 6e22843acb6bbd61260849fac171bba61ac6650f
Parents: 1f206a4
Author: Funs Kessen <funs@barred.org>
Authored: Fri Apr 5 22:25:34 2013 +0530
Committer: Rohit Yadav <bhaisaab@apache.org>
Committed: Fri Apr 5 22:42:55 2013 +0530

----------------------------------------------------------------------
 tools/cli/cloudmonkey/requester.py |   57 +++++++++++++++++++++++++-----
 1 files changed, 47 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6e22843a/tools/cli/cloudmonkey/requester.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/requester.py b/tools/cli/cloudmonkey/requester.py
index 5c4cd1e..d58c1af 100644
--- a/tools/cli/cloudmonkey/requester.py
+++ b/tools/cli/cloudmonkey/requester.py
@@ -32,6 +32,7 @@ try:
     import types
     import urllib
     import urllib2
+    from urllib2 import urlopen, HTTPError
 
 except ImportError, e:
     print "Import error in %s : %s" % (__name__, e)
@@ -77,19 +78,20 @@ def make_request(command, args, logger, host, port,
         logger_debug(logger, "Request sent: %s" % request_url)
         connection = urllib2.urlopen(request_url)
         response = connection.read()
-    except Exception, e:
-        error = str(e)
+    except HTTPError, e:
+        error = "%s: %s" % (e.msg, e.info().getheader('X-Description'))
 
     logger_debug(logger, "Response received: %s" % response)
     if error is not None:
-        logger_debug(logger, error)
+        logger_debug(logger, "Error: error is not None, %s" % (error))
+        return response, error
 
     return response, error
 
 
 def monkeyrequest(command, args, isasync, asyncblock, logger, host, port,
                   apikey, secretkey, timeout, protocol, path):
-
+    fcommand = command
     response = None
     error = None
     logger_debug(logger, "======== START Request ========")
@@ -106,7 +108,8 @@ def monkeyrequest(command, args, isasync, asyncblock, logger, host, port,
             response = json.loads(str(response))
         except ValueError, e:
             error = "Error processing json response, %s" % e
-            logger_debug(logger, "Error processing json", e)
+            logger_debug(logger, "Error processing json: %s" % e)
+
         return response
 
     response = process_json(response)
@@ -125,29 +128,63 @@ def monkeyrequest(command, args, isasync, asyncblock, logger, host,
port,
         progress = 1
         while timeout > 0:
             print '\r' + '.' * progress,
-            time.sleep(pollperiod)
-            timeout = timeout - pollperiod
+            sys.stdout.flush()
             progress += 1
+            timeout = timeout - pollperiod
             logger_debug(logger, "Job %s to timeout in %ds" % (jobid, timeout))
             sys.stdout.flush()
-            response, error = monkeyrequest(command, request, isasync,
+            if re.match("queryAsyncJobResult", fcommand):
+                # logger_debug(logger, "%d loop: Job %s" % (progress, jobid))
+                # sys.stdout.flush()
+                time.sleep(pollperiod)
+            else:
+                response, error = monkeyrequest(command, request, isasync,
                                             asyncblock, logger,
                                             host, port,  apikey, secretkey,
                                             timeout, protocol, path)
-            response = process_json(response)
+
             responsekeys = filter(lambda x: 'response' in x, response.keys())
+
             if len(responsekeys) < 1:
+                time.sleep(pollperiod)
                 continue
+
             result = response[responsekeys[0]]
             jobstatus = result['jobstatus']
-            if jobstatus == 2:
+            jobresultcode = result['jobresultcode']
+            try:
                 jobresult = result["jobresult"]
+                logger_debug(logger, "jobresult %s" % (jobresult))
+                sys.stdout.flush()
+                return response, None
+            except KeyError:
+                logger_debug(logger, "No jobresult yet %s" % (result))
+                sys.stdout.flush()
+
+            if jobresultcode != 0:
+                error = "Error: resultcode %d for jobid %s" % (jobresultcode, jobid)
+                logger_debug(logger, "%s" % (error))
+                return response, error
+            else:
+                # if we get a valid respons resultcode give back results
+                response, error = monkeyrequest(command, request, isasync,
+                            asyncblock, logger,
+                            host, port,  apikey, secretkey,
+                            timeout, protocol, path)
+                logger_debug(logger, "Ok: %s" % (jobid))
+                return response, error
+
+            if jobstatus == 2:
                 error = "\rAsync job %s failed\nError %s, %s" % (jobid,
                         jobresult["errorcode"], jobresult["errortext"])
                 return response, error
             elif jobstatus == 1:
                 print '\r',
                 return response, error
+            else:
+                logger_debug(logger, "We should not arrive here!")
+                sys.stdout.flush()
+
         error = "Error: Async query timeout occurred for jobid %s" % jobid
 
     return response, error


Mime
View raw message