blob: 45b1f773185769a344c0ea6b874f7d19c166312d [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
Alex3ebc5632019-04-18 16:47:18 -05004import checker
5
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 )
32
Alexd9fd85e2019-05-16 16:58:24 -050033 pkg_repos = pkg_subparsers.add_parser(
34 'versions',
35 help="Parse versions at given URL and create local map"
36 )
37 pkg_repos.add_argument(
38 '--list-tags',
39 action="store_true", default=False,
40 help="Just list tags available in mirror"
41 )
42 pkg_repos.add_argument(
43 '--url',
44 metavar='repo_url', default="http://mirror.mirantis.com",
45 help="URL for repos, default: http://mirror.mirantis.com"
46 )
47 pkg_repos.add_argument(
48 '--tag',
49 metavar='repo_tag', default=None,
50 help="Repository tag to process packages from. Default: "
51 "All url's root folder tags"
52 )
53 pkg_repos.add_argument(
54 '--build-repos',
55 action="store_true", default=False,
56 help="Conduct build stage before working with tags"
57 )
58 pkg_repos.add_argument(
59 '--gen-desc',
60 action="store_true", default=False,
61 help="Save pkg descriptions while parsing"
62 )
Alexd0391d42019-05-21 18:48:55 -050063 pkg_repos.add_argument(
64 '--gen-apps',
65 action="store_true", default=False,
66 help="Save pkg descriptions while parsing"
67 )
Alex74dc1352019-05-17 13:18:24 -050068 pkg_show = pkg_subparsers.add_parser(
69 'show',
70 help="Show package history from the map"
71 )
72 pkg_show.add_argument(
73 'args',
74 nargs='+',
75 help="Package names separated by space"
76 )
Alexd0391d42019-05-21 18:48:55 -050077 pkg_app = pkg_subparsers.add_parser(
78 'show-app',
79 help="Show packages for single app"
80 )
81 pkg_app.add_argument(
82 'args',
83 nargs='+',
84 help="List of app's packages (or 'source' in package description)"
85 )
Alex74dc1352019-05-17 13:18:24 -050086
Alexbab1efe2019-04-23 18:51:23 -050087 return _parser
88
Alex Savatieievc9055712019-03-01 14:43:56 -060089
90def do_report(args):
Alex41485522019-04-12 17:26:18 -050091 """Create package versions report, HTML
Alex Savatieievc9055712019-03-01 14:43:56 -060092
93 :args: - parser arguments
94 :return: - no return value
95 """
Alexbab1efe2019-04-23 18:51:23 -050096 _type, _filename = args_utils.get_package_report_type_and_filename(args)
Alex Savatieievc9055712019-03-01 14:43:56 -060097
98 # init connection to salt and collect minion data
99 pChecker = checker.CloudPackageChecker()
100 # collect data on installed packages
101 pChecker.collect_installed_packages()
102 # diff installed and candidates
Alex Savatieiev3db12a72019-03-22 16:32:31 -0500103 pChecker.collect_packages()
Alex Savatieievc9055712019-03-01 14:43:56 -0600104 # report it
Alex41485522019-04-12 17:26:18 -0500105 pChecker.create_report(_filename, rtype=_type, full=args.full)
Alexd9fd85e2019-05-16 16:58:24 -0500106
107
108def do_versions(args):
109 """Builds tagged repo structure and parses Packages.gz files
110
111 :args: - parser arguments
112 :return: - no return value
113 """
114 # Get the list of tags for the url
115 r = RepoManager()
Alex74dc1352019-05-17 13:18:24 -0500116 if args.list_tags:
117 r.action_for_tag(args.url, args.tag, action="list")
118 return
Alexd9fd85e2019-05-16 16:58:24 -0500119 if args.build_repos:
120 # if tag is supplied, use it
121 if args.tag:
122 r.action_for_tag(args.url, args.tag, action="build")
123 else:
124 r.build_repos(args.url)
125
Alexd9fd85e2019-05-16 16:58:24 -0500126 if args.tag:
127 # Process only this tag
128 r.action_for_tag(
129 args.url,
130 args.tag,
131 action="fetch",
Alexd0391d42019-05-21 18:48:55 -0500132 descriptions=args.gen_desc,
133 apps=args.gen_apps
Alexd9fd85e2019-05-16 16:58:24 -0500134 )
135 else:
136 # All of them
137 r.parse_repos()
Alex74dc1352019-05-17 13:18:24 -0500138
139
140def do_show(args):
141 """Shows package (or multiple) history across parsed tags
142 """
143 # Init manager
144 r = RepoManager()
145 # show packages
146 for p in args.args:
147 r.show_package(p)
Alexd0391d42019-05-21 18:48:55 -0500148
149
150def do_show_app(args):
151 """Shows packages for app
152 """
153 # Init manager
154 r = RepoManager()
155 # show packages
156 for a in args.args:
157 r.show_app(a)