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