Simplify functest/cli/commands/cli_env.py
[functest.git] / functest / cli / commands / cli_env.py
index 0e0afe5..a5c0e39 100644 (file)
@@ -5,54 +5,47 @@
 # are made available under the terms of the Apache License, Version 2.0
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
-#
-
-import click
-import prettytable
 
-from functest.utils.constants import CONST
+# pylint: disable=missing-docstring
 
+import os
 
-class Env(object):
+import click
+import prettytable
+import six
 
-    def __init__(self):
-        pass
 
-    def show(self):
-        def _get_value(attr, default='Unknown'):
-            return attr if attr else default
+class Env(object):  # pylint: disable=too-few-public-methods
 
-        install_type = _get_value(CONST.__getattribute__('INSTALLER_TYPE'))
-        installer_ip = _get_value(CONST.__getattribute__('INSTALLER_IP'))
+    @staticmethod
+    def show():
+        install_type = os.environ.get('INSTALLER_TYPE', 'Unknown')
+        installer_ip = os.environ.get('INSTALLER_IP', 'Unknown')
         installer_info = ("%s, %s" % (install_type, installer_ip))
-        scenario = _get_value(CONST.__getattribute__('DEPLOY_SCENARIO'))
-        node = _get_value(CONST.__getattribute__('NODE_NAME'))
-        is_debug = _get_value(CONST.__getattribute__('CI_DEBUG'), 'false')
-        build_tag = CONST.__getattribute__('BUILD_TAG')
-        if build_tag is not None:
+        scenario = os.environ.get('DEPLOY_SCENARIO', 'Unknown')
+        node = os.environ.get('NODE_NAME', 'Unknown')
+        build_tag = os.environ.get('BUILD_TAG', None)
+        if build_tag:
             build_tag = build_tag.lstrip(
                 "jenkins-").lstrip("functest").lstrip("-")
 
         env_info = {'INSTALLER': installer_info,
                     'SCENARIO': scenario,
                     'POD': node,
-                    'DEBUG FLAG': is_debug,
                     'BUILD_TAG': build_tag}
 
         return env_info
 
 
-class CliEnv(Env):
-
-    def __init__(self):
-        super(CliEnv, self).__init__()
+class CliEnv(object):  # pylint: disable=too-few-public-methods
 
-    def show(self):
-        env_info = super(CliEnv, self).show()
+    @staticmethod
+    def show():
+        env_info = Env.show()
         msg = prettytable.PrettyTable(
             header_style='upper', padding_width=5,
             field_names=['Functest Environment', 'value'])
-        for key, value in env_info.iteritems():
+        for key, value in six.iteritems(env_info):
             if key is not None:
                 msg.add_row([key, value])
         click.echo(msg.get_string())