Merge "Cover ODLResultVisitor"
[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 import functest.utils.functest_constants as ft_constants
20
21
22 class CliTestcase:
23
24     def __init__(self):
25         CI_INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE
26         CI_SCENARIO = ft_constants.CI_SCENARIO
27         testcases = ft_constants.FUNCTEST_TESTCASES_YAML
28
29         self.tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, testcases)
30
31     def list(self):
32         summary = ""
33         for tier in self.tiers.get_tiers():
34             for test in tier.get_tests():
35                 summary += (" %s\n" % test.get_name())
36         click.echo(summary)
37
38     def show(self, testname):
39         description = self.tiers.get_test(testname)
40         if description is None:
41             click.echo("The test case '%s' does not exist or is not supported."
42                        % testname)
43
44         click.echo(description)
45
46     def run(self, testname, noclean=False):
47         if testname == 'vacation':
48             vacation.main()
49         elif not os.path.isfile(ft_constants.ENV_FILE):
50             click.echo("Functest environment is not ready. "
51                        "Run first 'functest env prepare'")
52         else:
53             tests = testname.split(",")
54             for test in tests:
55                 if noclean:
56                     cmd = ("python %s/functest/ci/run_tests.py "
57                            "-n -t %s" % (ft_constants.FUNCTEST_REPO_DIR, test))
58                 else:
59                     cmd = ("python %s/functest/ci/run_tests.py "
60                            "-t %s" % (ft_constants.FUNCTEST_REPO_DIR, test))
61                 ft_utils.execute_command(cmd)