Merge "Remove openstack utils calls in rally and tempest"
[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 pkg_resources
13
14 import click
15
16 import functest.ci.tier_builder as tb
17 from functest.utils.constants import CONST
18 import functest.utils.functest_utils as ft_utils
19 import functest.utils.functest_vacation as vacation
20
21
22 class Testcase(object):
23
24     def __init__(self):
25         self.tiers = tb.TierBuilder(
26             CONST.__getattribute__('INSTALLER_TYPE'),
27             CONST.__getattribute__('DEPLOY_SCENARIO'),
28             pkg_resources.resource_filename('functest', 'ci/testcases.yaml'))
29
30     def list(self):
31         summary = ""
32         for tier in self.tiers.get_tiers():
33             for test in tier.get_tests():
34                 summary += (" %s\n" % test.get_name())
35         return summary
36
37     def show(self, testname):
38         description = self.tiers.get_test(testname)
39         return description
40
41     @staticmethod
42     def run(testname, noclean=False, report=False):
43
44         flags = ""
45         if noclean:
46             flags += "-n "
47         if report:
48             flags += "-r "
49
50         if testname == 'vacation':
51             vacation.main()
52         else:
53             tests = testname.split(",")
54             for test in tests:
55                 cmd = "run_tests {}-t {}".format(flags, test)
56                 ft_utils.execute_command(cmd)
57
58
59 class CliTestcase(Testcase):
60
61     def __init__(self):
62         super(CliTestcase, self).__init__()
63
64     def list(self):
65         click.echo(super(CliTestcase, self).list())
66
67     def show(self, testname):
68         testcase_show = super(CliTestcase, self).show(testname)
69         if testcase_show:
70             click.echo(testcase_show)
71         else:
72             click.echo("The test case '%s' does not exist or is not supported."
73                        % testname)