Multiple K8s integration issues

   - Fixed config loading issue on remote env
   - Fixed kube.conf path passing
   - Fixed skip.list handling

  Related-PROD: PROD-35903

Change-Id: I4c22607dcbfab7dfe15d86b5a6ece77c32aaac2c
diff --git a/cfg_checker/common/const.py b/cfg_checker/common/const.py
index a16011f..b629eb6 100644
--- a/cfg_checker/common/const.py
+++ b/cfg_checker/common/const.py
@@ -54,8 +54,13 @@
 
 uknown_code = "unk"
 
-ENV_TYPE_KUBE = "salt"
-ENV_TYPE_KUBE = "kube"
+ENV_TYPE_GLOB = "MCP"
+ENV_TYPE_SALT = "SALT"
+ENV_TYPE_KUBE = "KUBE"
+ENV_TYPE_LINUX = "LINUX"
+ENV_LOCAL = "local"
+
+supported_envs = [ENV_TYPE_LINUX, ENV_TYPE_SALT, ENV_TYPE_KUBE]
 
 all_salt_roles_map = {
     "apt": "repository",
diff --git a/cfg_checker/common/kube_utils.py b/cfg_checker/common/kube_utils.py
index 5b791cd..f6f499d 100644
--- a/cfg_checker/common/kube_utils.py
+++ b/cfg_checker/common/kube_utils.py
@@ -14,12 +14,14 @@
 from cfg_checker.common.file_utils import create_temp_file_with_content
 from cfg_checker.common.other import utils, shell
 from cfg_checker.common.ssh_utils import ssh_shell_p
+from cfg_checker.common.const import ENV_LOCAL
 
 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
 
 
 def _init_kube_conf_local(config):
     # Init kube library locally
+    _path = "local:{}".format(config.kube_config_path)
     try:
         kconfig.load_kube_config()
         if config.insecure:
@@ -38,7 +40,7 @@
                 str(e)
             )
         )
-        return None, None
+        return None, None, _path
 
 
 def _init_kube_conf_remote(config):
