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 | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame^] | 4 | from . import checker |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 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 | ) |
Alex | e9547d8 | 2019-06-03 15:22:50 -0500 | [diff] [blame] | 32 | 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 | ) |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 44 | 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 | ) |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 74 | pkg_repos.add_argument( |
| 75 | '--gen-apps', |
| 76 | action="store_true", default=False, |
| 77 | help="Save pkg descriptions while parsing" |
| 78 | ) |
Alex | 74dc135 | 2019-05-17 13:18:24 -0500 | [diff] [blame] | 79 | 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 | ) |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 88 | 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 | ) |
Alex | 74dc135 | 2019-05-17 13:18:24 -0500 | [diff] [blame] | 97 | |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 98 | return _parser |
| 99 | |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 100 | |
| 101 | def do_report(args): |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 102 | """Create package versions report, HTML |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 103 | |
| 104 | :args: - parser arguments |
| 105 | :return: - no return value |
| 106 | """ |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 107 | _type, _filename = args_utils.get_package_report_type_and_filename(args) |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 108 | |
Alex | e9547d8 | 2019-06-03 15:22:50 -0500 | [diff] [blame] | 109 | if ' ' in args.exclude_keywords: |
| 110 | _kw = args.exclude_keywords.split(' ') |
| 111 | else: |
| 112 | _kw = [args.exclude_keywords] |
| 113 | |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 114 | # init connection to salt and collect minion data |
Alex | e9547d8 | 2019-06-03 15:22:50 -0500 | [diff] [blame] | 115 | pChecker = checker.CloudPackageChecker( |
| 116 | force_tag=args.force_tag, |
| 117 | exclude_keywords=_kw |
| 118 | ) |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 119 | # collect data on installed packages |
| 120 | pChecker.collect_installed_packages() |
| 121 | # diff installed and candidates |
Alex Savatieiev | 3db12a7 | 2019-03-22 16:32:31 -0500 | [diff] [blame] | 122 | pChecker.collect_packages() |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 123 | # report it |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 124 | pChecker.create_report(_filename, rtype=_type, full=args.full) |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 125 | |
| 126 | |
| 127 | def do_versions(args): |
| 128 | """Builds tagged repo structure and parses Packages.gz files |
| 129 | |
| 130 | :args: - parser arguments |
| 131 | :return: - no return value |
| 132 | """ |
| 133 | # Get the list of tags for the url |
| 134 | r = RepoManager() |
Alex | 74dc135 | 2019-05-17 13:18:24 -0500 | [diff] [blame] | 135 | if args.list_tags: |
| 136 | r.action_for_tag(args.url, args.tag, action="list") |
| 137 | return |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 138 | if args.build_repos: |
| 139 | # if tag is supplied, use it |
| 140 | if args.tag: |
| 141 | r.action_for_tag(args.url, args.tag, action="build") |
| 142 | else: |
| 143 | r.build_repos(args.url) |
| 144 | |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 145 | if args.tag: |
| 146 | # Process only this tag |
| 147 | r.action_for_tag( |
| 148 | args.url, |
| 149 | args.tag, |
| 150 | action="fetch", |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 151 | descriptions=args.gen_desc, |
| 152 | apps=args.gen_apps |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 153 | ) |
| 154 | else: |
| 155 | # All of them |
| 156 | r.parse_repos() |
Alex | 74dc135 | 2019-05-17 13:18:24 -0500 | [diff] [blame] | 157 | |
| 158 | |
| 159 | def do_show(args): |
| 160 | """Shows package (or multiple) history across parsed tags |
| 161 | """ |
| 162 | # Init manager |
| 163 | r = RepoManager() |
| 164 | # show packages |
| 165 | for p in args.args: |
| 166 | r.show_package(p) |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 167 | |
| 168 | |
| 169 | def do_show_app(args): |
| 170 | """Shows packages for app |
| 171 | """ |
| 172 | # Init manager |
| 173 | r = RepoManager() |
| 174 | # show packages |
| 175 | for a in args.args: |
| 176 | r.show_app(a) |