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