@@ -60,7 +62,13 @@
         --header "Authorization: Bearer $TOKEN" --insecure
     """
     import yaml
-    if not config.kube_config_path:
+    _path = ''
+    if not config.env_name == ENV_LOCAL:
+        _path = "{}@{}:{}".format(
+            config.ssh_user,
+            config.ssh_host,
+            config.kube_config_path
+        )
         _c_data = ssh_shell_p(
             "sudo cat " + config.kube_config_path,
             config.ssh_host,
@@ -70,9 +78,13 @@
             use_sudo=config.ssh_uses_sudo,
         )
     else:
+        _path = "local:{}".format(config.kube_config_path)
         with open(config.kube_config_path, 'r') as ff:
             _c_data = ff.read()
 
+    if len(_c_data) < 1:
+        return None, None, _path
+
     _conf = yaml.load(_c_data, Loader=yaml.SafeLoader)
 
     _kube_conf = kclient.Configuration()
@@ -140,20 +152,22 @@
     # Create a ApiClient with our config
     _kube_api = kclient.ApiClient(_kube_conf)
 
-    return _kube_conf, _kube_api
+    return _kube_conf, _kube_api, _path
 
 
 class KubeApi(object):
     def __init__(self, config):
         self.config = config
-        self._init_kclient()
+        self.initialized = self._init_kclient()
         self.last_response = None
 
     def _init_kclient(self):
         # if there is no password - try to get local, if this available
-        logger_cli.debug("# Initializong Kube config...")
+        logger_cli.debug("... init kube config")
         if self.config.env_name == "local":
-            self.kConf, self.kApi = _init_kube_conf_local(self.config)
+            self.kConf, self.kApi, self.kConfigPath = _init_kube_conf_local(
+                self.config
+            )
             self.is_local = True
             # Load local config data
             if os.path.exists(self.config.kube_config_path):
@@ -166,9 +180,16 @@
                 )
                 self.yaml_conf = _c_data
         else:
-            self.kConf, self.kApi = _init_kube_conf_remote(self.config)
+            self.kConf, self.kApi, self.kConfigPath = _init_kube_conf_remote(
+                self.config
+            )
             self.is_local = False
 
+        if self.kConf is None or self.kApi is None:
+            return False
+        else:
+            return True
+
     def get_versions_api(self):
         # client.CoreApi().get_api_versions().versions
         return kclient.VersionApi(self.kApi)
diff --git a/cfg_checker/common/settings.py b/cfg_checker/common/settings.py
index c681114..c654970 100644
--- a/cfg_checker/common/settings.py
+++ b/cfg_checker/common/settings.py
@@ -3,6 +3,10 @@
 import pwd
 import sys
 
+from cfg_checker.common.const import ENV_TYPE_GLOB, ENV_TYPE_SALT
+from cfg_checker.common.const import ENV_TYPE_KUBE, ENV_TYPE_LINUX, ENV_LOCAL
+from cfg_checker.common.const import supported_envs
+
 from cfg_checker.common.exception import ConfigException
 from cfg_checker.common.log import logger_cli
 
@@ -18,15 +22,6 @@
 
 _default_work_folder = os.path.normpath(pkg_dir)
 
-ENV_TYPE_GLOB = "MCP"
-ENV_TYPE_SALT = "SALT"
-ENV_TYPE_KUBE = "KUBE"
-ENV_TYPE_LINUX = "LINUX"
-
-ENV_LOCAL = "local"
-
-supported_envs = [ENV_TYPE_LINUX, ENV_TYPE_SALT, ENV_TYPE_KUBE]
-
 
 def _extract_salt_return(_raw):
     if not isinstance(_raw, str):
@@ -93,6 +88,19 @@
                 return False
         elif _type == ENV_TYPE_KUBE:
             _kube = get_kube_remote(self)
+            if not _kube.initialized:
+                logger_cli.debug(
+                    "... failed to load config from '{}'".format(
+                        _kube.kConfigPath
+                    )
+                )
+                return False
+            else:
+                logger_cli.debug(
+                    "... config loaded from '{}'".format(
+                        _kube.kConfigPath
+                    )
+                )
             try:
                 _vApi = _kube.get_versions_api()
                 _v = _vApi.get_code()
@@ -111,8 +119,8 @@
                 else:
                     return False
             except Exception as e:
-                logger_cli.warn(
-                    "# Unexpected error finding Kube env: '{}' ".format(
+                logger_cli.debug(
+                    "... kube env error: '{}' ".format(
                         str(e)
                     )
                 )
@@ -178,7 +186,7 @@
 
         self.pkg_versions_map = 'versions_map.csv'
 
-        self.ssh_uses_sudo = False
+        # self.ssh_uses_sudo = False
         self.ssh_key = os.environ.get('MCP_SSH_KEY', None)
         self.ssh_user = os.environ.get('MCP_SSH_USER', None)
         self.ssh_host = os.environ.get('MCP_SSH_HOST', None)
@@ -347,11 +355,13 @@
         if args.env_name == ENV_LOCAL:
             _env = os.getenv('MCP_ENV', None)
             _env = _env if _env else args.env_name
+            _env_config_path = os.path.join(pkg_dir, 'etc', _env + '.env')
         else:
             _env = args.env_name
+            _env_config_path = args.env_config
 
         # Init environment variables from file, validate
-        self._init_env(args.env_config, env_name=_env)
+        self._init_env(_env_config_path, env_name=_env)
         # Load Common vars for any type of the env
         self._init_mcp_values()
         # Detect env types present
diff --git a/cfg_checker/modules/network/checker.py b/cfg_checker/modules/network/checker.py
index f7b55db..54dadb9 100644
--- a/cfg_checker/modules/network/checker.py
+++ b/cfg_checker/modules/network/checker.py
@@ -67,6 +67,7 @@
             skip_list_file=skip_list_file
         )
 
+
 class KubeNetworkChecker(NetworkChecker):
     def __init__(
         self,
diff --git a/cfg_checker/modules/packages/checker.py b/cfg_checker/modules/packages/checker.py
index 46e98be..174691f 100644
--- a/cfg_checker/modules/packages/checker.py
+++ b/cfg_checker/modules/packages/checker.py
@@ -455,8 +455,8 @@
             config,
             force_tag=force_tag,
             exclude_keywords=[],
-            skip_list=None,
-            skip_list_file=None
+            skip_list=skip_list,
+            skip_list_file=skip_list_file
         )
 
 
@@ -474,6 +474,6 @@
             config,
             force_tag=force_tag,
             exclude_keywords=[],
-            skip_list=None,
-            skip_list_file=None
+            skip_list=skip_list,
+            skip_list_file=skip_list_file
         )
diff --git a/cfg_checker/nodes.py b/cfg_checker/nodes.py
index 1780b60..eea6500 100644
--- a/cfg_checker/nodes.py
+++ b/cfg_checker/nodes.py
@@ -31,13 +31,15 @@
     # skip list file
     if skip_list_file:
         _valid, _invalid = utils.get_nodes_list(skip_list_file)
-        logger_cli.info(
-            "\n# WARNING: Detected invalid entries "
-            "in nodes skip list: {}\n".format(
-                "\n".join(_invalid)
-            )
-        )
         _skipped_minions.extend(_valid)
+        if len(_invalid) < 1:
+            logger_cli.info(
+                "\n# WARNING: Detected invalid entries "
+                "in nodes skip list:\n{}\n".format(
+                    "\n".join(_invalid)
+                )
+            )
+        
     # process wildcard, create node list out of mask
     if skip_list:
         _list = []
@@ -329,6 +331,14 @@
                 _data[_pillar_keys[-1]] = _result[node]
 
     def prepare_json_on_node(self, node, _dict, filename):
+        if node in self.skip_list:
+            logger_cli.debug(
+                "... '{}' skipped while preparing json file of '{}'".format(
+                    node,
+                    filename
+                )
+            )
+
         # this function assumes that all folders are created
         _dumps = json.dumps(_dict, indent=2).splitlines()
         _storage_path = os.path.join(
diff --git a/tests/res/_fake_skip_list b/tests/res/_fake_skip_list
new file mode 100644
index 0000000..1cb8758
--- /dev/null
+++ b/tests/res/_fake_skip_list
@@ -0,0 +1,4 @@
+cfg01.fakedomain.local
+ctl01.fakedomain.local
+prx01.fakedomain.local
+gbattnlon1-001cfg.attni.dom
\ No newline at end of file