From b15a8c8297b6667ca9d9f4cc8f946f895d7e99fa Mon Sep 17 00:00:00 2001 From: George Paraskevopoulos Date: Wed, 22 Mar 2017 10:13:17 +0200 Subject: Perform cmd argument parsing when called from cli To be able to import run_tests as a module we must not try to parse command line arguments in global scope Also import the testcase using the full module path Change-Id: I1696800a16301d446bf9c926bdaf2b545435a2e7 Signed-off-by: George Paraskevopoulos (cherry picked from commit 08aa86e1e7cb874aac72c831e239c003070e5ca3) --- sfc/tests/functest/run_tests.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/sfc/tests/functest/run_tests.py b/sfc/tests/functest/run_tests.py index a043d191..ab77de74 100644 --- a/sfc/tests/functest/run_tests.py +++ b/sfc/tests/functest/run_tests.py @@ -28,12 +28,6 @@ from collections import OrderedDict from opnfv.deployment.factory import Factory as DeploymentFactory -parser = argparse.ArgumentParser() -parser.add_argument("-r", "--report", - help="Create json result file", - action="store_true") -args = parser.parse_args() - logger = ft_logger.getLogger('SFC_run_tests') COMMON_CONFIG = sfc_config.CommonConfig() @@ -80,7 +74,7 @@ def disable_heat_resource_finder_cache(nodes): time.sleep(10) -def main(): +def main(report=False): deploymentHandler = DeploymentFactory.get_handler( COMMON_CONFIG.installer_type, COMMON_CONFIG.installer_ip, @@ -131,7 +125,9 @@ def main(): (test_name, test_descr)) logger.info(title) logger.info("%s\n" % ("=" * len(title))) - t = importlib.import_module(testcase, package=None) + t = importlib.import_module( + "sfc.tests.functest.{0}".format(testcase), + package=None) start_time = time.time() try: result = t.main() @@ -164,7 +160,7 @@ def main(): overall_details.update({test_name_db: "execution error."}) ovs_logger.create_artifact_archive() - if args.report: + if report: details = result.get("details") push_results( test_name_db, start_time, end_time, status, details) @@ -174,7 +170,7 @@ def main(): sfc_cleanup.cleanup(odl_ip=odl_ip, odl_port=odl_port) overall_end_time = time.time() - if args.report: + if report: push_results( "odl-sfc", overall_start_time, overall_end_time, overall_status, overall_details) @@ -186,4 +182,9 @@ def main(): if __name__ == '__main__': - main() + parser = argparse.ArgumentParser() + parser.add_argument("-r", "--report", + help="Create json result file", + action="store_true") + args = parser.parse_args() + main(report=args.report) -- cgit 1.2.3-korg