Merge "Added unit tests for api_check, health_check, and smoke tests."
[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 import pkg_resources
14
15 import click
16
17 import functest.ci.tier_builder as tb
18 from functest.utils.constants import CONST
19 import functest.utils.functest_utils as ft_utils
20 import functest.utils.functest_vacation as vacation
21
22
23 class CliTestcase(object):
24
25     def __init__(self):
26         self.tiers = tb.TierBuilder(
27             CONST.__getattribute__('INSTALLER_TYPE'),
28             CONST.__getattribute__('DEPLOY_SCENARIO'),
29             pkg_resources.resource_filename('functest', 'ci/testcases.yaml'))
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     @staticmethod
47     def run(testname, noclean=False, report=False):
48
49         flags = ""
50         if noclean:
51             flags += "-n "
52         if report:
53             flags += "-r "
54
55         if testname == 'vacation':
56             vacation.main()
57         elif not os.path.isfile(CONST.__getattribute__('env_active')):
58             click.echo("Functest environment is not ready. "
59                        "Run first 'functest env prepare'")
60         else:
61             tests = testname.split(",")
62             for test in tests:
63                 cmd = ("python %s %s -t %s" %
64                        (pkg_resources.resource_filename(
65                            'functest', 'ci/run_tests.py'),
66                         flags, test))
67                 ft_utils.execute_command(cmd)