CLOUDSTACK-3075: append test case name to account

Accounts will be prepended by the testcase name to ease analysis
post-test runs.

Signed-off-by: Prasanna Santhanam <tsp@apache.org>
(cherry picked from commit 17af34fd19ba9aa310a416e8e8cb80de37a018c2)
This commit is contained in:
Prasanna Santhanam 2013-07-20 15:53:14 +05:30
parent b8148c6220
commit 2000005f90
6 changed files with 56 additions and 30 deletions

View File

@ -15,22 +15,7 @@
# specific language governing permissions and limitations
# under the License.
from cloudstackAPI import *
import unittest
import cloudstackTestClient
#class UserName(object):
# def __init__(self, account, domain, type=0):
# self.account = account
# self.domain = domain
# self.accounttype = type
# def __call__(self, cls):
# class Wrapped(cls):
# cls.UserName = self.account
# cls.DomainName = self.domain
# cls.AcctType = self.accounttype
# return Wrapped
def user(Name, DomainName, AcctType):
def wrapper(cls):
@ -51,7 +36,6 @@ class cloudstackTestCase(unittest.case.TestCase):
def __init__(self, args):
unittest.case.TestCase.__init__(self, args)
# self.testClient = cloudstackTestClient.cloudstackTestClient()
@classmethod
def getClsTestClient(cls):

View File

@ -37,8 +37,17 @@ class cloudstackTestClient(object):
self.dbConnection = None
self.asyncJobMgr = None
self.ssh = None
self.id = None
self.defaultWorkerThreads = defaultWorkerThreads
@property
def identifier(self):
return self.id
@identifier.setter
def identifier(self, id):
self.id = id
def dbConfigure(self, host="localhost", port=3306, user='cloud',
passwd='cloud', db='cloud'):
self.dbConnection = dbConnection.dbConnection(host, port, user, passwd,
@ -64,7 +73,10 @@ class cloudstackTestClient(object):
def random_gen(self, size=6, chars=string.ascii_uppercase + string.digits):
"""Generate Random Strings of variable length"""
return ''.join(random.choice(chars) for x in range(size))
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():
@ -153,6 +165,7 @@ class cloudstackTestClient(object):
return self.dbConnection.executeSqlFromFile(sqlFile)
def getApiClient(self):
self.apiClient.id = self.identifier
return self.apiClient
def getUserApiClient(self, account, domain, type=0):
@ -189,4 +202,4 @@ class cloudstackTestClient(object):
if self.asyncJobMgr is None:
self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient,
self.dbConnection)
self.asyncJobMgr.submitJobs(jobs, nums_threads, interval)
self.asyncJobMgr.submitJobs(jobs, nums_threads, interval)

View File

@ -48,7 +48,8 @@ class codeGenerator(object):
returned by API discovery or from the xml spec of commands generated by
the ApiDocWriter. This class provides helper methods for these uses.
"""
space = " "
space = ' '
newline = '\n'
cmdsName = []
def __init__(self, outputFolder):
@ -86,11 +87,11 @@ class codeGenerator(object):
if desc is not None:
self.code += self.space
self.code += "''' " + pro.desc + " '''"
self.code += "\n"
self.code += self.newline
self.code += self.space
self.code += attr + " = " + str(value)
self.code += "\n"
self.code += self.newline
def generateSubClass(self, name, properties):
'''generate code for sub list'''
@ -114,7 +115,7 @@ class codeGenerator(object):
self.cmd = cmd
self.cmdsName.append(self.cmd.name)
self.code = self.license
self.code += "\n"
self.code += self.newline
self.code += '"""%s"""\n' % self.cmd.desc
self.code += 'from baseCmd import *\n'
self.code += 'from baseResponse import *\n'
@ -147,7 +148,7 @@ class codeGenerator(object):
"""generate response code"""
subItems = {}
self.code += "\n"
self.code += self.newline
self.code += 'class %sResponse (baseResponse):\n' % self.cmd.name
self.code += self.space + "def __init__(self):\n"
if len(self.cmd.response) == 0:
@ -165,7 +166,7 @@ class codeGenerator(object):
else:
self.code += self.space + self.space
self.code += 'self.%s = None\n' % res.name
self.code += '\n'
self.code += self.newline
for subclass in self.subclass:
self.code += subclass + "\n"
@ -187,12 +188,33 @@ class codeGenerator(object):
body += "class CloudStackAPIClient(object):\n"
body += self.space + 'def __init__(self, connection):\n'
body += self.space + self.space + 'self.connection = connection\n'
body += "\n"
body += self.space + self.space + 'self._id = None\n'
body += self.newline
body += self.space + 'def __copy__(self):\n'
body += self.space + self.space
body += 'return CloudStackAPIClient(copy.copy(self.connection))\n'
body += "\n"
body += self.newline
# The `id` property will be used to link the test with the cloud resource being created #
# @property
# def id(self):
# return self._id
#
# @id.setter
# def id(self, identifier):
# self._id = identifier
body += self.space + '@property' + self.newline
body += self.space + 'def id(self):' + self.newline
body += self.space*2 + 'return self._id' + self.newline
body += self.newline
body += self.space + '@id.setter' + self.newline
body += self.space + 'def id(self, identifier):' + self.newline
body += self.space*2 + 'self._id = identifier' + self.newline
body += self.newline
for cmdName in self.cmdsName:
body += self.space
@ -203,7 +225,7 @@ class codeGenerator(object):
body += 'response = self.connection.marvin_request(command,'
body += ' response_type=response, method=method)\n'
body += self.space + self.space + 'return response\n'
body += '\n'
body += self.newline
imports += 'from %s import %sResponse\n' % (cmdName, cmdName)
initCmdsList += '"%s",' % cmdName

View File

@ -98,7 +98,7 @@ class Account:
cmd.lastname = services["lastname"]
cmd.password = services["password"]
cmd.username = "-".join([services["username"], random_gen()])
cmd.username = "-".join([services["username"], random_gen(id=apiclient.id)])
if "accountUUID" in services:
cmd.accountid = "-".join([services["accountUUID"],random_gen()])

View File

@ -95,9 +95,12 @@ def get_first_text_block(email_message_instance):
return email_message_instance.get_payload()
def random_gen(size=6, chars=string.ascii_uppercase + string.digits):
def random_gen(id=None, size=6, chars=string.ascii_uppercase + string.digits):
"""Generate Random Strings of variable length"""
return ''.join(random.choice(chars) for x in range(size))
randomstr = ''.join(random.choice(chars) for x in range(size))
if id:
return ''.join([id, '-', randomstr])
return randomstr
def cleanup_resources(api_client, resources):

View File

@ -125,6 +125,9 @@ class MarvinPlugin(Plugin):
if config is not None:
self.config = config
def beforeTest(self, test):
self.testclient.identifier = test.__str__().split()[0]
def _injectClients(self, test):
testcaselogger = logging.getLogger("testclient.testcase.%s" %
test.__name__)
@ -132,6 +135,7 @@ class MarvinPlugin(Plugin):
setFormatter(logging.
Formatter("%(asctime)s - %(levelname)s - %(name)s" +
" - %(message)s"))
testcaselogger.addHandler(self.debug_stream)
testcaselogger.setLevel(logging.DEBUG)