Extracted all global parameters into functest_constants.py
[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 import functest.utils.functest_utils as ft_utils
18 import functest.utils.functest_constants as ft_constants
19
20
21 class CliTier:
22
23     def __init__(self):
24         CI_INSTALLER_TYPE = ft_constants.CI_INSTALLER_TYPE
25         CI_SCENARIO = ft_constants.CI_SCENARIO
26         testcases = ft_constants.FUNCTEST_TESTCASES_YAML
27         self.tiers = tb.TierBuilder(CI_INSTALLER_TYPE, CI_SCENARIO, testcases)
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     def run(self, tiername, noclean=False):
58         if not os.path.isfile(ft_constants.ENV_FILE):
59             click.echo("Functest environment is not ready. "
60                        "Run first 'functest env prepare'")
61         else:
62             if noclean:
63                 cmd = ("python %s/functest/ci/run_tests.py "
64                        "-n -t %s" % (ft_constants.FUNCTEST_REPO_DIR, tiername))
65             else:
66                 cmd = ("python %s/functest/ci/run_tests.py "
67                        "-t %s" % (ft_constants.FUNCTEST_REPO_DIR, tiername))
68             ft_utils.execute_command(cmd)