Skip to content

Commit 2000005

Browse files
author
Prasanna Santhanam
committed
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 17af34f)
1 parent b8148c6 commit 2000005

6 files changed

Lines changed: 56 additions & 30 deletions

File tree

‎tools/marvin/marvin/cloudstackTestCase.py‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from cloudstackAPI import *
1918
import unittest
20-
import cloudstackTestClient
21-
22-
#class UserName(object):
23-
# def __init__(self, account, domain, type=0):
24-
# self.account = account
25-
# self.domain = domain
26-
# self.accounttype = type
27-
# def __call__(self, cls):
28-
# class Wrapped(cls):
29-
# cls.UserName = self.account
30-
# cls.DomainName = self.domain
31-
# cls.AcctType = self.accounttype
32-
# return Wrapped
33-
3419

3520
def user(Name, DomainName, AcctType):
3621
def wrapper(cls):
@@ -51,7 +36,6 @@ class cloudstackTestCase(unittest.case.TestCase):
5136

5237
def __init__(self, args):
5338
unittest.case.TestCase.__init__(self, args)
54-
# self.testClient = cloudstackTestClient.cloudstackTestClient()
5539

5640
@classmethod
5741
def getClsTestClient(cls):

‎tools/marvin/marvin/cloudstackTestClient.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,17 @@ def __init__(self, mgtSvr=None, port=8096, user=None, passwd=None,
3737
self.dbConnection = None
3838
self.asyncJobMgr = None
3939
self.ssh = None
40+
self.id = None
4041
self.defaultWorkerThreads = defaultWorkerThreads
4142

43+
@property
44+
def identifier(self):
45+
return self.id
46+
47+
@identifier.setter
48+
def identifier(self, id):
49+
self.id = id
50+
4251
def dbConfigure(self, host="localhost", port=3306, user='cloud',
4352
passwd='cloud', db='cloud'):
4453
self.dbConnection = dbConnection.dbConnection(host, port, user, passwd,
@@ -64,7 +73,10 @@ def isAdminContext(self):
6473

6574
def random_gen(self, size=6, chars=string.ascii_uppercase + string.digits):
6675
"""Generate Random Strings of variable length"""
67-
return ''.join(random.choice(chars) for x in range(size))
76+
randomstr = ''.join(random.choice(chars) for x in range(size))
77+
if self.identifier:
78+
return ''.join([self.identifier, '-', randomstr])
79+
return randomstr
6880

6981
def createUserApiClient(self, UserName, DomainName, acctType=0):
7082
if not self.isAdminContext():
@@ -153,6 +165,7 @@ def executeSqlFromFile(self, sqlFile=None):
153165
return self.dbConnection.executeSqlFromFile(sqlFile)
154166

155167
def getApiClient(self):
168+
self.apiClient.id = self.identifier
156169
return self.apiClient
157170

158171
def getUserApiClient(self, account, domain, type=0):
@@ -189,4 +202,4 @@ def submitJobs(self, jobs, nums_threads=10, interval=1):
189202
if self.asyncJobMgr is None:
190203
self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient,
191204
self.dbConnection)
192-
self.asyncJobMgr.submitJobs(jobs, nums_threads, interval)
205+
self.asyncJobMgr.submitJobs(jobs, nums_threads, interval)

‎tools/marvin/marvin/codegenerator.py‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class codeGenerator(object):
4848
returned by API discovery or from the xml spec of commands generated by
4949
the ApiDocWriter. This class provides helper methods for these uses.
5050
"""
51-
space = " "
51+
space = ' '
52+
newline = '\n'
5253
cmdsName = []
5354

5455
def __init__(self, outputFolder):
@@ -86,11 +87,11 @@ def addAttribute(self, attr, pro):
8687
if desc is not None:
8788
self.code += self.space
8889
self.code += "''' " + pro.desc + " '''"
89-
self.code += "\n"
90+
self.code += self.newline
9091

9192
self.code += self.space
9293
self.code += attr + " = " + str(value)
93-
self.code += "\n"
94+
self.code += self.newline
9495

9596
def generateSubClass(self, name, properties):
9697
'''generate code for sub list'''
@@ -114,7 +115,7 @@ def generate(self, cmd):
114115
self.cmd = cmd
115116
self.cmdsName.append(self.cmd.name)
116117
self.code = self.license
117-
self.code += "\n"
118+
self.code += self.newline
118119
self.code += '"""%s"""\n' % self.cmd.desc
119120
self.code += 'from baseCmd import *\n'
120121
self.code += 'from baseResponse import *\n'
@@ -147,7 +148,7 @@ def generate(self, cmd):
147148

148149
"""generate response code"""
149150
subItems = {}
150-
self.code += "\n"
151+
self.code += self.newline
151152
self.code += 'class %sResponse (baseResponse):\n' % self.cmd.name
152153
self.code += self.space + "def __init__(self):\n"
153154
if len(self.cmd.response) == 0:
@@ -165,7 +166,7 @@ def generate(self, cmd):
165166
else:
166167
self.code += self.space + self.space
167168
self.code += 'self.%s = None\n' % res.name
168-
self.code += '\n'
169+
self.code += self.newline
169170

170171
for subclass in self.subclass:
171172
self.code += subclass + "\n"
@@ -187,12 +188,33 @@ def finalize(self):
187188
body += "class CloudStackAPIClient(object):\n"
188189
body += self.space + 'def __init__(self, connection):\n'
189190
body += self.space + self.space + 'self.connection = connection\n'
190-
body += "\n"
191+
body += self.space + self.space + 'self._id = None\n'
192+
body += self.newline
191193

192194
body += self.space + 'def __copy__(self):\n'
193195
body += self.space + self.space
194196
body += 'return CloudStackAPIClient(copy.copy(self.connection))\n'
195-
body += "\n"
197+
body += self.newline
198+
199+
# The `id` property will be used to link the test with the cloud resource being created #
200+
# @property
201+
# def id(self):
202+
# return self._id
203+
#
204+
# @id.setter
205+
# def id(self, identifier):
206+
# self._id = identifier
207+
208+
209+
body += self.space + '@property' + self.newline
210+
body += self.space + 'def id(self):' + self.newline
211+
body += self.space*2 + 'return self._id' + self.newline
212+
body += self.newline
213+
214+
body += self.space + '@id.setter' + self.newline
215+
body += self.space + 'def id(self, identifier):' + self.newline
216+
body += self.space*2 + 'self._id = identifier' + self.newline
217+
body += self.newline
196218

197219
for cmdName in self.cmdsName:
198220
body += self.space
@@ -203,7 +225,7 @@ def finalize(self):
203225
body += 'response = self.connection.marvin_request(command,'
204226
body += ' response_type=response, method=method)\n'
205227
body += self.space + self.space + 'return response\n'
206-
body += '\n'
228+
body += self.newline
207229

208230
imports += 'from %s import %sResponse\n' % (cmdName, cmdName)
209231
initCmdsList += '"%s",' % cmdName

‎tools/marvin/marvin/integration/lib/base.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def create(cls, apiclient, services, admin=False, domainid=None):
9898
cmd.lastname = services["lastname"]
9999

100100
cmd.password = services["password"]
101-
cmd.username = "-".join([services["username"], random_gen()])
101+
cmd.username = "-".join([services["username"], random_gen(id=apiclient.id)])
102102

103103
if "accountUUID" in services:
104104
cmd.accountid = "-".join([services["accountUUID"],random_gen()])

‎tools/marvin/marvin/integration/lib/utils.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ def get_first_text_block(email_message_instance):
9595
return email_message_instance.get_payload()
9696

9797

98-
def random_gen(size=6, chars=string.ascii_uppercase + string.digits):
98+
def random_gen(id=None, size=6, chars=string.ascii_uppercase + string.digits):
9999
"""Generate Random Strings of variable length"""
100-
return ''.join(random.choice(chars) for x in range(size))
100+
randomstr = ''.join(random.choice(chars) for x in range(size))
101+
if id:
102+
return ''.join([id, '-', randomstr])
103+
return randomstr
101104

102105

103106
def cleanup_resources(api_client, resources):

‎tools/marvin/marvin/marvinPlugin.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,17 @@ def setConfig(self, config):
125125
if config is not None:
126126
self.config = config
127127

128+
def beforeTest(self, test):
129+
self.testclient.identifier = test.__str__().split()[0]
130+
128131
def _injectClients(self, test):
129132
testcaselogger = logging.getLogger("testclient.testcase.%s" %
130133
test.__name__)
131134
self.debug_stream. \
132135
setFormatter(logging.
133136
Formatter("%(asctime)s - %(levelname)s - %(name)s" +
134137
" - %(message)s"))
138+
135139
testcaselogger.addHandler(self.debug_stream)
136140
testcaselogger.setLevel(logging.DEBUG)
137141

0 commit comments

Comments
 (0)