mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-3096 format cloudsteackTestClient.py
This commit is contained in:
parent
08d4ab79f2
commit
3fdcf1836c
|
|
@ -5,9 +5,9 @@
|
|||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
|
@ -23,23 +23,26 @@ import random
|
|||
import string
|
||||
import hashlib
|
||||
|
||||
|
||||
class cloudstackTestClient(object):
|
||||
def __init__(self, mgtSvr=None, port=8096, user=None, passwd=None,
|
||||
apiKey=None, securityKey=None, asyncTimeout=3600,
|
||||
defaultWorkerThreads=10, logging=None):
|
||||
self.connection = \
|
||||
cloudstackConnection.cloudConnection(
|
||||
mgtSvr, port, user,
|
||||
passwd, apiKey, securityKey,
|
||||
asyncTimeout, logging)
|
||||
self.apiClient = cloudstackAPIClient.CloudStackAPIClient(self.connection)
|
||||
cloudstackConnection.cloudConnection(mgtSvr, port, user, passwd,
|
||||
apiKey, securityKey,
|
||||
asyncTimeout, logging)
|
||||
self.apiClient =\
|
||||
cloudstackAPIClient.CloudStackAPIClient(self.connection)
|
||||
self.dbConnection = None
|
||||
self.asyncJobMgr = None
|
||||
self.ssh = None
|
||||
self.defaultWorkerThreads = defaultWorkerThreads
|
||||
|
||||
def dbConfigure(self, host="localhost", port=3306, user='cloud', passwd='cloud', db='cloud'):
|
||||
self.dbConnection = dbConnection.dbConnection(host, port, user, passwd, db)
|
||||
def dbConfigure(self, host="localhost", port=3306, user='cloud',
|
||||
passwd='cloud', db='cloud'):
|
||||
self.dbConnection = dbConnection.dbConnection(host, port, user, passwd,
|
||||
db)
|
||||
|
||||
def isAdminContext(self):
|
||||
"""
|
||||
|
|
@ -53,11 +56,11 @@ class cloudstackTestClient(object):
|
|||
listdomres = self.apiClient.listDomains(listdom)
|
||||
rootdom = listdomres[0].name
|
||||
if rootdom == 'ROOT':
|
||||
return 1 #admin
|
||||
return 1 # admin
|
||||
else:
|
||||
return 2 #domain-admin
|
||||
return 2 # domain-admin
|
||||
except:
|
||||
return 0 #user
|
||||
return 0 # user
|
||||
|
||||
def random_gen(self, size=6, chars=string.ascii_uppercase + string.digits):
|
||||
"""Generate Random Strings of variable length"""
|
||||
|
|
@ -93,7 +96,8 @@ class cloudstackTestClient(object):
|
|||
createAcctCmd = createAccount.createAccountCmd()
|
||||
createAcctCmd.accounttype = acctType
|
||||
createAcctCmd.domainid = domId
|
||||
createAcctCmd.email = "test-" + self.random_gen() + "@cloudstack.org"
|
||||
createAcctCmd.email = "test-" + self.random_gen()\
|
||||
+ "@cloudstack.org"
|
||||
createAcctCmd.firstname = UserName
|
||||
createAcctCmd.lastname = UserName
|
||||
createAcctCmd.password = mdf_pass
|
||||
|
|
@ -116,10 +120,16 @@ class cloudstackTestClient(object):
|
|||
apiKey = registerUserRes.apikey
|
||||
securityKey = registerUserRes.secretkey
|
||||
|
||||
newUserConnection = cloudstackConnection.cloudConnection(self.connection.mgtSvr, self.connection.port,
|
||||
self.connection.user, self.connection.passwd,
|
||||
apiKey, securityKey, self.connection.asyncTimeout, self.connection.logging)
|
||||
self.userApiClient = cloudstackAPIClient.CloudStackAPIClient(newUserConnection)
|
||||
newUserConnection =\
|
||||
cloudstackConnection.cloudConnection(self.connection.mgtSvr,
|
||||
self.connection.port,
|
||||
self.connection.user,
|
||||
self.connection.passwd,
|
||||
apiKey, securityKey,
|
||||
self.connection.asyncTimeout,
|
||||
self.connection.logging)
|
||||
self.userApiClient =\
|
||||
cloudstackAPIClient.CloudStackAPIClient(newUserConnection)
|
||||
self.userApiClient.connection = newUserConnection
|
||||
self.userApiClient.hypervisor = self.apiClient.hypervisor
|
||||
return self.userApiClient
|
||||
|
|
@ -156,24 +166,27 @@ class cloudstackTestClient(object):
|
|||
return self.userApiClient
|
||||
return None
|
||||
|
||||
|
||||
'''FixME, httplib has issue if more than one thread submitted'''
|
||||
|
||||
def submitCmdsAndWait(self, cmds, workers=1):
|
||||
'''FixME, httplib has issue if more than one thread submitted'''
|
||||
if self.asyncJobMgr is None:
|
||||
self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient, self.dbConnection)
|
||||
self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient,
|
||||
self.dbConnection)
|
||||
return self.asyncJobMgr.submitCmdsAndWait(cmds, workers)
|
||||
|
||||
'''submit one job and execute the same job ntimes, with nums_threads of threads'''
|
||||
|
||||
def submitJob(self, job, ntimes=1, nums_threads=10, interval=1):
|
||||
'''
|
||||
submit one job and execute the same job ntimes, with nums_threads
|
||||
of threads
|
||||
'''
|
||||
if self.asyncJobMgr is None:
|
||||
self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient, self.dbConnection)
|
||||
self.asyncJobMgr.submitJobExecuteNtimes(job, ntimes, nums_threads, interval)
|
||||
|
||||
'''submit n jobs, execute them with nums_threads of threads'''
|
||||
self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient,
|
||||
self.dbConnection)
|
||||
self.asyncJobMgr.submitJobExecuteNtimes(job, ntimes, nums_threads,
|
||||
interval)
|
||||
|
||||
def submitJobs(self, jobs, nums_threads=10, interval=1):
|
||||
'''submit n jobs, execute them with nums_threads of threads'''
|
||||
if self.asyncJobMgr is None:
|
||||
self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient, self.dbConnection)
|
||||
self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient,
|
||||
self.dbConnection)
|
||||
self.asyncJobMgr.submitJobs(jobs, nums_threads, interval)
|
||||
|
|
|
|||
Loading…
Reference in New Issue