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