Merge "Update rally version"
[functest.git] / functest / cli / commands / cli_testcase.py
1 #!/usr/bin/env python
2 #
3 # jose.lausuch@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9
10 """ global variables """
11
12 import os
13
14 import click
15
16 import functest.ci.tier_builder as tb
17 import functest.utils.functest_utils as ft_utils
18 import functest.utils.functest_vacation as vacation
19
20
21 FUNCTEST_CONF_DIR = \
22     ft_utils.get_functest_config('general.directories.dir_functest_conf')
23 ENV_FILE = FUNCTEST_CONF_DIR + "/env_active"
24 FUNCTEST_REPO = ft_utils.FUNCTEST_REPO
25
26
27 class CliTestcase:
28
29     def __init__(self):
30         CI_INSTALLER_TYPE = os.getenv('INSTALLER_TYPE')
31         CI_SCENARIO = os.getenv('DEPLOY_SCENARIO')
32         testcases = ft_utils.get_testcases_file()
33         self.tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, testcases)
34
35     def list(self):
36         summary = ""
37         for tier in self.tiers.get_tiers():
38             for test in tier.get_tests():
39                 summary += (" %s\n" % test.get_name())
40         click.echo(summary)
41
42     def show(self, testname):
43         description = self.tiers.get_test(testname)
44         if description is None:
45             click.echo("The test case '%s' does not exist or is not supported."
46                        % testname)
47
48         click.echo(description)
49
50     def run(self, testname, noclean=False):
51         if testname == 'vacation':
52             vacation.main()
53         elif not os.path.isfile(ENV_FILE):
54             click.echo("Functest environment is not ready. "
55                        "Run first 'functest env prepare'")
56         else:
57             if noclean:
58                 cmd = ("python %s/ci/run_tests.py "
59                        "-n -t %s" % (FUNCTEST_REPO, testname))
60             else:
61                 cmd = ("python %s/ci/run_tests.py "
62                        "-t %s" % (FUNCTEST_REPO, testname))
63             ft_utils.execute_command(cmd)