Network pinger module fix
Change-Id: I7fc47c4db8e995d40da104ffc0802cc67b39ec32
Related-PROD: PROD-35903
diff --git a/cfg_checker/modules/network/__init__.py b/cfg_checker/modules/network/__init__.py
index 0245e06..c4a74d7 100644
--- a/cfg_checker/modules/network/__init__.py
+++ b/cfg_checker/modules/network/__init__.py
@@ -1,5 +1,5 @@
from cfg_checker.common import logger_cli
-from cfg_checker.common.settings import ENV_TYPE_SALT
+from cfg_checker.common.settings import ENV_TYPE_SALT, ENV_TYPE_KUBE
from cfg_checker.common.exception import CheckerException
from cfg_checker.helpers import args_utils
from cfg_checker.modules.network import checker, mapper, pinger
@@ -31,23 +31,6 @@
return _class
-def _selectChecker(_env):
- pChecker = None
- if _env == ENV_TYPE_SALT:
- pChecker = checker.SaltNetworkChecker(
- config,
- skip_list=_skip,
- skip_list_file=_skip_file
- )
- elif _env == ENV_TYPE_KUBE:
- pChecker = checker.KubeNetworkChecker(
- config,
- skip_list=_skip,
- skip_list_file=_skip_file
- )
- return pChecker
-
-
def init_parser(_parser):
# network subparser
net_subparsers = _parser.add_subparsers(dest='type')
@@ -216,8 +199,17 @@
logger_cli.error("\n# Use mcp-check network list to get list of CIDRs")
_cidr = args_utils.get_arg(args, "cidr")
_skip, _skip_file = args_utils.get_skip_args(args)
- _pinger = pinger.NetworkPinger(
+ # init mapper
+ _skip, _skip_file = args_utils.get_skip_args(args)
+ _class = _selectClass(_env, strClassHint="mapper")
+ _mapper = _class(
config,
+ skip_list=_skip,
+ skip_list_file=_skip_file
+ )
+ # init pinger
+ _pinger = pinger.NetworkPinger(
+ _mapper,
mtu=args.mtu,
detailed=args.detailed,
skip_list=_skip,
diff --git a/cfg_checker/modules/network/pinger.py b/cfg_checker/modules/network/pinger.py
index 17f8597..075012c 100644
--- a/cfg_checker/modules/network/pinger.py
+++ b/cfg_checker/modules/network/pinger.py
@@ -3,16 +3,14 @@
from cfg_checker.common import logger_cli
from cfg_checker.helpers.console_utils import Progress
-from cfg_checker.modules.network.mapper import NetworkMapper
from cfg_checker.modules.network.network_errors import NetworkErrors
-from cfg_checker.nodes import SaltNodes
# This is independent class with a salt.nodes input
class NetworkPinger(object):
def __init__(
self,
- config,
+ mapper,
mtu=None,
detailed=False,
errors_class=None,
@@ -20,13 +18,7 @@
skip_list_file=None
):
logger_cli.info("# Initializing Pinger")
- self.salt_master = SaltNodes(config)
- # all active nodes in the cloud
- self.target_nodes = self.salt_master.get_nodes(
- skip_list=skip_list,
- skip_list_file=skip_list_file
- )
-
+ self.mapper = mapper
# default MTU value
self.target_mtu = mtu if mtu else 64
# only data
@@ -42,8 +34,7 @@
def _collect_node_addresses(self, target_net):
# use reclass model and standard methods
# to create list of nodes with target network
- _mapper = NetworkMapper(errors_class=self.errors)
- _reclass = _mapper.map_network(_mapper.RUNTIME)
+ _reclass = self.mapper.map_network(self.mapper.RUNTIME)
if target_net in _reclass:
return _reclass[target_net]
else:
@@ -119,7 +110,7 @@
# do ping of packets
logger_cli.info("# Pinging nodes: MTU={}".format(self.target_mtu))
- self.salt_master.prepare_script_on_active_nodes("ping.py")
+ self.mapper.master.prepare_script_on_active_nodes("ping.py")
_progress = Progress(_count)
_progress_index = 0
_node_index = 0
@@ -127,13 +118,13 @@
_targets = src_data["targets"]
_node_index += 1
# create 'targets.json' on source host
- _path = self.salt_master.prepare_json_on_node(
+ _path = self.mapper.master.prepare_json_on_node(
src,
_targets,
"targets.json"
)
# execute ping.py
- _results = self.salt_master.execute_script_on_node(
+ _results = self.mapper.master.execute_script_on_node(
src,
"ping.py",
args=[_path]