savex | 4448e13 | 2018-04-25 15:51:14 +0200 | [diff] [blame] | 1 | import json |
savex | 4448e13 | 2018-04-25 15:51:14 +0200 | [diff] [blame] | 2 | |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 3 | from cfg_checker.common import const, logger_cli |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 4 | from cfg_checker.common.exception import ConfigException |
Alex | 26b8a8c | 2019-10-09 17:09:07 -0500 | [diff] [blame] | 5 | from cfg_checker.common.other import merge_dict |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 6 | from cfg_checker.common.settings import ENV_TYPE_SALT |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 7 | from cfg_checker.helpers.console_utils import Progress |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 8 | from cfg_checker.modules.packages.repos import RepoManager |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 9 | from cfg_checker.nodes import SaltNodes, KubeNodes |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 10 | from cfg_checker.reports import reporter |
| 11 | |
Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 12 | from .versions import DebianVersion, PkgVersions, VersionCmpResult |
savex | 4448e13 | 2018-04-25 15:51:14 +0200 | [diff] [blame] | 13 | |
| 14 | |
Alex | e0c5b9e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 15 | class CloudPackageChecker(object): |
Alex | e9908f7 | 2020-05-19 16:04:53 -0500 | [diff] [blame] | 16 | def __init__( |
| 17 | self, |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 18 | config, |
Alex | e9908f7 | 2020-05-19 16:04:53 -0500 | [diff] [blame] | 19 | force_tag=None, |
| 20 | exclude_keywords=[], |
| 21 | skip_list=None, |
| 22 | skip_list_file=None |
| 23 | ): |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 24 | # check that this env tag is present in Manager |
| 25 | self.env_config = config |
| 26 | self.rm = RepoManager() |
| 27 | self.force_tag = force_tag |
| 28 | self.exclude_keywords = exclude_keywords |
| 29 | |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 30 | # Init salt master info |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 31 | if not self.master.nodes: |
| 32 | self.master.nodes = self.master.get_nodes( |
Alex | e9908f7 | 2020-05-19 16:04:53 -0500 | [diff] [blame] | 33 | skip_list=skip_list, |
| 34 | skip_list_file=skip_list_file |
| 35 | ) |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 36 | |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 37 | _tags = self.rm.get_available_tags(tag=self.master.mcp_release) |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 38 | if not _tags: |
| 39 | logger_cli.warning( |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 40 | "\n# WARNING: '{0}' is not listed in repo index. " |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 41 | "Consider running:\n\t{1}\nto add info on this tag's " |
| 42 | "release package versions".format( |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 43 | self.master.mcp_release, |
| 44 | "mcp-checker packages versions --tag <target_tag>" |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 45 | ) |
| 46 | ) |
| 47 | |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 48 | @staticmethod |
| 49 | def presort_packages(all_packages, full=None): |
| 50 | logger_cli.info("-> Presorting packages") |
| 51 | # labels |
| 52 | _data = {} |
| 53 | _data = { |
| 54 | "cs": { |
| 55 | "ok": const.VERSION_OK, |
| 56 | "up": const.VERSION_UP, |
| 57 | "down": const.VERSION_DOWN, |
Alex | 26b8a8c | 2019-10-09 17:09:07 -0500 | [diff] [blame] | 58 | "warn": const.VERSION_WARN, |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 59 | "err": const.VERSION_ERR |
| 60 | }, |
| 61 | "ca": { |
| 62 | "na": const.ACT_NA, |
| 63 | "up": const.ACT_UPGRADE, |
| 64 | "need_up": const.ACT_NEED_UP, |
| 65 | "need_down": const.ACT_NEED_DOWN, |
| 66 | "repo": const.ACT_REPO |
| 67 | } |
| 68 | } |
| 69 | _data['status_err'] = const.VERSION_ERR |
Alex | 26b8a8c | 2019-10-09 17:09:07 -0500 | [diff] [blame] | 70 | _data['status_warn'] = const.VERSION_WARN |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 71 | _data['status_down'] = const.VERSION_DOWN |
Alex | e9908f7 | 2020-05-19 16:04:53 -0500 | [diff] [blame] | 72 | _data['status_skip'] = const.VERSION_NA |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 73 | |
| 74 | # Presort packages |
| 75 | _data['critical'] = {} |
| 76 | _data['system'] = {} |
| 77 | _data['other'] = {} |
| 78 | _data['unlisted'] = {} |
| 79 | |
| 80 | _l = len(all_packages) |
| 81 | _progress = Progress(_l) |
| 82 | _progress_index = 0 |
| 83 | # counters |
| 84 | _ec = _es = _eo = _eu = 0 |
Alex | 26b8a8c | 2019-10-09 17:09:07 -0500 | [diff] [blame] | 85 | _wc = _ws = _wo = _wu = 0 |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 86 | _dc = _ds = _do = _du = 0 |
| 87 | while _progress_index < _l: |
| 88 | # progress bar |
| 89 | _progress_index += 1 |
| 90 | _progress.write_progress(_progress_index) |
| 91 | # sort packages |
| 92 | _pn, _val = all_packages.popitem() |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 93 | _c = _val['desc']['section'] |
Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 94 | _rkeys = _val['results'].keys() |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 95 | |
Alex | e0c5b9e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 96 | if not full: |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 97 | # Check if this packet has errors |
| 98 | # if all is ok -> just skip it |
| 99 | _max_status = max(_val['results'].keys()) |
| 100 | if _max_status <= const.VERSION_OK: |
| 101 | _max_action = max(_val['results'][_max_status].keys()) |
| 102 | if _max_action == const.ACT_NA: |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 103 | # this package does not have any comments |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 104 | # ...just skip it from report |
| 105 | continue |
| 106 | |
Alex | 26b8a8c | 2019-10-09 17:09:07 -0500 | [diff] [blame] | 107 | _differ = len(set(_val['results'].keys())) > 1 |
| 108 | if _differ: |
| 109 | # in case package has different status across nodes |
| 110 | # Warning becomes Error. |
| 111 | if const.VERSION_WARN in _val['results']: |
| 112 | if const.VERSION_ERR in _val['results']: |
| 113 | # add warns to err |
| 114 | # should never happen, though |
| 115 | merge_dict( |
| 116 | _val['results'].pop(const.VERSION_WARN), |
| 117 | _val['results'][const.VERSION_ERR] |
| 118 | ) |
| 119 | else: |
| 120 | _val['results'][const.VERSION_ERR] = \ |
| 121 | _val['results'].pop(const.VERSION_WARN) |
| 122 | else: |
| 123 | # in case package has same status on all nodes |
| 124 | # Error becomes Warning |
| 125 | if const.VERSION_ERR in _val['results']: |
| 126 | if const.VERSION_WARN in _val['results']: |
| 127 | # add warns to err |
| 128 | # should never happen, though |
| 129 | merge_dict( |
| 130 | _val['results'].pop(const.VERSION_ERR), |
| 131 | _val['results'][const.VERSION_WARN] |
| 132 | ) |
| 133 | else: |
| 134 | _val['results'][const.VERSION_WARN] = \ |
| 135 | _val['results'].pop(const.VERSION_ERR) |
| 136 | |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 137 | if len(_c) > 0 and _val['is_mirantis'] is None: |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 138 | # not listed package in version lib |
| 139 | _data['unlisted'].update({ |
| 140 | _pn: _val |
| 141 | }) |
Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 142 | _eu += sum(x == const.VERSION_ERR for x in _rkeys) |
| 143 | _wu += sum(x == const.VERSION_WARN for x in _rkeys) |
| 144 | _du += sum(x == const.VERSION_DOWN for x in _rkeys) |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 145 | # mirantis/critical |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 146 | # elif len(_c) > 0 and _c != 'System': |
| 147 | elif _val['is_mirantis']: |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 148 | # not blank and not system |
| 149 | _data['critical'].update({ |
| 150 | _pn: _val |
| 151 | }) |
Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 152 | _ec += sum(x == const.VERSION_ERR for x in _rkeys) |
| 153 | _wc += sum(x == const.VERSION_WARN for x in _rkeys) |
| 154 | _dc += sum(x == const.VERSION_DOWN for x in _rkeys) |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 155 | # system |
| 156 | elif _c == 'System': |
| 157 | _data['system'].update({ |
| 158 | _pn: _val |
| 159 | }) |
Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 160 | _es += sum(x == const.VERSION_ERR for x in _rkeys) |
| 161 | _ws += sum(x == const.VERSION_WARN for x in _rkeys) |
| 162 | _ds += sum(x == const.VERSION_DOWN for x in _rkeys) |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 163 | # rest |
| 164 | else: |
| 165 | _data['other'].update({ |
| 166 | _pn: _val |
| 167 | }) |
Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 168 | _eo += sum(x == const.VERSION_ERR for x in _rkeys) |
| 169 | _wo += sum(x == const.VERSION_WARN for x in _rkeys) |
| 170 | _do += sum(x == const.VERSION_DOWN for x in _rkeys) |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 171 | |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 172 | _progress.end() |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 173 | |
| 174 | _data['errors'] = { |
| 175 | 'mirantis': _ec, |
| 176 | 'system': _es, |
| 177 | 'other': _eo, |
| 178 | 'unlisted': _eu |
| 179 | } |
Alex | 26b8a8c | 2019-10-09 17:09:07 -0500 | [diff] [blame] | 180 | _data['warnings'] = { |
| 181 | 'mirantis': _wc, |
| 182 | 'system': _ws, |
| 183 | 'other': _wo, |
| 184 | 'unlisted': _wu |
| 185 | } |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 186 | _data['downgrades'] = { |
| 187 | 'mirantis': _dc, |
| 188 | 'system': _ds, |
| 189 | 'other': _do, |
| 190 | 'unlisted': _du |
| 191 | } |
| 192 | |
| 193 | return _data |
| 194 | |
savex | 4448e13 | 2018-04-25 15:51:14 +0200 | [diff] [blame] | 195 | def collect_packages(self): |
| 196 | """ |
| 197 | Check package versions in repos vs installed |
| 198 | |
| 199 | :return: no return values, all date put to dict in place |
| 200 | """ |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 201 | # Preload OpenStack release versions |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 202 | _desc = PkgVersions(self.env_config) |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 203 | logger_cli.info( |
| 204 | "# Cross-comparing: Installed vs Candidates vs Release" |
| 205 | ) |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 206 | # shortcuts for this cloud values |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 207 | _os = self.master.openstack_release |
| 208 | _mcp = self.master.mcp_release |
Alex | e9547d8 | 2019-06-03 15:22:50 -0500 | [diff] [blame] | 209 | _t = [self.force_tag] if self.force_tag else [] |
| 210 | _t.append(_mcp) |
| 211 | |
| 212 | logger_cli.info("# Tag search list: {}".format(", ".join(_t))) |
| 213 | logger_cli.info("# Openstack version: {}".format(_os)) |
| 214 | logger_cli.info( |
| 215 | "# Release versions repos keyword exclude list: {}".format( |
Alex | 9e4bfaf | 2019-06-11 15:21:59 -0500 | [diff] [blame] | 216 | ", ".join(self.exclude_keywords) |
Alex | e9547d8 | 2019-06-03 15:22:50 -0500 | [diff] [blame] | 217 | ) |
| 218 | ) |
| 219 | |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 220 | # Progress class |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 221 | _progress = Progress(len(self.master.nodes.keys())) |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 222 | _progress_index = 0 |
| 223 | _total_processed = 0 |
Alex Savatieiev | 3db12a7 | 2019-03-22 16:32:31 -0500 | [diff] [blame] | 224 | # Collect packages from all of the nodes in flat dict |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 225 | _all_packages = {} |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 226 | for node_name, node_value in self.master.nodes.items(): |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 227 | _uniq_len = len(_all_packages.keys()) |
| 228 | _progress_index += 1 |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 229 | # progress updates shown before next node only |
| 230 | # it is costly operation to do it for each of the 150k packages |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 231 | _progress.write_progress( |
| 232 | _progress_index, |
| 233 | note="/ {} uniq out of {} packages found".format( |
| 234 | _uniq_len, |
| 235 | _total_processed |
| 236 | ) |
| 237 | ) |
Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 238 | for _name, _value in node_value['packages'].items(): |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 239 | _total_processed += 1 |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 240 | # Parse versions from nodes |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 241 | _ver_ins = DebianVersion(_value['installed']) |
| 242 | _ver_can = DebianVersion(_value['candidate']) |
| 243 | |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 244 | # Process package description and release version |
| 245 | # at a first sight |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 246 | if _name not in _all_packages: |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 247 | # get node attributes |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 248 | _linux = \ |
| 249 | self.master.nodes[node_name]['linux_codename'] |
| 250 | _arch = self.master.nodes[node_name]['linux_arch'] |
Alex | e9547d8 | 2019-06-03 15:22:50 -0500 | [diff] [blame] | 251 | # get versions for tag, Openstack release and repo headers |
| 252 | # excluding 'nightly' repos by default |
| 253 | _r = {} |
| 254 | # if there is a forced tag = use it |
| 255 | if self.force_tag: |
| 256 | _r = self.rm.get_filtered_versions( |
| 257 | _name, |
| 258 | tag=self.force_tag, |
| 259 | include=[_os, _linux, _arch], |
Alex | 9e4bfaf | 2019-06-11 15:21:59 -0500 | [diff] [blame] | 260 | exclude=self.exclude_keywords |
Alex | e9547d8 | 2019-06-03 15:22:50 -0500 | [diff] [blame] | 261 | ) |
| 262 | # if nothing found, look everywhere |
Alex | 9e4bfaf | 2019-06-11 15:21:59 -0500 | [diff] [blame] | 263 | # but with no word 'openstack' |
Alex | e9547d8 | 2019-06-03 15:22:50 -0500 | [diff] [blame] | 264 | if not _r: |
| 265 | _r = self.rm.get_filtered_versions( |
| 266 | _name, |
| 267 | tag=self.force_tag, |
| 268 | include=[_linux, _arch], |
Alex | 9e4bfaf | 2019-06-11 15:21:59 -0500 | [diff] [blame] | 269 | exclude=self.exclude_keywords + ['openstack'] |
Alex | e9547d8 | 2019-06-03 15:22:50 -0500 | [diff] [blame] | 270 | ) |
| 271 | # if nothing is found at this point, |
| 272 | # repeat search using normal tags |
| 273 | if not _r: |
| 274 | _r = self.rm.get_filtered_versions( |
| 275 | _name, |
| 276 | tag=_mcp, |
| 277 | include=[_os, _linux, _arch], |
Alex | 9e4bfaf | 2019-06-11 15:21:59 -0500 | [diff] [blame] | 278 | exclude=self.exclude_keywords |
Alex | e9547d8 | 2019-06-03 15:22:50 -0500 | [diff] [blame] | 279 | ) |
| 280 | # Once again, if nothing found, look everywhere |
| 281 | if not _r: |
| 282 | _r = self.rm.get_filtered_versions( |
| 283 | _name, |
| 284 | tag=_mcp, |
| 285 | include=[_linux, _arch], |
Alex | 9e4bfaf | 2019-06-11 15:21:59 -0500 | [diff] [blame] | 286 | exclude=self.exclude_keywords + ['openstack'] |
Alex | e9547d8 | 2019-06-03 15:22:50 -0500 | [diff] [blame] | 287 | ) |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 288 | # repack versions in flat format |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 289 | _vs = {} |
| 290 | _sections = {} |
| 291 | _apps = {} |
Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 292 | for s, apps in _r.items(): |
| 293 | for a, versions in apps.items(): |
| 294 | for v, repos in versions.items(): |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 295 | for repo in repos: |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 296 | if v not in _vs: |
| 297 | _vs[v] = [] |
| 298 | _vs[v].append(repo) |
| 299 | if v not in _sections: |
| 300 | _sections[v] = [] |
| 301 | _sections[v].append(s) |
| 302 | if v not in _apps: |
| 303 | _apps[v] = [] |
| 304 | _apps[v].append(a) |
| 305 | # search for the newest version among filtered |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 306 | _r_desc = [] |
Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 307 | _vs_keys = iter(_vs.keys()) |
| 308 | # get next version, if any |
| 309 | try: |
| 310 | _newest = DebianVersion(next(_vs_keys)) |
| 311 | except StopIteration: |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 312 | _newest = DebianVersion('') |
Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 313 | # iterate others, if any |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 314 | for v in _vs_keys: |
| 315 | _this = DebianVersion(v) |
| 316 | if _this > _newest: |
| 317 | _newest = _this |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 318 | _release = _newest |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 319 | # Get best description for the package |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 320 | if _release.version != 'n/a': |
| 321 | _r_desc = _vs[_release.version] |
| 322 | # preload special description |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 323 | if _desc[_name]: |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 324 | _pkg_desc = _desc[_name] |
| 325 | else: |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 326 | _pkg_desc = _desc.dummy_desc |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 327 | # Save repos list and desc for this version |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 328 | # Check if we can provide better from the package |
| 329 | if _release.version != 'n/a': |
| 330 | if not _pkg_desc['section']: |
| 331 | _pkg_desc['section'] = \ |
| 332 | "/".join(_sections[_release.version]) |
| 333 | if not _pkg_desc['app']: |
| 334 | _pkg_desc['app'] = \ |
| 335 | "/".join(_apps[_release.version]) |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 336 | |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 337 | # Populate package info, once for package |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 338 | _m = _r_desc[0]["maintainer"] if _r_desc else 'n/a' |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 339 | _all_packages[_name] = { |
| 340 | "desc": _pkg_desc, |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 341 | "repos": _r_desc, |
| 342 | "maintainer": _m, |
| 343 | "is_mirantis": self.rm.is_mirantis( |
| 344 | _name, |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 345 | tag=_mcp |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 346 | ), |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 347 | "results": {}, |
| 348 | "r": _release, |
Alex Savatieiev | 3db12a7 | 2019-03-22 16:32:31 -0500 | [diff] [blame] | 349 | } |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 350 | # Cross-compare versions |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 351 | _cmp = VersionCmpResult( |
| 352 | _ver_ins, |
| 353 | _ver_can, |
| 354 | _all_packages[_name]['r'] |
| 355 | ) |
Alex | cf91b18 | 2019-05-31 11:57:07 -0500 | [diff] [blame] | 356 | # Update results structure |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 357 | # shortcut to results |
| 358 | _res = _all_packages[_name]['results'] |
| 359 | # update status |
| 360 | if _cmp.status not in _res: |
| 361 | _res[_cmp.status] = {} |
| 362 | # update action |
| 363 | if _cmp.action not in _res[_cmp.status]: |
| 364 | _res[_cmp.status][_cmp.action] = {} |
| 365 | # update node |
| 366 | if node_name not in _res[_cmp.status][_cmp.action]: |
| 367 | _res[_cmp.status][_cmp.action][node_name] = {} |
| 368 | # put result |
| 369 | _res[_cmp.status][_cmp.action][node_name] = { |
| 370 | 'i': _ver_ins, |
| 371 | 'c': _ver_can, |
| 372 | 'res': _cmp, |
| 373 | 'raw': _value['raw'] |
| 374 | } |
savex | 4448e13 | 2018-04-25 15:51:14 +0200 | [diff] [blame] | 375 | |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 376 | self._packages = _all_packages |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 377 | _progress.end() |
savex | 4448e13 | 2018-04-25 15:51:14 +0200 | [diff] [blame] | 378 | |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 379 | def create_report(self, filename, rtype, full=None): |
savex | 4448e13 | 2018-04-25 15:51:14 +0200 | [diff] [blame] | 380 | """ |
| 381 | Create static html showing packages diff per node |
| 382 | |
| 383 | :return: buff with html |
| 384 | """ |
Alex Savatieiev | 42b89fa | 2019-03-07 18:45:26 -0600 | [diff] [blame] | 385 | logger_cli.info("# Generating report to '{}'".format(filename)) |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 386 | if rtype == 'html': |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 387 | _type = reporter.HTMLPackageCandidates(self.master) |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 388 | elif rtype == 'csv': |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 389 | _type = reporter.CSVAllPackages(self.master) |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 390 | else: |
| 391 | raise ConfigException("Report type not set") |
Alex Savatieiev | d48994d | 2018-12-13 12:13:00 +0100 | [diff] [blame] | 392 | _report = reporter.ReportToFile( |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 393 | _type, |
savex | 4448e13 | 2018-04-25 15:51:14 +0200 | [diff] [blame] | 394 | filename |
| 395 | ) |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 396 | payload = { |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 397 | "nodes": self.master.nodes, |
| 398 | "mcp_release": self.master.mcp_release, |
| 399 | "openstack_release": self.master.openstack_release |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 400 | } |
| 401 | payload.update(self.presort_packages(self._packages, full)) |
| 402 | _report(payload) |
Alex Savatieiev | 799bee3 | 2019-02-20 17:19:26 -0600 | [diff] [blame] | 403 | logger_cli.info("-> Done") |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 404 | |
| 405 | def collect_installed_packages(self): |
| 406 | """ |
| 407 | Collect installed packages on each node |
| 408 | sets 'installed' dict property in the class |
| 409 | |
| 410 | :return: none |
| 411 | """ |
| 412 | logger_cli.info("# Collecting installed packages") |
| 413 | if self.master.env_type == ENV_TYPE_SALT: |
| 414 | self.master.prepare_script_on_active_nodes("pkg_versions.py") |
| 415 | _result = self.master.execute_script_on_active_nodes( |
| 416 | "pkg_versions.py" |
| 417 | ) |
| 418 | |
| 419 | for key in self.master.nodes.keys(): |
| 420 | # due to much data to be passed from salt, it is happening in order |
| 421 | if key in _result and _result[key]: |
| 422 | _text = _result[key] |
| 423 | try: |
| 424 | _dict = json.loads(_text[_text.find('{'):]) |
| 425 | except ValueError: |
| 426 | logger_cli.info("... no JSON for '{}'".format( |
| 427 | key |
| 428 | )) |
| 429 | logger_cli.debug( |
| 430 | "ERROR:\n{}\n".format(_text[:_text.find('{')]) |
| 431 | ) |
| 432 | _dict = {} |
| 433 | |
| 434 | self.master.nodes[key]['packages'] = _dict |
| 435 | else: |
| 436 | self.master.nodes[key]['packages'] = {} |
| 437 | logger_cli.debug("... {} has {} packages installed".format( |
| 438 | key, |
| 439 | len(self.master.nodes[key]['packages'].keys()) |
| 440 | )) |
| 441 | logger_cli.info("-> Done") |
| 442 | |
| 443 | |
| 444 | class SaltCloudPackageChecker(CloudPackageChecker): |
| 445 | def __init__( |
| 446 | self, |
| 447 | config, |
| 448 | force_tag=None, |
| 449 | exclude_keywords=[], |
| 450 | skip_list=None, |
| 451 | skip_list_file=None |
| 452 | ): |
| 453 | self.master = SaltNodes(config) |
| 454 | super(SaltCloudPackageChecker, self).__init__( |
| 455 | config, |
Alex | ccb72e0 | 2021-01-20 16:38:03 -0600 | [diff] [blame] | 456 | force_tag=force_tag, |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 457 | exclude_keywords=[], |
Alex | 359e575 | 2021-08-16 17:28:30 -0500 | [diff] [blame] | 458 | skip_list=skip_list, |
| 459 | skip_list_file=skip_list_file |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 460 | ) |
| 461 | |
| 462 | |
| 463 | class KubeCloudPackageChecker(CloudPackageChecker): |
| 464 | def __init__( |
| 465 | self, |
| 466 | config, |
| 467 | force_tag=None, |
| 468 | exclude_keywords=[], |
| 469 | skip_list=None, |
| 470 | skip_list_file=None |
| 471 | ): |
| 472 | self.master = KubeNodes(config) |
| 473 | super(KubeCloudPackageChecker, self).__init__( |
| 474 | config, |
Alex | ccb72e0 | 2021-01-20 16:38:03 -0600 | [diff] [blame] | 475 | force_tag=force_tag, |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 476 | exclude_keywords=[], |
Alex | 359e575 | 2021-08-16 17:28:30 -0500 | [diff] [blame] | 477 | skip_list=skip_list, |
| 478 | skip_list_file=skip_list_file |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 479 | ) |