diff --git a/tools/testClient/cloudstackConnection.py b/tools/testClient/cloudstackConnection.py index 3d341418665..2ab98597bf6 100644 --- a/tools/testClient/cloudstackConnection.py +++ b/tools/testClient/cloudstackConnection.py @@ -1,6 +1,7 @@ import httplib import urllib import base64 +import copy import hmac import hashlib import json @@ -49,9 +50,16 @@ class cloudConnection(object): sig = urllib.quote_plus(base64.encodestring(hmac.new(self.securityKey, hashStr, hashlib.sha1).digest()).strip()) requestUrl += "&signature=%s"%sig - self.connection.request("GET", "/client/api?%s"%requestUrl) - return self.connection.getresponse().read() + + try: + response = self.connection.getresponse().read() + except httplib.HTTPException: + self.close() + self = copy.copy(self) + else: + return response + return def make_request_without_auth(self, command, requests={}): requests["command"] = command @@ -121,10 +129,10 @@ class cloudConnection(object): else: result = self.make_request_without_auth(commandName, requests) - if self.logging is not None: - self.logging.debug("got result: " + result) if result is None: return None + if self.logging is not None: + self.logging.debug("got result: " + result) result = jsonHelper.getResultObj(result, response) if raw or isAsync == "false": @@ -138,4 +146,4 @@ if __name__ == '__main__': xml = '407i-1-407-RS3i-1-407-RS3system1ROOT2011-07-30T14:45:19-0700Runningfalse1CA13kvm-50-2054CentOS 5.5(64-bit) no GUI (KVM)CentOS 5.5(64-bit) no GUI (KVM)false1Small Instance15005121120NetworkFilesystem380203255.255.255.065.19.181.165.19.181.110vlan://65vlan://65GuestDirecttrue06:52:da:00:00:08KVM' conn = cloudConnection(None) - print conn.paraseReturnXML(xml, deployVirtualMachine.deployVirtualMachineResponse()) \ No newline at end of file + print conn.paraseReturnXML(xml, deployVirtualMachine.deployVirtualMachineResponse()) diff --git a/tools/testClient/remoteSSHClient.py b/tools/testClient/remoteSSHClient.py index 86a7e5c3747..806de7a9eb8 100644 --- a/tools/testClient/remoteSSHClient.py +++ b/tools/testClient/remoteSSHClient.py @@ -1,7 +1,7 @@ import paramiko import cloudstackException class remoteSSHClient(object): - def __init__(self, host, port, user, passwd): + def __init__(self, host, port, user, passwd, timeout=120): self.host = host self.port = port self.user = user @@ -9,7 +9,7 @@ class remoteSSHClient(object): self.ssh = paramiko.SSHClient() self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: - self.ssh.connect(str(host),int(port), user, passwd) + self.ssh.connect(str(host),int(port), user, passwd, timeout=timeout) except paramiko.SSHException, sshex: raise cloudstackException.InvalidParameterException(repr(sshex)) @@ -33,4 +33,4 @@ class remoteSSHClient(object): if __name__ == "__main__": ssh = remoteSSHClient("192.168.137.2", 22, "root", "password") print ssh.execute("ls -l") - print ssh.execute("rm x") \ No newline at end of file + print ssh.execute("rm x")