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

git commit: updated refs/heads/4.2 to c2a41b5

Updated Branches:
  refs/heads/4.2 3017b416f -> c2a41b565


CLOUDSTACK-5423: Fixed 5423

Conflicts:
	tools/marvin/marvin/deployAndRun.py


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

Branch: refs/heads/4.2
Commit: c2a41b565a781eca9a2dace1459925bd150b7b7b
Parents: 3017b41
Author: Santhosh Edukulla <Sa...@citrix.com>
Authored: Tue Dec 10 20:25:23 2013 +0530
Committer: Girish Shilamkar <gi...@clogeny.com>
Committed: Wed Dec 11 12:06:35 2013 +0530

----------------------------------------------------------------------
 tools/marvin/marvin/TestCaseExecuteEngine.py | 102 ------------
 tools/marvin/marvin/configGenerator.py       |   5 -
 tools/marvin/marvin/deployAndRun.py          | 187 +++++++++++++++-------
 tools/marvin/marvin/tcExecuteEngine.py       |  71 ++++++++
 4 files changed, 202 insertions(+), 163 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2a41b56/tools/marvin/marvin/TestCaseExecuteEngine.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/TestCaseExecuteEngine.py b/tools/marvin/marvin/TestCaseExecuteEngine.py
deleted file mode 100644
index f5af1fe..0000000
--- a/tools/marvin/marvin/TestCaseExecuteEngine.py
+++ /dev/null
@@ -1,102 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-import unittest
-import os
-import sys
-import logging
-from functools import partial
-
-
-def testCaseLogger(message, logger=None):
-    if logger is not None:
-        logger.debug(message)
-
-
-class TestCaseExecuteEngine(object):
-    def __init__(self, testclient, config, testcaseLogFile=None,
-                 testResultLogFile=None):
-        """
-        Initialize the testcase execution engine, just the basics here
-        @var testcaseLogFile: client log file
-        @var testResultLogFile: summary report file
-        """
-        self.testclient = testclient
-        self.config = config
-        self.logformat =\
-            logging.Formatter(
-                "%(asctime)s - %(levelname)s - %(name)s - %(message)s")
-        self.loader = unittest.loader.TestLoader()
-        self.suite = None
-
-        if testcaseLogFile is not None:
-            self.logfile = testcaseLogFile
-            self.logger = logging.getLogger("TestCaseExecuteEngine")
-            fh = logging.FileHandler(self.logfile)
-            fh.setFormatter(self.logformat)
-            self.logger.addHandler(fh)
-            self.logger.setLevel(logging.DEBUG)
-        if testResultLogFile is not None:
-            ch = logging.StreamHandler()
-            ch.setLevel(logging.ERROR)
-            ch.setFormatter(self.logformat)
-            self.logger.addHandler(ch)
-            fp = open(testResultLogFile, "w")
-            self.testResultLogFile = fp
-        else:
-            self.testResultLogFile = sys.stdout
-
-    def loadTestsFromDir(self, testDirectory):
-        """ Load the test suites from a package with multiple test files """
-        self.suite = self.loader.discover(testDirectory)
-        self.injectTestCase(self.suite)
-
-    def loadTestsFromFile(self, file_name):
-        """ Load the tests from a single script/module """
-        if os.path.isfile(file_name):
-            self.suite = self.loader.discover(os.path.dirname(file_name),
-                                              os.path.basename(file_name))
-            self.injectTestCase(self.suite)
-
-    def injectTestCase(self, testSuites):
-        for test in testSuites:
-            if isinstance(test, unittest.BaseTestSuite):
-                self.injectTestCase(test)
-            else:
-                #logger bears the name of the test class
-                testcaselogger = logging.getLogger("%s" % (test))
-                fh = logging.FileHandler(self.logfile)
-                fh.setFormatter(self.logformat)
-                testcaselogger.addHandler(fh)
-                testcaselogger.setLevel(logging.DEBUG)
-
-                #inject testclient and logger into each unittest
-                setattr(test, "testClient", self.testclient)
-                setattr(test, "config", self.config)
-                setattr(test, "debug", partial(testCaseLogger,
-                                               logger=testcaselogger))
-                setattr(test.__class__, "clstestclient", self.testclient)
-                if hasattr(test, "user"):
-                    # attribute when test is entirely executed as user
-                    self.testclient.createUserApiClient(test.UserName,
-                                                        test.DomainName,
-                                                        test.AcctType)
-
-    def run(self):
-        if self.suite:
-            unittest.TextTestRunner(stream=self.testResultLogFile,
-                                    verbosity=2).run(self.suite)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2a41b56/tools/marvin/marvin/configGenerator.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/configGenerator.py b/tools/marvin/marvin/configGenerator.py
index 3f98aca..6d5b70d 100644
--- a/tools/marvin/marvin/configGenerator.py
+++ b/tools/marvin/marvin/configGenerator.py
@@ -93,11 +93,6 @@ class trafficType(object):
                 if 'vmware' in labeldict.keys() else None
             self.simulator = labeldict['simulator']\
                 if 'simulator' in labeldict.keys() else None
