Merge "Refactor rally report generation"
[functest.git] / functest / cli / commands / cli_env.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 # pylint: disable=missing-docstring
10
11 import click
12 import prettytable
13
14 from functest.utils.constants import CONST
15
16 import six
17
18
19 class Env(object):  # pylint: disable=too-few-public-methods
20
21     @staticmethod
22     def show():
23         def _get_value(attr, default='Unknown'):
24             return attr if attr else default
25
26         install_type = _get_value(CONST.__getattribute__('INSTALLER_TYPE'))
27         installer_ip = _get_value(CONST.__getattribute__('INSTALLER_IP'))
28         installer_info = ("%s, %s" % (install_type, installer_ip))
29         scenario = _get_value(CONST.__getattribute__('DEPLOY_SCENARIO'))
30         node = _get_value(CONST.__getattribute__('NODE_NAME'))
31         is_debug = _get_value(CONST.__getattribute__('CI_DEBUG'), 'false')
32         build_tag = CONST.__getattribute__('BUILD_TAG')
33         if build_tag is not None:
34             build_tag = build_tag.lstrip(
35                 "jenkins-").lstrip("functest").lstrip("-")
36
37         env_info = {'INSTALLER': installer_info,
38                     'SCENARIO': scenario,
39                     'POD': node,
40                     'DEBUG FLAG': is_debug,
41                     'BUILD_TAG': build_tag}
42
43         return env_info
44
45
46 class CliEnv(object):  # pylint: disable=too-few-public-methods
47
48     @staticmethod
49     def show():
50         env_info = Env.show()
51         msg = prettytable.PrettyTable(
52             header_style='upper', padding_width=5,
53             field_names=['Functest Environment', 'value'])
54         for key, value in six.iteritems(env_info):
55             if key is not None:
56                 msg.add_row([key, value])
57         click.echo(msg.get_string())