Package versions report updates
diff --git a/cfg_checker/modules/packages/__init__.py b/cfg_checker/modules/packages/__init__.py
index 4f1a809..0e2d956 100644
--- a/cfg_checker/modules/packages/__init__.py
+++ b/cfg_checker/modules/packages/__init__.py
@@ -16,6 +16,6 @@
# collect data on installed packages
pChecker.collect_installed_packages()
# diff installed and candidates
- # pChecker.collect_packages()
+ pChecker.collect_packages()
# report it
pChecker.create_html_report(_filename)
diff --git a/cfg_checker/modules/packages/checker.py b/cfg_checker/modules/packages/checker.py
index 100b329..4956a52 100644
--- a/cfg_checker/modules/packages/checker.py
+++ b/cfg_checker/modules/packages/checker.py
@@ -32,7 +32,7 @@
logger_cli.info("... no JSON for '{}'".format(
key
))
- logger_cli.debug("... {}".format(_text[:_text.find('{')]))
+ logger_cli.debug("ERROR:\n{}\n".format(_text[:_text.find('{')]))
_dict = {}
self.nodes[key]['packages'] = _dict
@@ -50,16 +50,31 @@
:return: no return values, all date put to dict in place
"""
- _all_packages = {}
+ # Collect packages from all of the nodes in flat dict
+ _diff_packages = {}
for node_name, node_value in self.nodes.iteritems():
- for package_name in node_value['packages']:
- if package_name not in _all_packages:
- _all_packages[package_name] = {}
- _all_packages[package_name][node_name] = node_value
+ for _name, _value in node_value['packages'].iteritems():
+ if _name not in _diff_packages:
+ _diff_packages[_name] = {}
+ _diff_packages[_name]['df_nodes'] = {}
+ _diff_packages[_name]['eq_nodes'] = []
+
+ # compare packages, mark if equal
+ if _value['installed'] != _value['candidate']:
+ # Saving compare value so we not do str compare again
+ _value['is_equal'] = False
+ # add node name to list
+ _diff_packages[_name]['df_nodes'][node_name] = {
+ 'i': _value['installed'],
+ 'c': _value['candidate'],
+ 'raw': _value['raw']
+ }
+ else:
+ # Saving compare value so we not do str compare again
+ _value['is_equal'] = True
+ _diff_packages[_name]['eq_nodes'].append(node_name)
- # TODO: process data for per-package basis
-
- self.all_packages = _all_packages
+ self.diff_packages = _diff_packages
def create_html_report(self, filename):
"""
@@ -74,6 +89,7 @@
)
_report({
"nodes": self.nodes,
- "diffs": {}
+ "rc_diffs": {},
+ "pkg_diffs": self.diff_packages
})
logger_cli.info("-> Done")
diff --git a/cfg_checker/modules/reclass/comparer.py b/cfg_checker/modules/reclass/comparer.py
index eaf1ce8..5ef2ca5 100644
--- a/cfg_checker/modules/reclass/comparer.py
+++ b/cfg_checker/modules/reclass/comparer.py
@@ -135,7 +135,7 @@
)
# save it as a single data object
- self.models[name]["all_diffs"] = raw_tree[root_key]
+ self.models[name]["rc_diffs"] = raw_tree[root_key]
return True
def find_changes(self, dict1, dict2, path=""):
@@ -356,7 +356,7 @@
# report will have tabs for each of the comparable entities in diffs
report({
"nodes": {},
- "all_diffs": diffs,
+ "rc_diffs": diffs,
})
# with open("./gen_tree.json", "w+") as _out:
# _out.write(json.dumps(mComparer.generate_model_report_tree))
diff --git a/cfg_checker/reports/reporter.py b/cfg_checker/reports/reporter.py
index 9d2b2eb..e1d6b6f 100644
--- a/cfg_checker/reports/reporter.py
+++ b/cfg_checker/reports/reporter.py
@@ -63,7 +63,8 @@
# system, nodes, clusters, and the rest in other
data.update({
"nodes": payload['nodes'],
- "all_diffs": payload['diffs'],
+ "rc_diffs": payload['rc_diffs'],
+ "pkg_diffs": payload['pkg_diffs'],
"tabs": {}
})
@@ -121,18 +122,20 @@
return _fail_uniq
def _extend_data(self, data):
- _all_pkg = 0
+ # Count values on per-node basis
for key, value in data['nodes'].iteritems():
- # add count of packages for this node to total
- _all_pkg += len(value.keys())
-
# count differences
data['counters'][key] = {}
data['counters'][key]['packages'] = len(value['packages'].keys())
data['counters'][key]['package_diff'] = 0
+ data['counters'][key]['package_eq'] = 0
+
+ # Lookup if this fail is uniq for this node
for pkg_name, pkg_value in value['packages'].iteritems():
- if pkg_value['installed'] != pkg_value['candidate']:
- pkg_value['is_equal'] = False
+ if pkg_value['is_equal']:
+ pkg_value['fail_uniq'] = False
+ data['counters'][key]['package_eq'] += 1
+ else:
pkg_value['fail_uniq'] = self.is_fail_uniq(
pkg_value,
pkg_name,
@@ -140,11 +143,15 @@
key
)
data['counters'][key]['package_diff'] += 1
- else:
- pkg_value['is_equal'] = True
- pkg_value['fail_uniq'] = False
+
+ # Count values on all-diffs basis
+ for key, value in data['pkg_diffs'].iteritems():
+ data['counters'][key] = {}
+ data['counters'][key]['df_nodes'] = len(value['df_nodes'].keys())
+ data['counters'][key]['eq_nodes'] = len(value['eq_nodes'])
- data['counters']['total_packages'] = _all_pkg
+ # Save all packages counter
+ data['counters']['total_packages'] = data['pkg_diffs'].keys()
# Package versions report
@@ -153,8 +160,8 @@
def _extend_data(self, data):
# move names into separate place
- data["names"] = data["all_diffs"].pop("diff_names")
- data["tabs"] = data.pop("all_diffs")
+ data["names"] = data["rc_diffs"].pop("diff_names")
+ data["tabs"] = data.pop("rc_diffs")
# counters - mdl_diff
for _tab in data["tabs"].keys():
diff --git a/templates/pkg_versions_tmpl.j2 b/templates/pkg_versions_tmpl.j2
index 3c61745..b03e2ef 100644
--- a/templates/pkg_versions_tmpl.j2
+++ b/templates/pkg_versions_tmpl.j2
@@ -45,7 +45,7 @@
text-align: left;
cursor: pointer;
transition: 0.3s;
- font-size: 1.3em;
+ font-size: 1.1em;
width: 100%;
padding: 1px;
margin: 1px;
@@ -53,12 +53,12 @@
button > div.node_name {
float: left;
- font-size: 1.3em;
+ font-size: 0.8em;
}
.smallgreytext {
float: right;
- font-size: 0.7em;
+ font-size: 0.5em;
color: gray;
}
@@ -86,6 +86,15 @@
overflow-x: scroll;
overflow-wrap: break-word;
}
+ .collapsable {
+ visibility: collapse;
+ display: none;
+ }
+
+ .collapsable.in {
+ visibility: visible;
+ display: table-row;
+ }
table {
border: 0 hidden;
@@ -144,6 +153,26 @@
</style>
<script language="JavaScript">
+ function toggleClassByID(pkg, number) {
+ var elements = document.querySelectorAll("#"+pkg+"_"+number);
+ var ii = elements.length;
+ var button = document.querySelector("#"+pkg+"_button"+number);
+
+ while (ii--) {
+ if( elements[ii].className && elements[ii].className.indexOf("in") > -1 ) {
+ elements[ii].classList.remove("in");
+ button.innerHTML = "↑"
+ }
+ else {
+ elements[ii].classList.add("in");
+ button.innerHTML = "↓"
+ }
+ }
+
+
+ }
+ </script>
+ <script language="JavaScript">
function init() {
// Declare all variables
var i, tabcontent, tablinks;
@@ -187,8 +216,11 @@
</head>
<body onload="init()">
<div class="tab">
+ <button class="tablinks" onclick="openTab(event, 'All Diffs')")>
+ <div class="node_name">All Diffs</div>
+ </button>
{% for node_name in nodes.keys() | sort %}
- {% if nodes[node_name] | is_active %}
+ {% if counters[node_name]['package_diff'] %}
<button class="tablinks" onclick="openTab(event, '{{ node_name | shortname }}')">
<div class="dot_green">●</div>
<div class="node_name">{{ node_name | shortname }}</div>
@@ -197,15 +229,54 @@
{% endif %}
{% endfor %}
{% for node_name in nodes.keys() | sort %}
- {% if not nodes[node_name] | is_active %}
+ {% if not counters[node_name]['package_diff'] %}
<button class="tablinks" onclick="openTab(event, '{{ node_name | shortname }}')">
<div class="dot_empty">○</div>
<div class="node_name">{{ node_name | shortname }}</div>
<div class="smallgreytext">({{ counters[node_name]['package_diff'] }} / {{ counters[node_name]['packages'] }})</div>
</button>
- {% endif %}
+ {% endif %}
{% endfor %}
</div>
+<div id="All Diffs" class="tabcontent">
+ <table class="pkgversions">
+ <tbody>
+ <tr>
+ <td class="Header">Node name</td>
+ <td class="Header">Installed</td>
+ <td class="Header">Candidate</td>
+ </tr>
+ {% for pkg_name in pkg_diffs.keys() | sort %}
+ {% if counters[pkg_name]['df_nodes'] %}
+ {% set pkg_counter = 1 + loop.index0 %}
+ <tr>
+ <td>
+ <a href="#" onclick="toggleClassByID('{{ pkg_name }}', '{{ pkg_counter }}')" id="{{ pkg_name }}_button{{ pkg_counter }}">↑</a>
+ {{ pkg_name }}
+ </td>
+ <td>{{ counters[pkg_name]['df_nodes'] }}</td>
+ <td></td>
+ </tr>
+ <tr><td colspan=3>
+ <table class="nodes"><tbody>
+ {% for node in pkg_diffs[pkg_name]['df_nodes'].keys() | sort %}
+ <tr class="collapsable" id="{{ pkg_name }}_{{ pkg_counter }}">
+ <td class="pkgName">{{ node }}</td>
+ <td class="version differ">
+ <div class="tooltip">{{ pkg_diffs[pkg_name]['df_nodes'][node]['i'] }}
+ <pre class="tooltiptext">{{ pkg_diffs[pkg_name]['df_nodes'][node]['raw'] | linebreaks }}</pre>
+ </div>
+ </td>
+ <td class="version">{{ pkg_diffs[pkg_name]['df_nodes'][node]['c'] }}</td>
+ </tr>
+ {% endfor %}
+ </tbody></table>
+ </td></tr>
+ {% endif%}
+ {% endfor %}
+ </tbody>
+ </table>
+</div>
{% for node_name in nodes.keys() | sort %}
<div id="{{ node_name | shortname }}" class="tabcontent">
<table class="pkgversions">
@@ -247,20 +318,7 @@
{% endif %}
{% endif %}
{% endfor %}
- <tr><td colspan=3>Packages with same versions: installed vs candidate</td></tr>
- {% for package_name in nodes[node_name]['packages'] | sort %}
- {% if nodes[node_name]['packages'][package_name] | is_equal %}
- <tr>
- <td class="pkgName">{{ package_name }}</td>
- <td class="version">
- <div class="tooltip">{{ nodes[node_name]['packages'][package_name]['installed'] }}
- <pre class="tooltiptext">{{ nodes[node_name]['packages'][package_name]['raw'] | linebreaks }}</pre>
- </div>
- </td>
- <td class="version">{{ nodes[node_name]['packages'][package_name]['candidate'] }}</td>
- </tr>
- {% endif %}
- {% endfor %}
+ <tr><td colspan=3>Packages with same versions (installed vs candidate): {{ counters[node_name]['package_eq'] }}</td></tr>
</tbody>
</table>
</div>