-        #{
-        #    'xen' : 'cloud-xen',
-        #    'kvm' : 'cloud-kvm',
-        #    'vmware' : 'cloud-vmware'
-        #}
 
 
 class pod(object):

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2a41b56/tools/marvin/marvin/deployAndRun.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/deployAndRun.py b/tools/marvin/marvin/deployAndRun.py
index d162fb3..56747a7 100644
--- a/tools/marvin/marvin/deployAndRun.py
+++ b/tools/marvin/marvin/deployAndRun.py
@@ -15,78 +15,153 @@
 # specific language governing permissions and limitations
 # under the License.
 
-import deployDataCenter
-import TestCaseExecuteEngine
+from tcExecuteEngine import TestCaseExecuteEngine
 import sys
+import os
+import traceback
+import time
 from argparse import ArgumentParser
-if __name__ == "__main__":
+from marvinInit import MarvinInit
+from marvin.codes import (SUCCESS,
+                          FAILED,
+                          EXCEPTION,
+                          UNKNOWN_ERROR
+                          )
+
+
+parser = None
+
+
+def printAndExit():
+    '''
+    Prints pretty message for parser and exit
+    '''
+    global parser
+    if parser is not None:
+        parser.print_usage()
+        exit(1)
+
 
+def parseAndCheck():
+    '''
+    Parses,reads the options and verifies for the config file
+    '''
+    global parser
     parser = ArgumentParser()
 
-    parser.add_argument("-d", "--directory", dest="testCaseFolder",
-                        help="the test case directory")
-    parser.add_argument("-f", "--file", dest="module",
-                        help="run tests in the given file")
-    parser.add_argument("-r", "--result", dest="result",
-                        help="test result log file", default='/tmp/t.log')
-    parser.add_argument("-t", "--client", dest="testcaselog",
-                        help="test case log file", default='/tmp/r.log')
+    parser.add_argument("-d", "--tcpath", dest="tcpath",
+                        help="the test case directory or file path")
     parser.add_argument("-c", "--config", action="store",
                         default="./datacenterCfg", dest="config",
                         help="the path where the json config file generated,\
- by default is ./datacenterCfg")
+                        by default is ./datacenterCfg")
     parser.add_argument("-l", "--load", dest="load", action="store_true",
                         help="only load config, do not deploy,\
- it will only run testcase")
+                        it will only run testcase")
     parser.add_argument("-n", "--num", dest="number",
-                        help="how many times you want run the test case")
+                        help="how many times you want to run the tests")
 
     options = parser.parse_args()
+    cfg_file = options.config
+    tc_path = options.tcpath
+    load_flag = options.load
+    num_iter = 1 if options.number is None else int(options.number)
 
-    testResultLogFile = None
-    if options.result is not None:
-        testResultLogFile = options.result
+    '''
+    Check if the config file is None or not and exit accordingly
+    '''
+    if cfg_file is None:
+        printAndExit()
+    return {"cfg_file": cfg_file,
+            "load_flag": load_flag,
+            "tc_path": tc_path,
+            "num_iter": num_iter}
 
-    testCaseLogFile = None
-    if options.testcaselog is not None:
-        testCaseLogFile = options.testcaselog
-    deploy = deployDataCenter.deployDataCenters(options.config)
-    if options.load:
-        deploy.loadCfg()
-    else:
-        deploy.deploy()
-    iterates = 1
-    if options.number is not None:
-        if options.number == "loop":
-            iterates = sys.maxint
+
+def startMarvin(cfg_file, load_flag):
+    '''
+    Initialize the Marvin
+    '''
+    try:
+        obj_marvininit = MarvinInit(cfg_file, load_flag)
+        if obj_marvininit.init() == SUCCESS:
+            testClient = obj_marvininit.getTestClient()
+            tcRunLogger = obj_marvininit.getLogger()
+            parsedConfig = obj_marvininit.getParsedConfig()
+            debugStream = obj_marvininit.getDebugFile()
+            return {"tc_client": testClient,
+                    "tc_runlogger": tcRunLogger,
+                    "tc_parsedcfg": parsedConfig,
+                    "tc_debugstream": debugStream}
         else:
-            try:
-                iterates = int(options.number)
-            except:
-                iterates = 1
-
-    if options.testCaseFolder is None:
-        if options.module is None:
-            parser.print_usage()
+            print "\nMarvin Initialization Failed"
+            exit(1)
+    except Exception, e:
+            print "\n Exception occurred while starting Marvin %s" % str(e)
             exit(1)
