You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2013/07/20 12:37:34 UTC

git commit: updated refs/heads/4.2 to 17af34f

Updated Branches:
  refs/heads/4.2 9c9003a0d -> 17af34fd1


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 <ts...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/17af34fd
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/17af34fd
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/17af34fd

Branch: refs/heads/4.2
Commit: 17af34fd19ba9aa310a416e8e8cb80de37a018c2
Parents: 9c9003a
Author: Prasanna Santhanam <ts...@apache.org>
Authored: Sat Jul 20 15:53:14 2013 +0530
Committer: Prasanna Santhanam <ts...@apache.org>
Committed: Sat Jul 20 15:53:14 2013 +0530

----------------------------------------------------------------------
 tools/marvin/marvin/cloudstackTestCase.py    | 16 ---------
 tools/marvin/marvin/cloudstackTestClient.py  | 17 ++++++++--
 tools/marvin/marvin/codegenerator.py         | 40 ++++++++++++++++++-----
 tools/marvin/marvin/integration/lib/base.py  |  2 +-
 tools/marvin/marvin/integration/lib/utils.py |  7 ++--
 tools/marvin/marvin/marvinPlugin.py          |  4 +++
 6 files changed, 56 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17af34fd/tools/marvin/marvin/cloudstackTestCase.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/cloudstackTestCase.py b/tools/marvin/marvin/cloudstackTestCase.py
index 114928c..742363d 100644
--- a/tools/marvin/marvin/cloudstackTestCase.py
+++ b/tools/marvin/marvin/cloudstackTestCase.py
@@ -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):

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17af34fd/tools/marvin/marvin/cloudstackTestClient.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/cloudstackTestClient.py b/tools/marvin/marvin/cloudstackTestClient.py
index ea32b90..eba53a1 100644
--- a/tools/marvin/marvin/cloudstackTestClient.py
+++ b/tools/marvin/marvin/cloudstackTestClient.py
@@ -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)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17af34fd/tools/marvin/marvin/codegenerator.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/codegenerator.py b/tools/marvin/marvin/codegenerator.py
index 632b8c6..e37dbcc 100644
--- a/tools/marvin/marvin/codegenerator.py
+++ b/tools/marvin/marvin/codegenerator.py
@@ -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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17af34fd/tools/marvin/marvin/integration/lib/base.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/base.py b/tools/marvin/marvin/integration/lib/base.py
index 0fb36cc..00dc506 100755
--- a/tools/marvin/marvin/integration/lib/base.py
+++ b/tools/marvin/marvin/integration/lib/base.py
@@ -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()])

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17af34fd/tools/marvin/marvin/integration/lib/utils.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/utils.py b/tools/marvin/marvin/integration/lib/utils.py
index 4eca8ba..f7f39c9 100644
--- a/tools/marvin/marvin/integration/lib/utils.py
+++ b/tools/marvin/marvin/integration/lib/utils.py
@@ -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):

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17af34fd/tools/marvin/marvin/marvinPlugin.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/marvinPlugin.py b/tools/marvin/marvin/marvinPlugin.py
index 5014a2c..a0ec3d5 100644
--- a/tools/marvin/marvin/marvinPlugin.py
+++ b/tools/marvin/marvin/marvinPlugin.py
@@ -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)