Replace CONST.* by getattribute/setattr for cli
[functest.git] / functest / cli / commands / cli_testcase.py
index da78ae9..3d3f1cb 100644 (file)
@@ -14,23 +14,18 @@ import os
 import click
 
 import functest.ci.tier_builder as tb
+from functest.utils.constants import CONST
 import functest.utils.functest_utils as ft_utils
 import functest.utils.functest_vacation as vacation
 
 
-FUNCTEST_CONF_DIR = \
-    ft_utils.get_functest_config('general.directories.dir_functest_conf')
-ENV_FILE = FUNCTEST_CONF_DIR + "/env_active"
-FUNCTEST_REPO = ft_utils.FUNCTEST_REPO
-
-
-class CliTestcase:
+class CliTestcase(object):
 
     def __init__(self):
-        CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE')
-        CI_SCENARIO = os.getenv('DEPLOY_SCENARIO')
-        testcases = ft_utils.get_testcases_file()
-        self.tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, testcases)
+        self.tiers = tb.TierBuilder(
+            CONST.__getattribute__('INSTALLER_TYPE'),
+            CONST.__getattribute__('DEPLOY_SCENARIO'),
+            CONST.__getattribute__('functest_testcases_yaml'))
 
     def list(self):
         summary = ""
@@ -47,17 +42,25 @@ class CliTestcase:
 
         click.echo(description)
 
-    def run(self, testname, noclean=False):
+    @staticmethod
+    def run(testname, noclean=False, report=False):
+
+        flags = ""
+        if noclean:
+            flags += "-n "
+        if report:
+            flags += "-r "
+
         if testname == 'vacation':
             vacation.main()
-        elif not os.path.isfile(ENV_FILE):
+        elif not os.path.isfile(CONST.__getattribute__('env_active')):
             click.echo("Functest environment is not ready. "
                        "Run first 'functest env prepare'")
         else:
-            if noclean:
-                cmd = ("python %s/functest/ci/run_tests.py "
-                       "-n -t %s" % (FUNCTEST_REPO, testname))
-            else:
+            tests = testname.split(",")
+            for test in tests:
                 cmd = ("python %s/functest/ci/run_tests.py "
-                       "-t %s" % (FUNCTEST_REPO, testname))
-            ft_utils.execute_command(cmd)
+                       "%s -t %s" %
+                       (CONST.__getattribute__('dir_repo_functest'),
+                        flags, test))
+                ft_utils.execute_command(cmd)