55# to you under the Apache License, Version 2.0 (the
66# "License"); you may not use this file except in compliance
77# with the License. You may obtain a copy of the License at
8- #
8+ #
99# http://www.apache.org/licenses/LICENSE-2.0
10- #
10+ #
1111# Unless required by applicable law or agreed to in writing,
1212# software distributed under the License is distributed on an
1313# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
2323import string
2424import hashlib
2525
26+
2627class cloudstackTestClient (object ):
2728 def __init__ (self , mgtSvr = None , port = 8096 , user = None , passwd = None ,
2829 apiKey = None , securityKey = None , asyncTimeout = 3600 ,
2930 defaultWorkerThreads = 10 , logging = None ):
3031 self .connection = \
31- cloudstackConnection .cloudConnection (
32- mgtSvr , port , user ,
33- passwd , apiKey , securityKey ,
34- asyncTimeout , logging )
35- self . apiClient = cloudstackAPIClient .CloudStackAPIClient (self .connection )
32+ cloudstackConnection .cloudConnection (mgtSvr , port , user , passwd ,
33+ apiKey , securityKey ,
34+ asyncTimeout , logging )
35+ self . apiClient = \
36+ cloudstackAPIClient .CloudStackAPIClient (self .connection )
3637 self .dbConnection = None
3738 self .asyncJobMgr = None
3839 self .ssh = None
3940 self .defaultWorkerThreads = defaultWorkerThreads
4041
41- def dbConfigure (self , host = "localhost" , port = 3306 , user = 'cloud' , passwd = 'cloud' , db = 'cloud' ):
42- self .dbConnection = dbConnection .dbConnection (host , port , user , passwd , db )
42+ def dbConfigure (self , host = "localhost" , port = 3306 , user = 'cloud' ,
43+ passwd = 'cloud' , db = 'cloud' ):
44+ self .dbConnection = dbConnection .dbConnection (host , port , user , passwd ,
45+ db )
4346
4447 def isAdminContext (self ):
4548 """
@@ -53,11 +56,11 @@ def isAdminContext(self):
5356 listdomres = self .apiClient .listDomains (listdom )
5457 rootdom = listdomres [0 ].name
5558 if rootdom == 'ROOT' :
56- return 1 # admin
59+ return 1 # admin
5760 else :
58- return 2 # domain-admin
61+ return 2 # domain-admin
5962 except :
60- return 0 # user
63+ return 0 # user
6164
6265 def random_gen (self , size = 6 , chars = string .ascii_uppercase + string .digits ):
6366 """Generate Random Strings of variable length"""
@@ -93,7 +96,8 @@ def createUserApiClient(self, UserName, DomainName, acctType=0):
9396 createAcctCmd = createAccount .createAccountCmd ()
9497 createAcctCmd .accounttype = acctType
9598 createAcctCmd .domainid = domId
96- createAcctCmd .email = "test-" + self .random_gen () + "@cloudstack.org"
99+ createAcctCmd .email = "test-" + self .random_gen ()\
100+ + "@cloudstack.org"
97101 createAcctCmd .firstname = UserName
98102 createAcctCmd .lastname = UserName
99103 createAcctCmd .password = mdf_pass
@@ -116,10 +120,16 @@ def createUserApiClient(self, UserName, DomainName, acctType=0):
116120 apiKey = registerUserRes .apikey
117121 securityKey = registerUserRes .secretkey
118122
119- newUserConnection = cloudstackConnection .cloudConnection (self .connection .mgtSvr , self .connection .port ,
120- self .connection .user , self .connection .passwd ,
121- apiKey , securityKey , self .connection .asyncTimeout , self .connection .logging )
122- self .userApiClient = cloudstackAPIClient .CloudStackAPIClient (newUserConnection )
123+ newUserConnection = \
124+ cloudstackConnection .cloudConnection (self .connection .mgtSvr ,
125+ self .connection .port ,
126+ self .connection .user ,
127+ self .connection .passwd ,
128+ apiKey , securityKey ,
129+ self .connection .asyncTimeout ,
130+ self .connection .logging )
131+ self .userApiClient = \
132+ cloudstackAPIClient .CloudStackAPIClient (newUserConnection )
123133 self .userApiClient .connection = newUserConnection
124134 self .userApiClient .hypervisor = self .apiClient .hypervisor
125135 return self .userApiClient
@@ -156,24 +166,27 @@ def getUserApiClient(self, account, domain, type=0):
156166 return self .userApiClient
157167 return None
158168
159-
160- '''FixME, httplib has issue if more than one thread submitted'''
161-
162169 def submitCmdsAndWait (self , cmds , workers = 1 ):
170+ '''FixME, httplib has issue if more than one thread submitted'''
163171 if self .asyncJobMgr is None :
164- self .asyncJobMgr = asyncJobMgr .asyncJobMgr (self .apiClient , self .dbConnection )
172+ self .asyncJobMgr = asyncJobMgr .asyncJobMgr (self .apiClient ,
173+ self .dbConnection )
165174 return self .asyncJobMgr .submitCmdsAndWait (cmds , workers )
166175
167- '''submit one job and execute the same job ntimes, with nums_threads of threads'''
168-
169176 def submitJob (self , job , ntimes = 1 , nums_threads = 10 , interval = 1 ):
177+ '''
178+ submit one job and execute the same job ntimes, with nums_threads
179+ of threads
180+ '''
170181 if self .asyncJobMgr is None :
171- self .asyncJobMgr = asyncJobMgr .asyncJobMgr (self .apiClient , self . dbConnection )
172- self . asyncJobMgr . submitJobExecuteNtimes ( job , ntimes , nums_threads , interval )
173-
174- '''submit n jobs, execute them with nums_threads of threads'''
182+ self .asyncJobMgr = asyncJobMgr .asyncJobMgr (self .apiClient ,
183+ self . dbConnection )
184+ self . asyncJobMgr . submitJobExecuteNtimes ( job , ntimes , nums_threads ,
185+ interval )
175186
176187 def submitJobs (self , jobs , nums_threads = 10 , interval = 1 ):
188+ '''submit n jobs, execute them with nums_threads of threads'''
177189 if self .asyncJobMgr is None :
178- self .asyncJobMgr = asyncJobMgr .asyncJobMgr (self .apiClient , self .dbConnection )
190+ self .asyncJobMgr = asyncJobMgr .asyncJobMgr (self .apiClient ,
191+ self .dbConnection )
179192 self .asyncJobMgr .submitJobs (jobs , nums_threads , interval )
0 commit comments