Replace CONST.* by getattribute/setattr for cli
[functest.git] / functest / cli / commands / cli_tier.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 from functest.utils.constants import CONST
18 import functest.utils.functest_utils as ft_utils
19
20
21 class CliTier(object):
22
23     def __init__(self):
24         self.tiers = tb.TierBuilder(
25             CONST.__getattribute__('INSTALLER_TYPE'),
26             CONST.__getattribute__('DEPLOY_SCENARIO'),
27             CONST.__getattribute__('functest_testcases_yaml'))
28
29     def list(self):
30         summary = ""
31         for tier in self.tiers.get_tiers():
32             summary += ("    - %s. %s:\n\t   %s\n"
33                         % (tier.get_order(),
34                            tier.get_name(),
35                            tier.get_test_names()))
36         click.echo(summary)
37
38     def show(self, tiername):
39         tier = self.tiers.get_tier(tiername)
40         if tier is None:
41             tier_names = self.tiers.get_tier_names()
42             click.echo("The tier with name '%s' does not exist. "
43                        "Available tiers are:\n  %s\n" % (tiername, tier_names))
44         else:
45             click.echo(self.tiers.get_tier(tiername))
46
47     def gettests(self, tiername):
48         tier = self.tiers.get_tier(tiername)
49         if tier is None:
50             tier_names = self.tiers.get_tier_names()
51             click.echo("The tier with name '%s' does not exist. "
52                        "Available tiers are:\n  %s\n" % (tiername, tier_names))
53         else:
54             tests = tier.get_test_names()
55             click.echo("Test cases in tier '%s':\n %s\n" % (tiername, tests))
56
57     @staticmethod
58     def run(tiername, noclean=False, report=False):
59
60         flags = ""
61         if noclean:
62             flags += "-n "
63         if report:
64             flags += "-r "
65
66         if not os.path.isfile(CONST.__getattribute__('env_active')):
67             click.echo("Functest environment is not ready. "
68                        "Run first 'functest env prepare'")
69         else:
70             cmd = ("python %s/functest/ci/run_tests.py "
71                    "%s -t %s" %
72                    (CONST.__getattribute__('dir_repo_functest'),
73                     flags, tiername))
74             ft_utils.execute_command(cmd)