Merge "Use new-style classes which inherit from object"
[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(CONST.INSTALLER_TYPE,
25                                     CONST.DEPLOY_SCENARIO,
26                                     CONST.functest_testcases_yaml)
27
28     def list(self):
29         summary = ""
30         for tier in self.tiers.get_tiers():
31             summary += ("    - %s. %s:\n\t   %s\n"
32                         % (tier.get_order(),
33                            tier.get_name(),
34                            tier.get_test_names()))
35         click.echo(summary)
36
37     def show(self, tiername):
38         tier = self.tiers.get_tier(tiername)
39         if tier is None:
40             tier_names = self.tiers.get_tier_names()
41             click.echo("The tier with name '%s' does not exist. "
42                        "Available tiers are:\n  %s\n" % (tiername, tier_names))
43         else:
44             click.echo(self.tiers.get_tier(tiername))
45
46     def gettests(self, tiername):
47         tier = self.tiers.get_tier(tiername)
48         if tier is None:
49             tier_names = self.tiers.get_tier_names()
50             click.echo("The tier with name '%s' does not exist. "
51                        "Available tiers are:\n  %s\n" % (tiername, tier_names))
52         else:
53             tests = tier.get_test_names()
54             click.echo("Test cases in tier '%s':\n %s\n" % (tiername, tests))
55
56     @staticmethod
57     def run(tiername, noclean=False, report=False):
58
59         flags = ""
60         if noclean:
61             flags += "-n "
62         if report:
63             flags += "-r "
64
65         if not os.path.isfile(CONST.env_active):
66             click.echo("Functest environment is not ready. "
67                        "Run first 'functest env prepare'")
68         else:
69             cmd = ("python %s/functest/ci/run_tests.py "
70                    "%s -t %s" % (CONST.dir_repo_functest, flags, tiername))
71             ft_utils.execute_command(cmd)