mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 13234: add UserName decorator on testcase, in the form of (username, domainName, accountType). status 13234: resolved fixed. Reviewed-by: prasanna
This commit is contained in:
parent
728f079bed
commit
5a06ddb36a
@ -52,6 +52,8 @@ class TestCaseExecuteEngine(object):
|
|||||||
setattr(test, "debug", partial(testCaseLogger, logger=testcaselogger))
|
setattr(test, "debug", partial(testCaseLogger, logger=testcaselogger))
|
||||||
setattr(test.__class__, "clstestclient", self.testclient)
|
setattr(test.__class__, "clstestclient", self.testclient)
|
||||||
|
|
||||||
|
if hasattr(test, "UserName"):
|
||||||
|
self.testclient.createNewApiClient(test.UserName, test.DomainName, test.AcctType)
|
||||||
def run(self):
|
def run(self):
|
||||||
loader = unittest.loader.TestLoader()
|
loader = unittest.loader.TestLoader()
|
||||||
suite = loader.discover(self.testCaseFolder)
|
suite = loader.discover(self.testCaseFolder)
|
||||||
|
|||||||
@ -5,6 +5,17 @@ except ImportError:
|
|||||||
import unittest
|
import unittest
|
||||||
import cloudstackTestClient
|
import cloudstackTestClient
|
||||||
|
|
||||||
|
def UserName(Name, DomainName, AcctType):
|
||||||
|
def wrapper(cls):
|
||||||
|
orig_init = cls.__init__
|
||||||
|
def __init__(self, *args, **kws):
|
||||||
|
cls.UserName = Name
|
||||||
|
cls.DomainName = DomainName
|
||||||
|
cls.AcctType = AcctType
|
||||||
|
orig_init(self, *args, **kws)
|
||||||
|
cls.__init__ = __init__
|
||||||
|
return cls
|
||||||
|
return wrapper
|
||||||
class cloudstackTestCase(unittest.case.TestCase):
|
class cloudstackTestCase(unittest.case.TestCase):
|
||||||
clstestclient = None
|
clstestclient = None
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import cloudstackConnection
|
import cloudstackConnection
|
||||||
import asyncJobMgr
|
import asyncJobMgr
|
||||||
import dbConnection
|
import dbConnection
|
||||||
|
import uuid
|
||||||
from cloudstackAPI import *
|
from cloudstackAPI import *
|
||||||
|
|
||||||
class cloudstackTestClient(object):
|
class cloudstackTestClient(object):
|
||||||
@ -16,6 +17,56 @@ class cloudstackTestClient(object):
|
|||||||
def dbConfigure(self, host="localhost", port=3306, user='cloud', passwd='cloud', db='cloud'):
|
def dbConfigure(self, host="localhost", port=3306, user='cloud', passwd='cloud', db='cloud'):
|
||||||
self.dbConnection = dbConnection.dbConnection(host, port, user, passwd, db)
|
self.dbConnection = dbConnection.dbConnection(host, port, user, passwd, db)
|
||||||
|
|
||||||
|
def createNewApiClient(self, UserName, DomainName, acctType):
|
||||||
|
listDomain = listDomains.listDomainsCmd()
|
||||||
|
listDomain.name = DomainName
|
||||||
|
try:
|
||||||
|
domains = self.apiClient.listDomains(listDomain)
|
||||||
|
domId = domains[0].id
|
||||||
|
except:
|
||||||
|
cdomain = createDomain.createDomainCmd()
|
||||||
|
cdomain.name = DomainName
|
||||||
|
domain = self.apiClient.createDomain(cdomain)
|
||||||
|
domId = domain.id
|
||||||
|
|
||||||
|
cmd = listAccounts.listAccountsCmd()
|
||||||
|
cmd.name = UserName
|
||||||
|
exist = True
|
||||||
|
try:
|
||||||
|
accounts = self.apiClient.listAccounts(cmd)
|
||||||
|
acctId = accounts[0].id
|
||||||
|
except:
|
||||||
|
createAcctCmd = createAccount.createAccountCmd()
|
||||||
|
createAcctCmd.accounttype = acctType
|
||||||
|
createAcctCmd.domainid = domId
|
||||||
|
createAcctCmd.email = str(uuid.uuid4()) + "@citrix.com"
|
||||||
|
createAcctCmd.firstname = UserName
|
||||||
|
createAcctCmd.lastname = UserName
|
||||||
|
createAcctCmd.password = "password"
|
||||||
|
createAcctCmd.username = UserName
|
||||||
|
acct = self.apiClient.createAccount(createAcctCmd)
|
||||||
|
acctId = acct.id
|
||||||
|
|
||||||
|
listuser = listUsers.listUsersCmd()
|
||||||
|
listuser.username = UserName
|
||||||
|
|
||||||
|
listuserRes = self.apiClient.listUsers(listuser)
|
||||||
|
userId = listuserRes[0].id
|
||||||
|
apiKey = listuserRes[0].apikey
|
||||||
|
securityKey = listuserRes[0].secretkey
|
||||||
|
|
||||||
|
if apiKey is None:
|
||||||
|
registerUser = registerUserKeys.registerUserKeysCmd()
|
||||||
|
registerUser.id = userId
|
||||||
|
registerUserRes = self.apiClient.registerUserKeys(registerUser)
|
||||||
|
apiKey = registerUserRes.apikey
|
||||||
|
securityKey = registerUserRes.secretkey
|
||||||
|
|
||||||
|
nConnection = cloudstackConnection.cloudConnection(self.connection.mgtSvr, self.connection.port, apiKey, securityKey, self.connection.asyncTimeout, self.connection.logging)
|
||||||
|
self.connection.close()
|
||||||
|
self.connection = nConnection
|
||||||
|
|
||||||
|
self.apiClient = cloudstackAPIClient.CloudStackAPIClient(self.connection)
|
||||||
def close(self):
|
def close(self):
|
||||||
if self.connection is not None:
|
if self.connection is not None:
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
from cloudstackTestCase import *
|
from cloudstackTestCase import *
|
||||||
|
|
||||||
|
@UserName("edison", "edison", "0")
|
||||||
class TestCase1(cloudstackTestCase):
|
class TestCase1(cloudstackTestCase):
|
||||||
|
|
||||||
def test_cloudstackapi(self):
|
def test_cloudstackapi(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user