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