Updated Branches: refs/heads/bvt f3167e683 -> 6104d1230
argparse TODO implemented 1. deployAndRun will use the more modern argparse module 2. improving logging within the remoteSSHClient, moving to debug and default logging to INFO 3. removing dependance on the xmlrunner. use nose --with-xunit instead Signed-off-by: Prasanna Santhanam <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/6104d123 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/6104d123 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/6104d123 Branch: refs/heads/bvt Commit: 6104d12306c795b24f437fc2da0ebef9d20bf3cd Parents: f3167e6 Author: Prasanna Santhanam <[email protected]> Authored: Wed Mar 13 11:49:08 2013 +0530 Committer: Prasanna Santhanam <[email protected]> Committed: Wed Mar 13 11:49:08 2013 +0530 ---------------------------------------------------------------------- tools/marvin/marvin/TestCaseExecuteEngine.py | 9 +---- tools/marvin/marvin/deployAndRun.py | 38 ++++++++------------ tools/marvin/marvin/remoteSSHClient.py | 9 ++--- tools/marvin/setup.py | 5 +-- 4 files changed, 23 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6104d123/tools/marvin/marvin/TestCaseExecuteEngine.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/TestCaseExecuteEngine.py b/tools/marvin/marvin/TestCaseExecuteEngine.py index 3c34c7e..144c5db 100644 --- a/tools/marvin/marvin/TestCaseExecuteEngine.py +++ b/tools/marvin/marvin/TestCaseExecuteEngine.py @@ -16,7 +16,6 @@ # under the License. import unittest -import xmlrunner import os import sys import logging @@ -27,7 +26,7 @@ def testCaseLogger(message, logger=None): logger.debug(message) class TestCaseExecuteEngine(object): - def __init__(self, testclient, config, testcaseLogFile=None, testResultLogFile=None, format="text", xmlDir="xml-reports"): + def __init__(self, testclient, config, testcaseLogFile=None, testResultLogFile=None): """ Initialize the testcase execution engine, just the basics here @var testcaseLogFile: client log file @@ -56,9 +55,7 @@ class TestCaseExecuteEngine(object): self.testResultLogFile = fp else: self.testResultLogFile = sys.stdout - if self.format == "xml" and (xmlDir is not None): - self.xmlDir = xmlDir - + def loadTestsFromDir(self, testDirectory): """ Load the test suites from a package with multiple test files """ self.suite = self.loader.discover(testDirectory) @@ -94,5 +91,3 @@ class TestCaseExecuteEngine(object): if self.suite: if self.format == "text": unittest.TextTestRunner(stream=self.testResultLogFile, verbosity=2).run(self.suite) - elif self.format == "xml": - xmlrunner.XMLTestRunner(output=self.xmlDir).run(self.suite) http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6104d123/tools/marvin/marvin/deployAndRun.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/deployAndRun.py b/tools/marvin/marvin/deployAndRun.py index e7b005c..54161eb 100644 --- a/tools/marvin/marvin/deployAndRun.py +++ b/tools/marvin/marvin/deployAndRun.py @@ -17,22 +17,22 @@ import deployDataCenter import TestCaseExecuteEngine -from optparse import OptionParser -import os - +from argparse import ArgumentParser if __name__ == "__main__": - parser = OptionParser() #TODO: deprecate and use the argparse module - - parser.add_option("-c", "--config", action="store", default="./datacenterCfg", dest="config", help="the path where the json config file generated, by default is ./datacenterCfg") - parser.add_option("-d", "--directory", dest="testCaseFolder", help="the test case directory") - parser.add_option("-r", "--result", dest="result", help="test result log file") - parser.add_option("-t", "--client", dest="testcaselog", help="test case log file") - parser.add_option("-l", "--load", dest="load", action="store_true", help="only load config, do not deploy, it will only run testcase") - parser.add_option("-f", "--file", dest="module", help="run tests in the given file") - parser.add_option("-x", "--xml", dest="xmlrunner", help="use the xml runner to generate xml reports and path to store xml files") + 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("-c", "--config", action="store", default="./datacenterCfg", dest="config", + help="the path where the json config file generated, 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") + (options, args) = parser.parse_args() - + testResultLogFile = None if options.result is not None: testResultLogFile = options.result @@ -46,12 +46,6 @@ if __name__ == "__main__": else: deploy.deploy() - fmt = "text" - xmlDir = None - if options.xmlrunner is not None: - xmlDir = options.xmlrunner - fmt = "xml" - if options.testCaseFolder is None: if options.module is None: parser.print_usage() @@ -61,15 +55,13 @@ if __name__ == "__main__": TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, deploy.getCfg(), testCaseLogFile, - testResultLogFile, fmt, - xmlDir) + testResultLogFile) engine.loadTestsFromFile(options.module) engine.run() else: engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, deploy.getCfg(), testCaseLogFile, - testResultLogFile, - fmt, xmlDir) + testResultLogFile) engine.loadTestsFromDir(options.testCaseFolder) engine.run() http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6104d123/tools/marvin/marvin/remoteSSHClient.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/remoteSSHClient.py b/tools/marvin/marvin/remoteSSHClient.py index 95a9ada..4fb2f0d 100644 --- a/tools/marvin/marvin/remoteSSHClient.py +++ b/tools/marvin/marvin/remoteSSHClient.py @@ -23,7 +23,7 @@ import logging from contextlib import closing class remoteSSHClient(object): - def __init__(self, host, port, user, passwd, retries = 10): + def __init__(self, host, port, user, passwd, retries = 10, log_lvl=logging.INFO): self.host = host self.port = port self.user = user @@ -32,14 +32,14 @@ class remoteSSHClient(object): self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self.logger = logging.getLogger('sshClient') ch = logging.StreamHandler() - ch.setLevel(logging.DEBUG) + ch.setLevel(log_lvl) self.logger.addHandler(ch) retry_count = retries while True: try: self.ssh.connect(str(host),int(port), user, passwd) - self.logger.debug("connecting to server %s with user %s passwd %s"%(str(host), user, passwd)) + self.logger.debug("SSH connect: %s@%s with passwd %s"%(user, str(host), passwd)) except paramiko.SSHException, sshex: if retry_count == 0: raise cloudstackException.InvalidParameterException(repr(sshex)) @@ -52,7 +52,6 @@ class remoteSSHClient(object): def execute(self, command): stdin, stdout, stderr = self.ssh.exec_command(command) - self.logger.debug("sending command %s to host %s"%(command, str(self.host))) output = stdout.readlines() errors = stderr.readlines() results = [] @@ -64,7 +63,7 @@ class remoteSSHClient(object): else: for strOut in output: results.append(strOut.rstrip()) - self.logger.debug("command %s returned %s"%(command, results)) + self.logger.debug("{Cmd: %s via Host: %s} {returns: %s}"%(command, str(self.host), results)) return results def scp(self, srcFile, destPath): http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6104d123/tools/marvin/setup.py ---------------------------------------------------------------------- diff --git a/tools/marvin/setup.py b/tools/marvin/setup.py index fea53d0..f8198d7 100644 --- a/tools/marvin/setup.py +++ b/tools/marvin/setup.py @@ -37,7 +37,6 @@ setup(name="Marvin", install_requires=[ "mysql-connector-python", "paramiko", - "nose", - "unittest-xml-reporting>1.2" - ], + "nose" + ], )
