aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Paraskevopoulos <geopar@intracom-telecom.com>2017-03-22 10:13:17 +0200
committerManuel Buil <mbuil@suse.com>2017-03-22 09:39:29 +0000
commitb15a8c8297b6667ca9d9f4cc8f946f895d7e99fa (patch)
treea171857789aa3d47e4d5916898f32ed6657398fe
parenta32584d817e775a58957773faee6f0037d12107d (diff)
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 <geopar@intracom-telecom.com> (cherry picked from commit 08aa86e1e7cb874aac72c831e239c003070e5ca3)
-rw-r--r--sfc/tests/functest/run_tests.py23
1 files 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)