Fixes for routes detection and proper interface names extraction
- proper bond naming hierachy saving/mapping
- proper default gate match with current net
- MTU matching fix
Change-Id: I4494a6ef695248dc29dabc5f54678a5d6f578c81
Related-PROD: PROD-28199
diff --git a/cfg_checker/modules/network/mapper.py b/cfg_checker/modules/network/mapper.py
index 02c5fa6..03237a6 100644
--- a/cfg_checker/modules/network/mapper.py
+++ b/cfg_checker/modules/network/mapper.py
@@ -118,23 +118,26 @@
continue
# build map based on IPs and save info too
- for _if_name, _if_data in _pillar.iteritems():
+ for if_name, _dat in _pillar.iteritems():
+ # get proper IF name
+ _if_name = if_name if 'name' not in _dat else _dat['name']
+ # place it
if _if_name not in self.interfaces[node]:
self.interfaces[node][_if_name] = deepcopy(_network_item)
- self.interfaces[node][_if_name]['reclass'] = deepcopy(_if_data)
+ self.interfaces[node][_if_name]['reclass'] = deepcopy(_dat)
# map network if any
- if 'address' in _if_data:
+ if 'address' in _dat:
_if = ipaddress.IPv4Interface(
- _if_data['address'] + '/' + _if_data['netmask']
+ _dat['address'] + '/' + _dat['netmask']
)
- _if_data['name'] = _if_name
- _if_data['ifs'] = [_if]
+ _dat['name'] = _if_name
+ _dat['ifs'] = [_if]
_reclass = self._map_network_for_host(
node,
_if,
_reclass,
- _if_data
+ _dat
)
return _reclass
@@ -191,16 +194,19 @@
continue
for net_name, net_data in node_data['networks'].iteritems():
+ # cut net name
+ _i = net_name.find('@')
+ _name = net_name if _i < 0 else net_name[:_i]
# get ips and calculate subnets
- if net_name in ['lo']:
+ if _name in ['lo']:
# skip the localhost
continue
else:
# add collected data to interface storage
- if net_name not in self.interfaces[host]:
- self.interfaces[host][net_name] = \
+ if _name not in self.interfaces[host]:
+ self.interfaces[host][_name] = \
deepcopy(_network_item)
- self.interfaces[host][net_name]['runtime'] = \
+ self.interfaces[host][_name]['runtime'] = \
deepcopy(net_data)
# get data and make sure that wide mask goes first
@@ -217,7 +223,7 @@
if _if.network.prefixlen == 32:
net_data['vip'] = str(_if.exploded)
if 'name' not in net_data:
- net_data['name'] = net_name
+ net_data['name'] = _name
if 'ifs' not in net_data:
net_data['ifs'] = [_if]
# map it
@@ -295,7 +301,6 @@
host=hostname
)
continue
-
# lookup interface name on node using network CIDR
_if_name = _runtime[network][hostname][0]["name"]
# get proper reclass
@@ -329,11 +334,6 @@
# get the gateway for current net
_routes = salt_master.nodes[hostname]['routes']
_route = _routes[_net] if _net in _routes else None
- if not _route:
- _gate = "no route!"
- else:
- _gate = _route['gateway'] if _route['gateway'] else "-"
-
# get the default gateway
if 'default' in _routes:
_d_gate = ipaddress.IPv4Address(
@@ -341,7 +341,12 @@
)
else:
_d_gate = None
- _d_gate_str = _d_gate if _d_gate else "No default gateway!"
+ _d_gate_str = str(_d_gate) if _d_gate else "No default!"
+ # match route with default
+ if not _route:
+ _gate = "?"
+ else:
+ _gate = _route['gateway'] if _route['gateway'] else "-"
else:
# in case of manual and dhcp, no check possible
_gate = "-"
@@ -356,15 +361,16 @@
_up_error = ""
_mtu_error = ""
- # check if node is UP
- # get proper network from reclass
+ # Match gateway
if _proto == 'static':
- # Lookup match for the ip
+ # default reclass gate
_r_gate = "-"
if "gateway" in _r:
_r_gate = _r["gateway"]
+
# if values not match, put *
- if _gate != _r_gate:
+ if _gate != _r_gate and _d_gate_str != _r_gate:
+ # if values not match, check if default match
_gate_error = "*"
# IF status in reclass
@@ -376,8 +382,8 @@
_rc_mtu_s = ""
if _rc_mtu:
# there is a reclass MTU, save it
- _rc_mtu_s = "/" + str(_rc_mtu)
- elif _host['mtu'] == 1500 \
+ _rc_mtu_s = str(_rc_mtu)
+ elif _host['mtu'] == "1500" \
or _proto == "-" \
or _proto == "dhcp":
# 1500 is a default value => reclass not have it
@@ -401,6 +407,7 @@
reclass_mtu=_rc_mtu,
runtime_mtu=_host['mtu']
)
+ _rc_mtu_s = "/" + _rc_mtu_s
_mtu_error = "*"
else:
# empty the matched value
@@ -423,7 +430,7 @@
_ip_str += " VIP"
# Host IF IP Proto MTU State Gate Def.Gate
_text = "{:7} {:17} {:25} {:6} {:10} " \
- "{:10} {}/{}".format(
+ "{:10} {} / {}".format(
_if_name + _if_rc,
_if_name_suffix,
_ip_str,
diff --git a/cfg_checker/modules/network/network_errors.py b/cfg_checker/modules/network/network_errors.py
index 80f1199..276c4ab 100644
--- a/cfg_checker/modules/network/network_errors.py
+++ b/cfg_checker/modules/network/network_errors.py
@@ -42,7 +42,7 @@
)
self.add_error_type(
self.NET_MASK_MISMATCH,
- "IFs mask settings for the same subnet is not the same"
+ "IFs mask settings for subnet is not the same"
)
self.add_error_type(
self.NET_NODE_NON_RESPONSIVE,