blob: e482eec59fb1ca29d86765a989055425c97b1b78 [file] [log] [blame]
Alex9a4ad212020-10-01 18:04:25 -05001from cfg_checker.common.settings import ENV_TYPE_SALT, \
2 ENV_TYPE_KUBE, ENV_TYPE_LINUX
Alex Savatieievc9055712019-03-01 14:43:56 -06003from cfg_checker.helpers import args_utils
Alexd9fd85e2019-05-16 16:58:24 -05004from cfg_checker.modules.packages.repos import RepoManager
Alex Savatieievc9055712019-03-01 14:43:56 -06005
Alex3bc95f62020-03-05 17:00:04 -06006from . import checker
Alex3ebc5632019-04-18 16:47:18 -05007
Alexbab1efe2019-04-23 18:51:23 -05008command_help = "Package versions check (Candidate vs Installed)"
Alex9a4ad212020-10-01 18:04:25 -05009supported_envs = [ENV_TYPE_SALT, ENV_TYPE_KUBE, ENV_TYPE_LINUX]
Alexbab1efe2019-04-23 18:51:23 -050010
11
12def init_parser(_parser):
13 # packages subparser
14 pkg_subparsers = _parser.add_subparsers(dest='type')
15
16 pkg_report_parser = pkg_subparsers.add_parser(
17 'report',
18 help="Report package versions to HTML file"
19 )
20 pkg_report_parser.add_argument(
21 '--full',
22 action="store_true", default=False,
23 help="HTML report will have all of the packages, not just errors"
24 )
25 pkg_report_parser.add_argument(
26 '--html',
27 metavar='packages_html_filename',
28 help="HTML filename to save report"
29 )
30 pkg_report_parser.add_argument(
31 '--csv',
32 metavar='packages_csv_filename',
33 help="CSV filename to save report"
34 )
Alexe9547d82019-06-03 15:22:50 -050035 pkg_report_parser.add_argument(
36 '--force-tag',
37 metavar='force_tag', default=None,
38 help="Tag to do a forced search of release versions in. "
39 "If nothing is found, 'mcp_version' tag will be used"
40 )
41 pkg_report_parser.add_argument(
42 '--exclude-keywords',
43 metavar='exclude_repos_keywords', default="nightly extra",
44 help="Keywords to exclude repos from searching "
45 "release versions. Space delimited: 'nightly extra'"
46 )
Alexd9fd85e2019-05-16 16:58:24 -050047 pkg_repos = pkg_subparsers.add_parser(
48 'versions',
49 help="Parse versions at given URL and create local map"
50 )
51 pkg_repos.add_argument(
52 '--list-tags',
53 action="store_true", default=False,
54 help="Just list tags available in mirror"
55 )
56 pkg_repos.add_argument(
57 '--url',
58 metavar='repo_url', default="http://mirror.mirantis.com",
59 help="URL for repos, default: http://mirror.mirantis.com"
60 )
61 pkg_repos.add_argument(
62 '--tag',
63 metavar='repo_tag', default=None,
64 help="Repository tag to process packages from. Default: "
65 "All url's root folder tags"
66 )
67 pkg_repos.add_argument(
68 '--build-repos',
69 action="store_true", default=False,
70 help="Conduct build stage before working with tags"
71 )
72 pkg_repos.add_argument(
73 '--gen-desc',
74 action="store_true", default=False,
75 help="Save pkg descriptions while parsing"
76 )
Alexd0391d42019-05-21 18:48:55 -050077 pkg_repos.add_argument(
78 '--gen-apps',
79 action="store_true", default=False,
80 help="Save pkg descriptions while parsing"
81 )
Alex74dc1352019-05-17 13:18:24 -050082 pkg_show = pkg_subparsers.add_parser(
83 'show',
84 help="Show package history from the map"
85 )
86 pkg_show.add_argument(
87 'args',
88 nargs='+',
89 help="Package names separated by space"
90 )
Alexd0391d42019-05-21 18:48:55 -050091 pkg_app = pkg_subparsers.add_parser(
92 'show-app',
93 help="Show packages for single app"
94 )
95 pkg_app.add_argument(
96 'args',
97 nargs='+',
98 help="List of app's packages (or 'source' in package description)"
99 )
Alex74dc1352019-05-17 13:18:24 -0500100
Alexbab1efe2019-04-23 18:51:23 -0500101 return _parser
102
Alex Savatieievc9055712019-03-01 14:43:56 -0600103
Alex9a4ad212020-10-01 18:04:25 -0500104def do_report(args, config):
Alex41485522019-04-12 17:26:18 -0500105 """Create package versions report, HTML
Alex Savatieievc9055712019-03-01 14:43:56 -0600106
107 :args: - parser arguments
108 :return: - no return value
109 """
Alex9a4ad212020-10-01 18:04:25 -0500110 # Check if there is supported env found
111 _env = args_utils.check_supported_env(
112 [ENV_TYPE_SALT, ENV_TYPE_KUBE],
113 args,
114 config
115 )
116 # Start command
Alexbab1efe2019-04-23 18:51:23 -0500117 _type, _filename = args_utils.get_package_report_type_and_filename(args)
Alex Savatieievc9055712019-03-01 14:43:56 -0600118
Alexe9547d82019-06-03 15:22:50 -0500119 if ' ' in args.exclude_keywords:
120 _kw = args.exclude_keywords.split(' ')
121 else:
122 _kw = [args.exclude_keywords]
123
Alex Savatieievc9055712019-03-01 14:43:56 -0600124 # init connection to salt and collect minion data
Alexe9908f72020-05-19 16:04:53 -0500125 _skip, _skip_file = args_utils.get_skip_args(args)
Alex9a4ad212020-10-01 18:04:25 -0500126 if _env == ENV_TYPE_SALT:
127 pChecker = checker.SaltCloudPackageChecker(
128 config,
129 force_tag=args.force_tag,
130 exclude_keywords=_kw,
131 skip_list=_skip,
132 skip_list_file=_skip_file
133 )
134 elif _env == ENV_TYPE_KUBE:
135 pChecker = checker.KubeCloudPackageChecker(
136 config,
137 force_tag=args.force_tag,
138 exclude_keywords=_kw,
139 skip_list=_skip,
140 skip_list_file=_skip_file
141 )
142
Alex Savatieievc9055712019-03-01 14:43:56 -0600143 # collect data on installed packages
144 pChecker.collect_installed_packages()
145 # diff installed and candidates
Alex Savatieiev3db12a72019-03-22 16:32:31 -0500146 pChecker.collect_packages()
Alex Savatieievc9055712019-03-01 14:43:56 -0600147 # report it
Alex41485522019-04-12 17:26:18 -0500148 pChecker.create_report(_filename, rtype=_type, full=args.full)
Alexd9fd85e2019-05-16 16:58:24 -0500149
150
Alex9a4ad212020-10-01 18:04:25 -0500151def do_versions(args, config):
Alexd9fd85e2019-05-16 16:58:24 -0500152 """Builds tagged repo structure and parses Packages.gz files
153
154 :args: - parser arguments
155 :return: - no return value
156 """
Alex9a4ad212020-10-01 18:04:25 -0500157 # Check if there is supported env found
158 args_utils.check_supported_env(ENV_TYPE_LINUX, args, config)
Alexd9fd85e2019-05-16 16:58:24 -0500159 # Get the list of tags for the url
160 r = RepoManager()
Alex74dc1352019-05-17 13:18:24 -0500161 if args.list_tags:
162 r.action_for_tag(args.url, args.tag, action="list")
163 return
Alexd9fd85e2019-05-16 16:58:24 -0500164 if args.build_repos:
165 # if tag is supplied, use it
166 if args.tag:
167 r.action_for_tag(args.url, args.tag, action="build")
168 else:
169 r.build_repos(args.url)
170
Alexd9fd85e2019-05-16 16:58:24 -0500171 if args.tag:
172 # Process only this tag
173 r.action_for_tag(
174 args.url,
175 args.tag,
176 action="fetch",
Alexd0391d42019-05-21 18:48:55 -0500177 descriptions=args.gen_desc,
178 apps=args.gen_apps
Alexd9fd85e2019-05-16 16:58:24 -0500179 )
180 else:
181 # All of them
182 r.parse_repos()
Alex74dc1352019-05-17 13:18:24 -0500183
184
Alex9a4ad212020-10-01 18:04:25 -0500185def do_show(args, config):
Alex74dc1352019-05-17 13:18:24 -0500186 """Shows package (or multiple) history across parsed tags
187 """
Alex9a4ad212020-10-01 18:04:25 -0500188 # Check if there is supported env found
189 args_utils.check_supported_env(ENV_TYPE_LINUX, args, config)
Alex74dc1352019-05-17 13:18:24 -0500190 # Init manager
191 r = RepoManager()
192 # show packages
193 for p in args.args:
194 r.show_package(p)
Alexd0391d42019-05-21 18:48:55 -0500195
196
Alex9a4ad212020-10-01 18:04:25 -0500197def do_show_app(args, config):
Alexd0391d42019-05-21 18:48:55 -0500198 """Shows packages for app
199 """
Alex9a4ad212020-10-01 18:04:25 -0500200 # Check if there is supported env found
201 args_utils.check_supported_env(ENV_TYPE_LINUX, args, config)
Alexd0391d42019-05-21 18:48:55 -0500202 # Init manager
203 r = RepoManager()
204 # show packages
205 for a in args.args:
206 r.show_app(a)