+
+
+def runTCs(num_iter, inp1, inp2):
+    '''
+    Run Test Cases based upon number of iterations
+    '''
+    n = 0
+    while(n < num_iter):
+        engine = TestCaseExecuteEngine(inp2["tc_client"],
+                                       inp2["tc_parsedcfg"],
+                                       inp2["tc_runlogger"],
+                                       inp2["tc_debugstream"])
+        if inp1["tc_file"] is not None:
+            engine.loadTestsFromFile(inp1["tc_file"])
         else:
-            n = 0
-            while(n < iterates):
-                engine = \
-                    TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient,
-                                                            deploy.getCfg(),
-                                                            testCaseLogFile,
-                                                            testResultLogFile)
-                engine.loadTestsFromFile(options.module)
-                engine.run()
-                n = n + 1
+            engine.loadTestsFromDir(inp1["tc_dir"])
+        engine.run()
+        n = n + 1
+
+
+def checkTCPath(tc_path):
+    '''
+    Verifies if the tc_path is a folder or file and its existence
+    '''
+    ret = {"tc_file": None, "tc_dir": None}
+    check = True
+    if tc_path is None:
+        printAndExit()
     else:
-        n = 0
-        while(n<iterates):
-            engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient,
-                                                             deploy.getCfg(),
-                                                             testCaseLogFile,
-                                                             testResultLogFile)
-            engine.loadTestsFromDir(options.testCaseFolder)
-            engine.run()
-            n = n + 1
+        if os.path.isfile(tc_path):
+            ret["tc_file"] = tc_path
+        elif os.path.isdir(tc_path):
+            ret["tc_dir"] = tc_path
+        else:
+            check = False
+    if check is False:
+        print"\nTC Path is Invalid.So Exiting"
+        exit(1)
+
+    return ret
+
+if __name__ == "__main__":
+
+    '''
+    1. Parse and Check
+    '''
+    out1 = parseAndCheck()
+    print "\nStep1 :Parsing Options And Check Went Fine"
+
+    '''
+    2. Start Marvin
+    '''
+    out2 = startMarvin(out1["cfg_file"], out1["load_flag"])
+    print "\nStep2: Marvin Initialization Went Fine"
+
+    '''
+    3. Check TC folder or Module and Path existence
+    '''
+    out3 = checkTCPath(out1["tc_path"])
+    print "\nStep3: TC Path Check Went Fine"
+
+    '''
+    4. Run TCs
+    '''
+    runTCs(out1["num_iter"], out3, out2)
+    print "\nStep4: TC Running Finished"

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2a41b56/tools/marvin/marvin/tcExecuteEngine.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/tcExecuteEngine.py b/tools/marvin/marvin/tcExecuteEngine.py
new file mode 100644
index 0000000..f959e7e
--- /dev/null
+++ b/tools/marvin/marvin/tcExecuteEngine.py
@@ -0,0 +1,71 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+import os
+import sys
+import logging
+from functools import partial
+
+
+class TestCaseExecuteEngine(object):
+    def __init__(self, testclient, config, tc_logger=None, debug_stream=None):
+        """
+        Initialize the testcase execution engine, just the basics here
+        @var testcaseLogFile: client log file
+        @var testResultLogFile: summary report file
+        """
+        self.testclient = testclient
+        self.config = config
+        self.tcRunLogger = tc_logger
+        self.debugStream = debug_stream
+        self.loader = unittest.loader.TestLoader()
+        self.suite = None
+
+    def loadTestsFromDir(self, testDirectory):
+        """ Load the test suites from a package with multiple test files """
+        self.suite = self.loader.discover(testDirectory)
+        self.injectTestCase(self.suite)
+
+    def loadTestsFromFile(self, file_name):
+        """ Load the tests from a single script/module """
+        if os.path.isfile(file_name):
+            self.suite = self.loader.discover(os.path.dirname(file_name),
+                                              os.path.basename(file_name))
+            self.injectTestCase(self.suite)
+
+    def injectTestCase(self, testSuites):
+        for test in testSuites:
+            if isinstance(test, unittest.BaseTestSuite):
+                self.injectTestCase(test)
+            else:
+                #inject testclient and logger into each unittest
+                self.tcRunLogger.name = test.__str__()
+                setattr(test, "testClient", self.testclient)
+                setattr(test, "config", self.config)
+                setattr(test, "debug", self.tcRunLogger.debug)
+                setattr(test.__class__, "clstestclient", self.testclient)
+                if hasattr(test, "user"):
+                    # attribute when test is entirely executed as user
+                    self.testclient.createUserApiClient(test.UserName,
+                                                        test.DomainName,
+                                                        test.AcctType)
+
+    def run(self):
+        if self.suite:
+            unittest.TextTestRunner(stream=self.debugStream,
+                                    verbosity=2).run(self.suite)