Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 1 | from cfg_checker.helpers import args_utils |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame^] | 2 | from cfg_checker.modules.packages.repos import RepoManager |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 3 | |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 4 | import checker |
| 5 | |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 6 | command_help = "Package versions check (Candidate vs Installed)" |
| 7 | |
| 8 | |
| 9 | def 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 | |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame^] | 33 | 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 | ) |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 63 | return _parser |
| 64 | |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 65 | |
| 66 | def do_report(args): |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 67 | """Create package versions report, HTML |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 68 | |
| 69 | :args: - parser arguments |
| 70 | :return: - no return value |
| 71 | """ |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 72 | _type, _filename = args_utils.get_package_report_type_and_filename(args) |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 73 | |
| 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 Savatieiev | 3db12a7 | 2019-03-22 16:32:31 -0500 | [diff] [blame] | 79 | pChecker.collect_packages() |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 80 | # report it |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 81 | pChecker.create_report(_filename, rtype=_type, full=args.full) |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame^] | 82 | |
| 83 | |
| 84 | def 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() |