Added few changes related to bug 4920. Removed unwanted code

There were few unwanted calls as part of test client, did some clean up
Made the test client API uniform to accept both mgmt and dbsvr details
Did some minor bug fixes as well.

Signed-off-by: Santhosh Edukulla <Santhosh.Edukulla@citrix.com>

Conflicts:
	tools/marvin/marvin/cloudstackConnection.py
	tools/marvin/marvin/cloudstackTestClient.py
	tools/marvin/marvin/configGenerator.py
	tools/marvin/marvin/deployDataCenter.py
This commit is contained in:
Santhosh Edukulla 2013-10-23 17:19:36 +05:30 committed by Girish Shilamkar
parent 79ef40c0a9
commit 87983e09e2
5 changed files with 104 additions and 61 deletions

View File

@ -59,9 +59,11 @@ class cloudConnection(object):
% (self.protocol, self.mgtSvr, self.port, self.path)
def __copy__(self):
return cloudConnection(self.mgtSvr, self.port, self.user, self.passwd,
self.apiKey, self.securityKey,
self.asyncTimeout, self.logging, self.protocol,
return cloudConnection(self.mgtSvr, self.port, self.user,
self.passwd, self.apiKey,
self.securityKey,
self.asyncTimeout, self.logging,
self.protocol,
self.path)
def loglevel(self, lvl=logging.WARNING):
@ -83,7 +85,7 @@ class cloudConnection(object):
timeout = self.asyncTimeout
while timeout > 0:
asyncResonse = self.marvin_request(cmd, response_type=response)
asyncResonse = self.marvinRequest(cmd, response_type=response)
if asyncResonse.jobstatus == 2:
raise cloudstackException.cloudstackAPIException(
@ -142,35 +144,38 @@ class cloudConnection(object):
payload["signature"] = signature
try:
'''
https_flag : Signifies whether to verify connection over http or https,
if set to true uses https otherwise http
cert_path : Signifies ca and cert path required by requests library for the connection
'''
https_flag = False
cert_path = ()
#https_flag : Signifies whether to verify connection over \
#http or https, \
#initialized to False, will be set to true if user provided https
#connection
https_flag = False
cert_path = ()
if self.protocol == "https":
https_flag = True
if self.certCAPath != "NA" and self.certPath != "NA":
cert_path = ( self.certCAPath,self.certPath )
if self.certCAPath != "NA" and self.certPath != "NA":
cert_path = (self.certCAPath, self.certPath)
'''
Verify whether protocol is "http", then call the request over http
'''
#Verify whether protocol is "http", then call the request over http
if self.protocol == "http":
if method == 'POST':
response = requests.post(self.baseurl, params=payload, verify=https_flag)
response = requests.post(self.baseurl, params=payload,
verify=https_flag)
else:
response = requests.get(self.baseurl, params=payload, verify=https_flag)
response = requests.get(self.baseurl, params=payload,
verify=https_flag)
else:
'''
If protocol is https, then request the url with user provided certificates provided as part of cert
If protocol is https, then create the connection url with \
user provided certificates \
provided as part of cert
'''
try:
if method == 'POST':
response = requests.post(self.baseurl, params=payload, cert=cert_path, verify=https_flag)
response = requests.post(self.baseurl, params=payload,
cert=cert_path, verify=https_flag)
else:
response = requests.get(self.baseurl, params=payload, cert=cert_path, verify=https_flag)
response = requests.get(self.baseurl, params=payload,
cert=cert_path, verify=https_flag)
except Exception,e:
'''
If an exception occurs with current CA certs,\
@ -180,28 +185,51 @@ class cloudConnection(object):
self.logging.debug( "Creating CS connection over https \
didnt worked with user provided certs %s"%e )
if method == 'POST':
response = requests.post(self.baseurl, params=payload, verify=https_flag)
response = requests.post(self.baseurl,
params=payload,
cert=cert_path,
verify=https_flag)
else:
response = requests.get(self.baseurl, params=payload, verify=https_flag)
response = requests.get(self.baseurl, params=payload,
cert=cert_path,
verify=https_flag)
except Exception, e:
'''
If an exception occurs with user provided CA certs, \
then try with default certs, \
we dont need to mention here the cert path
'''
self.logging.debug("Creating CS connection over https \
didnt worked with user provided certs \
, so trying with no certs %s" % e)
if method == 'POST':
response = requests.post(self.baseurl,
params=payload,
verify=https_flag)
else:
response = requests.get(self.baseurl,
params=payload,
verify=https_flag)
except ConnectionError, c:
self.logging.debug("Connection refused. Reason: %s : %s" %(self.baseurl, c))
self.logging.debug("Connection refused. Reason: %s : %s"
% (self.baseurl, c))
raise c
except HTTPError, h:
self.logging.debug("Server returned error code: %s" % h)
self.logging.debug("Http Error.Server returned error code: %s" % h)
raise h
except Timeout, t:
self.logging.debug("Connection timed out with %s" % t)
raise t
except RequestException, r:
self.logging.debug("Error returned by server %s" % r)
self.logging.debug("RequestException from server %s" % r)
raise r
except Exception, e:
self.logging.debug("Error returned by server %s" % e)
self.logging.debug("Error returned by server %s" % r)
raise e
else:
return response
def sanitize_command(self, cmd):
def sanitizeCommand(self, cmd):
"""
Removes None values, Validates all required params are present
@param cmd: Cmd object eg: createPhysicalNetwork
@ -239,9 +267,9 @@ class cloudConnection(object):
for k, v in val.iteritems():
requests["%s[%d].%s" % (param, i, k)] = v
i = i + 1
return cmdname, isAsync, requests
return cmdname.strip(), isAsync, requests
def marvin_request(self, cmd, response_type=None, method='GET', data=''):
def marvinRequest(self, cmd, response_type=None, method='GET', data=''):
"""
Requester for marvin command objects
@param cmd: marvin's command from cloudstackAPI
@ -249,11 +277,13 @@ class cloudConnection(object):
@param method: HTTP GET/POST, defaults to GET
@return:
"""
cmdname, isAsync, payload = self.sanitize_command(cmd)
cmdname, isAsync, payload = self.sanitizeCommand(cmd)
self.logging.debug("sending %s request: %s %s" % (method, cmdname,
str(payload)))
response = self.request(
cmdname, self.auth, payload=payload, method=method)
response = self.request(cmdname,
self.auth,
payload=payload,
method=method)
self.logging.debug("Request: %s Response: %s" %
(response.url, response.text))
try:

View File

@ -35,11 +35,27 @@ from configGenerator import ConfigManager
logging :
'''
'''
@Desc : CloudStackTestClient is encapsulated class for getting various \
clients viz., apiclient,dbconnection etc
@Input : mgmtDetails : Management Server Details
dbSvrDetails: Database Server details of Management \
Server. Retrieved from configuration file.
asyncTimeout :
defaultWorkerThreads :
logging :
'''
class cloudstackTestClient(object):
def __init__(self,mgmtDetails,asyncTimeout=3600,defaultWorkerThreads=10, logging=None):
def __init__(self, mgmtDetails,
dbSvrDetails, asyncTimeout=3600,
defaultWorkerThreads=10,
logging=None):
self.connection = \
cloudstackConnection.cloudConnection( mgmtDetails,asyncTimeout,logging)
cloudstackConnection.cloudConnection(mgmtDetails,
asyncTimeout,
logging)
self.apiClient =\
cloudstackAPIClient.CloudStackAPIClient(self.connection)
self.dbConnection = None
@ -59,7 +75,6 @@ class cloudstackTestClient(object):
'''
self.configObj = ConfigManager()
self.asyncJobMgr = None
self.ssh = None
self.id = None
self.defaultWorkerThreads = defaultWorkerThreads
@ -93,13 +108,6 @@ class cloudstackTestClient(object):
except:
return 0 # user
def random_gen(self, size=6, chars=string.ascii_uppercase + string.digits):
"""Generate Random Strings of variable length"""
randomstr = ''.join(random.choice(chars) for x in range(size))
if self.identifier:
return ''.join([self.identifier, '-', randomstr])
return randomstr
def createUserApiClient(self, UserName, DomainName, acctType=0):
if not self.isAdminContext():
return self.apiClient

View File

@ -222,7 +222,7 @@ class codeGenerator(object):
body += self.space + self.space
body += 'response = %sResponse()\n' % cmdName
body += self.space + self.space
body += 'response = self.connection.marvin_request(command,'
body += 'response = self.connection.marvinRequest(command,'
body += ' response_type=response, method=method)\n'
body += self.space + self.space + 'return response\n'
body += self.newline

View File

@ -28,9 +28,9 @@ class managementServer(object):
self.port = 8096
self.apiKey = None
self.securityKey = None
self.useHttps = None
self.certCAPath = None
self.certPath = None
self.useHttps = None
self.certCAPath = None
self.certPath = None
class dbServer(object):

View File

@ -32,8 +32,12 @@ class deployDataCenters(object):
if not path.exists(cfgFile) \
and not path.exists(path.abspath(cfgFile)):
raise IOError("config file %s not found. please \
specify a valid config file" % cfgFile)
specify a valid config file" % cfgFile)
self.configFile = cfgFile
'''
parsed configuration information
'''
self.config = None
def addHosts(self, hosts, zoneId, podId, clusterId, hypervisor):
if hosts is None:
@ -514,7 +518,10 @@ specify a valid config file" % cfgFile)
except:
raise cloudstackException.InvalidParameterException("Failed to load config %s" % self.configFile)
''' Retrieving Management Server Connection Details '''
mgtDetails = self.config.mgtSvr[0]
''' Retrieving Database Connection Details'''
dbSvrDetails = self.config.dbSvr
loggers = self.config.logger
testClientLogFile = None
self.testCaseLogFile = None
@ -541,18 +548,19 @@ specify a valid config file" % cfgFile)
self.testClient = \
cloudstackTestClient.\
cloudstackTestClient( mgtDetails,logging=self.testClientLogger)
cloudstackTestClient(mgtDetails,
dbSvrDetails,
logging=self.testClientLogger)
if mgtDetails.apiKey is None:
mgtDetails.apiKey,mgtDetails.securityKey = self.registerApiKey()
mgtDetails.port = 8080
self.testClient = cloudstackTestClient.cloudstackTestClient( mgtDetails,logging=self.testClientLogger)
"""config database"""
dbSvr = self.config.dbSvr
if dbSvr is not None:
self.testClient.dbConfigure(dbSvr.dbSvr, dbSvr.port, dbSvr.user, \
dbSvr.passwd, dbSvr.db)
mgtDetails.apiKey, mgtDetails.securityKey = self.registerApiKey()
mgtDetails.port = 8080
self.testClient = \
cloudstackTestClient.cloudstackTestClient(
mgtDetails,
dbSvrDetails,
logging=
self.testClientLogger)
self.apiClient = self.testClient.getApiClient()
"""set hypervisor"""
@ -591,16 +599,13 @@ specify a valid config file" % cfgFile)
self.configureS3(self.config.s3)
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-i", "--input", action="store",
default="./datacenterCfg", dest="input", help="the path \
where the json config file generated, by default is \
./datacenterCfg")
(options, args) = parser.parse_args()
deploy = deployDataCenters(options.input)
deploy.deploy()