blob: f88ce511c7acdcad331e969f062c403a5f6f1e07 [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 )
Alexbab1efe2019-04-23 18:51:23 -050063 return _parser
64
Alex Savatieievc9055712019-03-01 14:43:56 -060065
66def do_report(args):
Alex41485522019-04-12 17:26:18 -050067 """Create package versions report, HTML
Alex Savatieievc9055712019-03-01 14:43:56 -060068
69 :args: - parser arguments
70 :return: - no return value
71 """
Alexbab1efe2019-04-23 18:51:23 -050072 _type, _filename = args_utils.get_package_report_type_and_filename(args)
Alex Savatieievc9055712019-03-01 14:43:56 -060073
74 # init connection to salt and collect minion data
75 pChecker = checker.CloudPackageChecker()
76 # collect data on installed packages
77 pChecker.collect_installed_packages()
78 # diff installed and candidates
Alex Savatieiev3db12a72019-03-22 16:32:31 -050079 pChecker.collect_packages()
Alex Savatieievc9055712019-03-01 14:43:56 -060080 # report it
Alex41485522019-04-12 17:26:18 -050081 pChecker.create_report(_filename, rtype=_type, full=args.full)
Alexd9fd85e2019-05-16 16:58:24 -050082
83
84def do_versions(args):
85 """Builds tagged repo structure and parses Packages.gz files
86
87 :args: - parser arguments
88 :return: - no return value
89 """
90 # Get the list of tags for the url
91 r = RepoManager()
92 if args.build_repos:
93 # if tag is supplied, use it
94 if args.tag:
95 r.action_for_tag(args.url, args.tag, action="build")
96 else:
97 r.build_repos(args.url)
98
99 # if tag is supplied, use it
100 if args.tag:
101 # Process only this tag
102 r.action_for_tag(
103 args.url,
104 args.tag,
105 action="fetch",
106 descriptions=args.gen_desc
107 )
108 else:
109 # All of them
110 r.parse_repos()