blob: 6d84a80d9fbdc7d77db616bf1a11117d196bb53c [file] [log] [blame]
Alex0989ecf2022-03-29 13:43:21 -05001# Author: Alex Savatieiev (osavatieiev@mirantis.com; a.savex@gmail.com)
2# Copyright 2019-2022 Mirantis, Inc.
Alex9a4ad212020-10-01 18:04:25 -05003from cfg_checker.common.settings import ENV_TYPE_SALT, \
4 ENV_TYPE_KUBE, ENV_TYPE_LINUX
Alex Savatieievc9055712019-03-01 14:43:56 -06005from cfg_checker.helpers import args_utils
Alexd9fd85e2019-05-16 16:58:24 -05006from cfg_checker.modules.packages.repos import RepoManager
Alex Savatieievc9055712019-03-01 14:43:56 -06007
Alex3bc95f62020-03-05 17:00:04 -06008from . import checker
Alex3ebc5632019-04-18 16:47:18 -05009
Alexbab1efe2019-04-23 18:51:23 -050010command_help = "Package versions check (Candidate vs Installed)"
Alex9a4ad212020-10-01 18:04:25 -050011supported_envs = [ENV_TYPE_SALT, ENV_TYPE_KUBE, ENV_TYPE_LINUX]
Alexbab1efe2019-04-23 18:51:23 -050012
13
14def init_parser(_parser):
15 # packages subparser
16 pkg_subparsers = _parser.add_subparsers(dest='type')
17
18 pkg_report_parser = pkg_subparsers.add_parser(
19 'report',
20 help="Report package versions to HTML file"
21 )
22 pkg_report_parser.add_argument(
23 '--full',
24 action="store_true", default=False,
25 help="HTML report will have all of the packages, not just errors"
26 )
27 pkg_report_parser.add_argument(
28 '--html',
29 metavar='packages_html_filename',
30 help="HTML filename to save report"
31 )
32 pkg_report_parser.add_argument(
33 '--csv',
34 metavar='packages_csv_filename',
35 help="CSV filename to save report"
36 )
Alexe9547d82019-06-03 15:22:50 -050037 pkg_report_parser.add_argument(
38 '--force-tag',
39 metavar='force_tag', default=None,
40 help="Tag to do a forced search of release versions in. "
41 "If nothing is found, 'mcp_version' tag will be used"
42 )
43 pkg_report_parser.add_argument(
44 '--exclude-keywords',
45 metavar='exclude_repos_keywords', default="nightly extra",
46 help="Keywords to exclude repos from searching "
47 "release versions. Space delimited: 'nightly extra'"
48 )
Alexd9fd85e2019-05-16 16:58:24 -050049 pkg_repos = pkg_subparsers.add_parser(
50 'versions',
51 help="Parse versions at given URL and create local map"
52 )
53 pkg_repos.add_argument(
54 '--list-tags',
55 action="store_true", default=False,
56 help="Just list tags available in mirror"
57 )
58 pkg_repos.add_argument(
59 '--url',
60 metavar='repo_url', default="http://mirror.mirantis.com",
61 help="URL for repos, default: http://mirror.mirantis.com"
62 )
63 pkg_repos.add_argument(
64 '--tag',
65 metavar='repo_tag', default=None,
66 help="Repository tag to process packages from. Default: "
67 "All url's root folder tags"
68 )
69 pkg_repos.add_argument(
70 '--build-repos',
71 action="store_true", default=False,
72 help="Conduct build stage before working with tags"
73 )
74 pkg_repos.add_argument(
75 '--gen-desc',
76 action="store_true", default=False,
77 help="Save pkg descriptions while parsing"
78 )
Alexd0391d42019-05-21 18:48:55 -050079 pkg_repos.add_argument(
80 '--gen-apps',
81 action="store_true", default=False,
82 help="Save pkg descriptions while parsing"
83 )
Alex74dc1352019-05-17 13:18:24 -050084 pkg_show = pkg_subparsers.add_parser(
85 'show',
86 help="Show package history from the map"
87 )
88 pkg_show.add_argument(
89 'args',
90 nargs='+',
91 help="Package names separated by space"
92 )
Alexd0391d42019-05-21 18:48:55 -050093 pkg_app = pkg_subparsers.add_parser(
94 'show-app',
95 help="Show packages for single app"
96 )
97 pkg_app.add_argument(
98 'args',
99 nargs='+',
100 help="List of app's packages (or 'source' in package description)"
101 )
Alex74dc1352019-05-17 13:18:24 -0500102
Alexbab1efe2019-04-23 18:51:23 -0500103 return _parser
104
Alex Savatieievc9055712019-03-01 14:43:56 -0600105
Alex9a4ad212020-10-01 18:04:25 -0500106def do_report(args, config):
Alex41485522019-04-12 17:26:18 -0500107 """Create package versions report, HTML
Alex Savatieievc9055712019-03-01 14:43:56 -0600108
109 :args: - parser arguments
110 :return: - no return value
111 """
Alex9a4ad212020-10-01 18:04:25 -0500112 # Check if there is supported env found
113 _env = args_utils.check_supported_env(
114 [ENV_TYPE_SALT, ENV_TYPE_KUBE],
115 args,
116 config
117 )
118 # Start command
Alexbab1efe2019-04-23 18:51:23 -0500119 _type, _filename = args_utils.get_package_report_type_and_filename(args)
Alex Savatieievc9055712019-03-01 14:43:56 -0600120
Alexe9547d82019-06-03 15:22:50 -0500121 if ' ' in args.exclude_keywords:
122 _kw = args.exclude_keywords.split(' ')
123 else:
124 _kw = [args.exclude_keywords]
125
Alex Savatieievc9055712019-03-01 14:43:56 -0600126 # init connection to salt and collect minion data
Alexe9908f72020-05-19 16:04:53 -0500127 _skip, _skip_file = args_utils.get_skip_args(args)
Alex9a4ad212020-10-01 18:04:25 -0500128 if _env == ENV_TYPE_SALT:
129 pChecker = checker.SaltCloudPackageChecker(
130 config,
131 force_tag=args.force_tag,
132 exclude_keywords=_kw,
133 skip_list=_skip,
134 skip_list_file=_skip_file
135 )
136 elif _env == ENV_TYPE_KUBE:
137 pChecker = checker.KubeCloudPackageChecker(
138 config,
139 force_tag=args.force_tag,
140 exclude_keywords=_kw,
141 skip_list=_skip,
142 skip_list_file=_skip_file
143 )
144
Alex Savatieievc9055712019-03-01 14:43:56 -0600145 # collect data on installed packages
146 pChecker.collect_installed_packages()
147 # diff installed and candidates
Alex Savatieiev3db12a72019-03-22 16:32:31 -0500148 pChecker.collect_packages()
Alex Savatieievc9055712019-03-01 14:43:56 -0600149 # report it
Alex41485522019-04-12 17:26:18 -0500150 pChecker.create_report(_filename, rtype=_type, full=args.full)
Alexd9fd85e2019-05-16 16:58:24 -0500151
152
Alex9a4ad212020-10-01 18:04:25 -0500153def do_versions(args, config):
Alexd9fd85e2019-05-16 16:58:24 -0500154 """Builds tagged repo structure and parses Packages.gz files
155
156 :args: - parser arguments
157 :return: - no return value
158 """
Alex9a4ad212020-10-01 18:04:25 -0500159 # Check if there is supported env found
160 args_utils.check_supported_env(ENV_TYPE_LINUX, args, config)
Alexd9fd85e2019-05-16 16:58:24 -0500161 # Get the list of tags for the url
162 r = RepoManager()
Alex74dc1352019-05-17 13:18:24 -0500163 if args.list_tags:
164 r.action_for_tag(args.url, args.tag, action="list")
165 return
Alexd9fd85e2019-05-16 16:58:24 -0500166 if args.build_repos:
167 # if tag is supplied, use it
168 if args.tag:
169 r.action_for_tag(args.url, args.tag, action="build")
170 else:
171 r.build_repos(args.url)
172
Alexd9fd85e2019-05-16 16:58:24 -0500173 if args.tag:
174 # Process only this tag
175 r.action_for_tag(
176 args.url,
177 args.tag,
178 action="fetch",
Alexd0391d42019-05-21 18:48:55 -0500179 descriptions=args.gen_desc,
180 apps=args.gen_apps
Alexd9fd85e2019-05-16 16:58:24 -0500181 )
182 else:
183 # All of them
184 r.parse_repos()
Alex74dc1352019-05-17 13:18:24 -0500185
186
Alex9a4ad212020-10-01 18:04:25 -0500187def do_show(args, config):
Alex74dc1352019-05-17 13:18:24 -0500188 """Shows package (or multiple) history across parsed tags
189 """
Alex9a4ad212020-10-01 18:04:25 -0500190 # Check if there is supported env found
191 args_utils.check_supported_env(ENV_TYPE_LINUX, args, config)
Alex74dc1352019-05-17 13:18:24 -0500192 # Init manager
193 r = RepoManager()
194 # show packages
195 for p in args.args:
196 r.show_package(p)
Alexd0391d42019-05-21 18:48:55 -0500197
198
Alex9a4ad212020-10-01 18:04:25 -0500199def do_show_app(args, config):
Alexd0391d42019-05-21 18:48:55 -0500200 """Shows packages for app
201 """
Alex9a4ad212020-10-01 18:04:25 -0500202 # Check if there is supported env found
203 args_utils.check_supported_env(ENV_TYPE_LINUX, args, config)
Alexd0391d42019-05-21 18:48:55 -0500204 # Init manager
205 r = RepoManager()
206 # show packages
207 for a in args.args:
208 r.show_app(a)