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