blob: 797c0fe6d48a4e8a5e11e773faf23de920bd0284 [file] [log] [blame]
savex4448e132018-04-25 15:51:14 +02001import json
2import os
Alex Savatieievc9055712019-03-01 14:43:56 -06003#import sys
savex4448e132018-04-25 15:51:14 +02004
5from copy import deepcopy
6
Alex Savatieievf526dc02019-03-06 10:11:32 -06007from cfg_checker.reports import reporter
Alex Savatieiev5118de02019-02-20 15:50:42 -06008from cfg_checker.common import utils, const
9from cfg_checker.common import config, logger, logger_cli, pkg_dir
10from cfg_checker.common import salt_utils
Alex Savatieiev9b2f6512019-02-20 18:05:00 -060011from cfg_checker.nodes import SaltNodes, node_tmpl
savex4448e132018-04-25 15:51:14 +020012
13
Alex Savatieiev9b2f6512019-02-20 18:05:00 -060014class CloudPackageChecker(SaltNodes):
savex4448e132018-04-25 15:51:14 +020015 def collect_installed_packages(self):
16 """
17 Collect installed packages on each node
18 sets 'installed' dict property in the class
19
20 :return: none
21 """
Alex Savatieiev42b89fa2019-03-07 18:45:26 -060022 logger_cli.info("# Collecting installed packages")
Alex Savatieiev01f0d7f2019-03-07 17:53:29 -060023 _result = self.execute_script_on_active_nodes("pkg_versions.py")
savex4448e132018-04-25 15:51:14 +020024
savex4448e132018-04-25 15:51:14 +020025 for key in self.nodes.keys():
26 # due to much data to be passed from salt, it is happening in order
27 if key in _result:
28 _text = _result[key]
29 _dict = json.loads(_text[_text.find('{'):])
30 self.nodes[key]['packages'] = _dict
31 else:
32 self.nodes[key]['packages'] = {}
Alex Savatieiev42b89fa2019-03-07 18:45:26 -060033 logger_cli.debug("... {} has {} packages installed".format(
savex4448e132018-04-25 15:51:14 +020034 key,
35 len(self.nodes[key]['packages'].keys())
36 ))
Alex Savatieiev799bee32019-02-20 17:19:26 -060037 logger_cli.info("-> Done")
savex4448e132018-04-25 15:51:14 +020038
39 def collect_packages(self):
40 """
41 Check package versions in repos vs installed
42
43 :return: no return values, all date put to dict in place
44 """
45 _all_packages = {}
46 for node_name, node_value in self.nodes.iteritems():
47 for package_name in node_value['packages']:
48 if package_name not in _all_packages:
49 _all_packages[package_name] = {}
50 _all_packages[package_name][node_name] = node_value
51
52 # TODO: process data for per-package basis
53
54 self.all_packages = _all_packages
55
56 def create_html_report(self, filename):
57 """
58 Create static html showing packages diff per node
59
60 :return: buff with html
61 """
Alex Savatieiev42b89fa2019-03-07 18:45:26 -060062 logger_cli.info("# Generating report to '{}'".format(filename))
Alex Savatieievd48994d2018-12-13 12:13:00 +010063 _report = reporter.ReportToFile(
64 reporter.HTMLPackageCandidates(),
savex4448e132018-04-25 15:51:14 +020065 filename
66 )
Alex Savatieiev36b938d2019-01-21 11:01:18 +010067 _report({
68 "nodes": self.nodes,
69 "diffs": {}
70 })
Alex Savatieiev799bee32019-02-20 17:19:26 -060071 logger_cli.info("-> Done")