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