blob: 2d0cc79cbc5edd3ed7a0d6c90fc48bd7fa364217 [file] [log] [blame]
Alex Savatieievc9055712019-03-01 14:43:56 -06001from cfg_checker.helpers import args_utils
Alexd9fd85e2019-05-16 16:58:24 -05002from cfg_checker.modules.packages.repos import RepoManager
Alex Savatieievc9055712019-03-01 14:43:56 -06003
Alex3bc95f62020-03-05 17:00:04 -06004from . import checker
Alex3ebc5632019-04-18 16:47:18 -05005
Alexbab1efe2019-04-23 18:51:23 -05006command_help = "Package versions check (Candidate vs Installed)"
7
8
9def init_parser(_parser):
10 # packages subparser
11 pkg_subparsers = _parser.add_subparsers(dest='type')
12
13 pkg_report_parser = pkg_subparsers.add_parser(
14 'report',
15 help="Report package versions to HTML file"
16 )
17 pkg_report_parser.add_argument(
18 '--full',
19 action="store_true", default=False,
20 help="HTML report will have all of the packages, not just errors"
21 )
22 pkg_report_parser.add_argument(
23 '--html',
24 metavar='packages_html_filename',
25 help="HTML filename to save report"
26 )
27 pkg_report_parser.add_argument(
28 '--csv',
29 metavar='packages_csv_filename',
30 help="CSV filename to save report"
31 )
Alexe9547d82019-06-03 15:22:50 -050032 pkg_report_parser.add_argument(
33 '--force-tag',
34 metavar='force_tag', default=None,
35 help="Tag to do a forced search of release versions in. "
36 "If nothing is found, 'mcp_version' tag will be used"
37 )
38 pkg_report_parser.add_argument(
39 '--exclude-keywords',
40 metavar='exclude_repos_keywords', default="nightly extra",
41 help="Keywords to exclude repos from searching "
42 "release versions. Space delimited: 'nightly extra'"
43 )
Alexd9fd85e2019-05-16 16:58:24 -050044 pkg_repos = pkg_subparsers.add_parser(
45 'versions',
46 help="Parse versions at given URL and create local map"
47 )
48 pkg_repos.add_argument(
49 '--list-tags',
50 action="store_true", default=False,
51 help="Just list tags available in mirror"
52 )
53 pkg_repos.add_argument(
54 '--url',
55 metavar='repo_url', default="http://mirror.mirantis.com",
56 help="URL for repos, default: http://mirror.mirantis.com"
57 )
58 pkg_repos.add_argument(
59 '--tag',
60 metavar='repo_tag', default=None,
61 help="Repository tag to process packages from. Default: "
62 "All url's root folder tags"
63 )
64 pkg_repos.add_argument(
65 '--build-repos',
66 action="store_true", default=False,
67 help="Conduct build stage before working with tags"
68 )
69 pkg_repos.add_argument(
70 '--gen-desc',
71 action="store_true", default=False,
72 help="Save pkg descriptions while parsing"
73 )
Alexd0391d42019-05-21 18:48:55 -050074 pkg_repos.add_argument(
75 '--gen-apps',
76 action="store_true", default=False,
77 help="Save pkg descriptions while parsing"
78 )
Alex74dc1352019-05-17 13:18:24 -050079 pkg_show = pkg_subparsers.add_parser(
80 'show',
81 help="Show package history from the map"
82 )
83 pkg_show.add_argument(
84 'args',
85 nargs='+',
86 help="Package names separated by space"
87 )
Alexd0391d42019-05-21 18:48:55 -050088 pkg_app = pkg_subparsers.add_parser(
89 'show-app',
90 help="Show packages for single app"
91 )
92 pkg_app.add_argument(
93 'args',
94 nargs='+',
95 help="List of app's packages (or 'source' in package description)"
96 )
Alex74dc1352019-05-17 13:18:24 -050097
Alexbab1efe2019-04-23 18:51:23 -050098 return _parser
99
Alex Savatieievc9055712019-03-01 14:43:56 -0600100
101def do_report(args):
Alex41485522019-04-12 17:26:18 -0500102 """Create package versions report, HTML
Alex Savatieievc9055712019-03-01 14:43:56 -0600103
104 :args: - parser arguments
105 :return: - no return value
106 """
Alexbab1efe2019-04-23 18:51:23 -0500107 _type, _filename = args_utils.get_package_report_type_and_filename(args)
Alex Savatieievc9055712019-03-01 14:43:56 -0600108
Alexe9547d82019-06-03 15:22:50 -0500109 if ' ' in args.exclude_keywords:
110 _kw = args.exclude_keywords.split(' ')
111 else:
112 _kw = [args.exclude_keywords]
113
Alex Savatieievc9055712019-03-01 14:43:56 -0600114 # init connection to salt and collect minion data
Alexe9908f72020-05-19 16:04:53 -0500115 _skip, _skip_file = args_utils.get_skip_args(args)
Alexe9547d82019-06-03 15:22:50 -0500116 pChecker = checker.CloudPackageChecker(
117 force_tag=args.force_tag,
Alexe9908f72020-05-19 16:04:53 -0500118 exclude_keywords=_kw,
119 skip_list=_skip,
120 skip_list_file=_skip_file
Alexe9547d82019-06-03 15:22:50 -0500121 )
Alex Savatieievc9055712019-03-01 14:43:56 -0600122 # collect data on installed packages
123 pChecker.collect_installed_packages()
124 # diff installed and candidates
Alex Savatieiev3db12a72019-03-22 16:32:31 -0500125 pChecker.collect_packages()
Alex Savatieievc9055712019-03-01 14:43:56 -0600126 # report it
Alex41485522019-04-12 17:26:18 -0500127 pChecker.create_report(_filename, rtype=_type, full=args.full)
Alexd9fd85e2019-05-16 16:58:24 -0500128
129
130def do_versions(args):
131 """Builds tagged repo structure and parses Packages.gz files
132
133 :args: - parser arguments
134 :return: - no return value
135 """
136 # Get the list of tags for the url
137 r = RepoManager()
Alex74dc1352019-05-17 13:18:24 -0500138 if args.list_tags:
139 r.action_for_tag(args.url, args.tag, action="list")
140 return
Alexd9fd85e2019-05-16 16:58:24 -0500141 if args.build_repos:
142 # if tag is supplied, use it
143 if args.tag:
144 r.action_for_tag(args.url, args.tag, action="build")
145 else:
146 r.build_repos(args.url)
147
Alexd9fd85e2019-05-16 16:58:24 -0500148 if args.tag:
149 # Process only this tag
150 r.action_for_tag(
151 args.url,
152 args.tag,
153 action="fetch",
Alexd0391d42019-05-21 18:48:55 -0500154 descriptions=args.gen_desc,
155 apps=args.gen_apps
Alexd9fd85e2019-05-16 16:58:24 -0500156 )
157 else:
158 # All of them
159 r.parse_repos()
Alex74dc1352019-05-17 13:18:24 -0500160
161
162def do_show(args):
163 """Shows package (or multiple) history across parsed tags
164 """
165 # Init manager
166 r = RepoManager()
167 # show packages
168 for p in args.args:
169 r.show_package(p)
Alexd0391d42019-05-21 18:48:55 -0500170
171
172def do_show_app(args):
173 """Shows packages for app
174 """
175 # Init manager
176 r = RepoManager()
177 # show packages
178 for a in args.args:
179 r.show_app(a)