marvin: check and use logger Checks and only then calls logger
Signed-off-by: Rohit Yadav <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/d72d3ee2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/d72d3ee2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/d72d3ee2 Branch: refs/heads/master Commit: d72d3ee22bf9cb0b4381b7370b291c9f3856247f Parents: 1c0e2cf Author: Rohit Yadav <[email protected]> Authored: Wed Oct 31 22:58:06 2012 +0530 Committer: Rohit Yadav <[email protected]> Committed: Wed Oct 31 23:18:06 2012 +0530 ---------------------------------------------------------------------- tools/marvin/marvin/cloudstackConnection.py | 24 ++++++++++++++------- 1 files changed, 16 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d72d3ee2/tools/marvin/marvin/cloudstackConnection.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/cloudstackConnection.py b/tools/marvin/marvin/cloudstackConnection.py index d70c192..98c0214 100644 --- a/tools/marvin/marvin/cloudstackConnection.py +++ b/tools/marvin/marvin/cloudstackConnection.py @@ -69,16 +69,21 @@ class cloudConnection(object): try: self.connection = urllib2.urlopen("http://%s:%d/client/api?%s"%(self.mgtSvr, self.port, requestUrl)) - self.logging.debug("sending GET request: %s"%requestUrl) + if self.logging is not None: + self.logging.debug("sending GET request: %s"%requestUrl) response = self.connection.read() - self.logging.info("got response: %s"%response) + if self.logging is not None: + self.logging.info("got response: %s"%response) except IOError, e: if hasattr(e, 'reason'): - self.logging.critical("failed to reach %s because of %s"%(self.mgtSvr, e.reason)) + if self.logging is not None: + self.logging.critical("failed to reach %s because of %s"%(self.mgtSvr, e.reason)) elif hasattr(e, 'code'): - self.logging.critical("server returned %d error code"%e.code) + if self.logging is not None: + self.logging.critical("server returned %d error code"%e.code) except httplib.HTTPException, h: - self.logging.debug("encountered http Exception %s"%h.args) + if self.logging is not None: + self.logging.debug("encountered http Exception %s"%h.args) if self.retries > 0: self.retries = self.retries - 1 self.make_request_with_auth(command, requests) @@ -95,9 +100,11 @@ class cloudConnection(object): requestUrl = "&".join(["=".join([request[0], urllib.quote_plus(str(request[1]))]) for request in requests]) self.connection = urllib2.urlopen("http://%s:%d/client/api?%s"%(self.mgtSvr, self.port, requestUrl)) - self.logging.debug("sending GET request without auth: %s"%requestUrl) + if self.logging is not None: + self.logging.debug("sending GET request without auth: %s"%requestUrl) response = self.connection.read() - self.logging.info("got response: %s"%response) + if self.logging is not None: + self.logging.info("got response: %s"%response) return response def pollAsyncJob(self, jobId, response): @@ -114,7 +121,8 @@ class cloudConnection(object): return asyncResonse time.sleep(5) - self.logging.debug("job: %s still processing, will timeout in %ds"%(jobId, timeout)) + if self.logging is not None: + self.logging.debug("job: %s still processing, will timeout in %ds"%(jobId, timeout)) timeout = timeout - 5 raise cloudstackException.cloudstackAPIException("asyncquery", "Async job timeout %s"%jobId)
