Updates for network checker
- New checks for uniform MTU and Duplicate IPs
- Updated mapping for K8s envs
- K8s envs can skip networks using IF name keywords. Defaults to "docker"
- Network listing now gives details on Names and used MTU
Related-PROD: PROD-35288
Change-Id: Ida345ce1762038f744c460805d607d1439e434b8
diff --git a/cfg_checker/modules/network/checker.py b/cfg_checker/modules/network/checker.py
index b5809f3..0b336f2 100644
--- a/cfg_checker/modules/network/checker.py
+++ b/cfg_checker/modules/network/checker.py
@@ -10,9 +10,78 @@
logger_cli.debug("... init error logs folder")
self.errors = NetworkErrors()
- def check_networks(self, map=True):
+ def _check_duplicate_ips(self):
+ # shortcuts
+ logger_cli.debug("... checking for duplicate ips")
+ _map = self.mapper.map
+ for _net in _map.keys():
+ _ips = set()
+ for _node_name, _interfaces in _map[_net].items():
+ for _if in _interfaces:
+ if _if["ip_address"] not in _ips:
+ # there was no such ip yet
+ _ips.add(_if["ip_address"])
+ else:
+ # this ip already used
+ logger_cli.warning(
+ "Warning: Duplicate ip address: "
+ "'{}: {}' at {} -> {}".format(
+ _if["interface"],
+ _if["ip_address"],
+ _net,
+ _node_name
+ )
+ )
+ self.errors.add_error(
+ self.errors.NET_DUPLICATE_IP,
+ network=_net,
+ node_name=_node_name,
+ if_name=_if["interface"],
+ ip_address=_if["ip_address"]
+ )
+ return
+
+ def _check_non_uniform_mtu(self):
+ # shortcuts
+ logger_cli.debug("... checking for duplicate ips")
+ _map = self.mapper.map
+ for _net in _map.keys():
+ _mtus = set()
+ for _node_name, _interfaces in _map[_net].items():
+ for _if in _interfaces:
+ if len(_mtus) < 1:
+ # this is the 1st iteration
+ _mtus.add(_if["rt_mtu"])
+ elif _if["rt_mtu"] not in _mtus:
+ # this ip already used
+ logger_cli.warning(
+ "Non-uniform MTU value of '{}' in '{}': "
+ "{}:{}:{}".format(
+ _net,
+ _node_name,
+ _if["interface"],
+ _if["ip_address"],
+ _if["rt_mtu"]
+ )
+ )
+ self.errors.add_error(
+ self.errors.NET_DUPLICATE_IP,
+ network=_net,
+ node_name=_node_name,
+ if_name=_if["interface"],
+ ip_address=_if["ip_address"],
+ mtu=_if["rt_mtu"]
+ )
+ return
+
+ def check_networks(self, map=True, skip_keywords=None):
+ # Load map
self.mapper.map_networks()
- self.mapper.create_map()
+ self.mapper.create_map(skip_keywords=skip_keywords)
+ # Check for errors that is not detectable during mapping
+ self._check_duplicate_ips()
+ self._check_non_uniform_mtu()
+ # print map if requested
if map:
self.mapper.print_map()