Simplify functest/cli/commands/cli_env.py
[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 os
12
13 import click
14 import prettytable
15 import six
16
17
18 class Env(object):  # pylint: disable=too-few-public-methods
19
20     @staticmethod
21     def show():
22         install_type = os.environ.get('INSTALLER_TYPE', 'Unknown')
23         installer_ip = os.environ.get('INSTALLER_IP', 'Unknown')
24         installer_info = ("%s, %s" % (install_type, installer_ip))
25         scenario = os.environ.get('DEPLOY_SCENARIO', 'Unknown')
26         node = os.environ.get('NODE_NAME', 'Unknown')
27         build_tag = os.environ.get('BUILD_TAG', None)
28         if build_tag:
29             build_tag = build_tag.lstrip(
30                 "jenkins-").lstrip("functest").lstrip("-")
31
32         env_info = {'INSTALLER': installer_info,
33                     'SCENARIO': scenario,
34                     'POD': node,
35                     'BUILD_TAG': build_tag}
36
37         return env_info
38
39
40 class CliEnv(object):  # pylint: disable=too-few-public-methods
41
42     @staticmethod
43     def show():
44         env_info = Env.show()
45         msg = prettytable.PrettyTable(
46             header_style='upper', padding_width=5,
47             field_names=['Functest Environment', 'value'])
48         for key, value in six.iteritems(env_info):
49             if key is not None:
50                 msg.add_row([key, value])
51         click.echo(msg.get_string())