Fixes for Network check report
- default values if nodee check failed
- net interface mapping fix
- net tree creation fix for multi-branched bonds
Change-Id: Ic1a4709d258201c7ed4a7a70aaef98bb9aa53f7b
Related-PROD: PROD-32792
diff --git a/cfg_checker/modules/network/mapper.py b/cfg_checker/modules/network/mapper.py
index cea81bf..482bdfa 100644
--- a/cfg_checker/modules/network/mapper.py
+++ b/cfg_checker/modules/network/mapper.py
@@ -252,16 +252,24 @@
# there is such interface in this level?
if interface not in tree[lvl]:
# - IF not present
- # -- get parents, add
- _p = res[interface]['lower']
+ _n = ''
+ if interface not in res:
+ _n = 'unknown IF'
+ _p = None
+ _c = None
+ else:
+ # -- get parents, add
+ _p = res[interface]['lower']
+ # -- get childs, add
+ _c = res[interface]['upper']
+
# if None, put empty list
_p = _p if _p else []
- # -- get childs, add
- _c = res[interface]['upper']
# if None, put empty list
_c = _c if _c else []
tree[lvl].update({
interface: {
+ "note": _n,
"parents": _p,
"children": _c,
"size": len(_p) if len(_p) > len(_c) else len(_c)
@@ -278,12 +286,28 @@
return
def _put(cNet, cIndex, _list):
- for _cI in range(cIndex, len(_list)):
+ _added = False
+ _actual_index = -1
+ # Check list len
+ _len = len(_list)
+ if cIndex >= _len:
+ # grow list to meet index
+ _list = _list + [''] * (cIndex - _len + 1)
+ _len = len(_list)
+
+ for _cI in range(cIndex, _len):
# add child per index
# if space is free
if not _list[_cI]:
_list[_cI] = cNet
+ _added = True
+ _actual_index = _cI
break
+ if not _added:
+ # grow list by one entry
+ _list = _list + [cNet]
+ _actual_index = len(_list) - 1
+ return _actual_index, _list
# build network hierachy
nr = node_data['networks']
@@ -316,7 +340,11 @@
# put current interface if this is only one left
if not _tree[_lv][_net]['children']:
if _net not in matrix[x]:
- _put(_net, y, matrix[x])
+ _, matrix[x] = _put(
+ _net,
+ y,
+ matrix[x]
+ )
y += 1
else:
# get all nets with same child
@@ -330,16 +358,25 @@
# there is such interface on this level
# get index
_nI = matrix[x].index(_a[idx])
- _put(_c, _nI, matrix[x+1])
+ _, matrix[x+1] = _put(
+ _c,
+ _nI,
+ matrix[x+1]
+ )
else:
# there is no such interface
# add it
- for _nI in range(len(matrix[x])):
- if not matrix[x][_nI]:
- matrix[x][_nI] = _a[idx]
- # also, put child
- _put(_c, _nI, matrix[x+1])
- break
+ _t, matrix[x] = _put(
+ _a[idx],
+ 0,
+ matrix[x]
+ )
+ # also, put child
+ _, matrix[x+1] = _put(
+ _c,
+ _t,
+ matrix[x+1]
+ )
# remove collected nets from processing
if _a[idx] in nets:
nets.remove(_a[idx])
diff --git a/cfg_checker/nodes.py b/cfg_checker/nodes.py
index 0ca1e85..ec20f6a 100644
--- a/cfg_checker/nodes.py
+++ b/cfg_checker/nodes.py
@@ -162,7 +162,7 @@
_nodes = self.nodes
_result = self.execute_cmd_on_active_nodes(cmd, nodes=nodes)
for node, data in _nodes.iteritems():
-
+
if node in self.skip_list:
logger_cli.debug(
"... '{}' skipped while collecting '{}'".format(
diff --git a/cfg_checker/reports/reporter.py b/cfg_checker/reports/reporter.py
index aa399df..40f2c59 100644
--- a/cfg_checker/reports/reporter.py
+++ b/cfg_checker/reports/reporter.py
@@ -343,15 +343,23 @@
for node, dt in _dict.iteritems():
_cpuindex = 1
_add_mode = True
- # final totals
- dt[_key] = {
- "total": [0, 0, 0, 0]
- }
# totals for start mark
_ts = [0, 0, 0, 0]
# skip if node is down
if dt['status'] == DOWN:
+ dt.pop(_key_r)
continue
+ if not dt[_key_r]:
+ # no stats collected, put negatives
+ dt.pop(_key_r)
+ dt[_key] = {
+ "total": [-1, -1, -1, -1]
+ }
+ continue
+ # final totals
+ dt[_key] = {
+ "total": [0, 0, 0, 0]
+ }
lines = dt[_key_r].splitlines()
for line in lines:
if line.startswith("#"):