Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 1 | from cfg_checker.common.settings import ENV_TYPE_SALT, \ |
| 2 | ENV_TYPE_KUBE, ENV_TYPE_LINUX |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 3 | from cfg_checker.helpers import args_utils |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 4 | from cfg_checker.modules.packages.repos import RepoManager |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 5 | |
Alex | 3bc95f6 | 2020-03-05 17:00:04 -0600 | [diff] [blame] | 6 | from . import checker |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 7 | |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 8 | command_help = "Package versions check (Candidate vs Installed)" |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 9 | supported_envs = [ENV_TYPE_SALT, ENV_TYPE_KUBE, ENV_TYPE_LINUX] |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 10 | |
| 11 | |
| 12 | def init_parser(_parser): |
| 13 | # packages subparser |
| 14 | pkg_subparsers = _parser.add_subparsers(dest='type') |
| 15 | |
| 16 | pkg_report_parser = pkg_subparsers.add_parser( |
| 17 | 'report', |
| 18 | help="Report package versions to HTML file" |
| 19 | ) |
| 20 | pkg_report_parser.add_argument( |
| 21 | '--full', |
| 22 | action="store_true", default=False, |
| 23 | help="HTML report will have all of the packages, not just errors" |
| 24 | ) |
| 25 | pkg_report_parser.add_argument( |
| 26 | '--html', |
| 27 | metavar='packages_html_filename', |
| 28 | help="HTML filename to save report" |
| 29 | ) |
| 30 | pkg_report_parser.add_argument( |
| 31 | '--csv', |
| 32 | metavar='packages_csv_filename', |
| 33 | help="CSV filename to save report" |
| 34 | ) |
Alex | e9547d8 | 2019-06-03 15:22:50 -0500 | [diff] [blame] | 35 | pkg_report_parser.add_argument( |
| 36 | '--force-tag', |
| 37 | metavar='force_tag', default=None, |
| 38 | help="Tag to do a forced search of release versions in. " |
| 39 | "If nothing is found, 'mcp_version' tag will be used" |
| 40 | ) |
| 41 | pkg_report_parser.add_argument( |
| 42 | '--exclude-keywords', |
| 43 | metavar='exclude_repos_keywords', default="nightly extra", |
| 44 | help="Keywords to exclude repos from searching " |
| 45 | "release versions. Space delimited: 'nightly extra'" |
| 46 | ) |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 47 | pkg_repos = pkg_subparsers.add_parser( |
| 48 | 'versions', |
| 49 | help="Parse versions at given URL and create local map" |
| 50 | ) |
| 51 | pkg_repos.add_argument( |
| 52 | '--list-tags', |
| 53 | action="store_true", default=False, |
| 54 | help="Just list tags available in mirror" |
| 55 | ) |
| 56 | pkg_repos.add_argument( |
| 57 | '--url', |
| 58 | metavar='repo_url', default="http://mirror.mirantis.com", |
| 59 | help="URL for repos, default: http://mirror.mirantis.com" |
| 60 | ) |
| 61 | pkg_repos.add_argument( |
| 62 | '--tag', |
| 63 | metavar='repo_tag', default=None, |
| 64 | help="Repository tag to process packages from. Default: " |
| 65 | "All url's root folder tags" |
| 66 | ) |
| 67 | pkg_repos.add_argument( |
| 68 | '--build-repos', |
| 69 | action="store_true", default=False, |
| 70 | help="Conduct build stage before working with tags" |
| 71 | ) |
| 72 | pkg_repos.add_argument( |
| 73 | '--gen-desc', |
| 74 | action="store_true", default=False, |
| 75 | help="Save pkg descriptions while parsing" |
| 76 | ) |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 77 | pkg_repos.add_argument( |
| 78 | '--gen-apps', |
| 79 | action="store_true", default=False, |
| 80 | help="Save pkg descriptions while parsing" |
| 81 | ) |
Alex | 74dc135 | 2019-05-17 13:18:24 -0500 | [diff] [blame] | 82 | pkg_show = pkg_subparsers.add_parser( |
| 83 | 'show', |
| 84 | help="Show package history from the map" |
| 85 | ) |
| 86 | pkg_show.add_argument( |
| 87 | 'args', |
| 88 | nargs='+', |
| 89 | help="Package names separated by space" |
| 90 | ) |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 91 | pkg_app = pkg_subparsers.add_parser( |
| 92 | 'show-app', |
| 93 | help="Show packages for single app" |
| 94 | ) |
| 95 | pkg_app.add_argument( |
| 96 | 'args', |
| 97 | nargs='+', |
| 98 | help="List of app's packages (or 'source' in package description)" |
| 99 | ) |
Alex | 74dc135 | 2019-05-17 13:18:24 -0500 | [diff] [blame] | 100 | |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 101 | return _parser |
| 102 | |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 103 | |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 104 | def do_report(args, config): |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 105 | """Create package versions report, HTML |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 106 | |
| 107 | :args: - parser arguments |
| 108 | :return: - no return value |
| 109 | """ |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 110 | # Check if there is supported env found |
| 111 | _env = args_utils.check_supported_env( |
| 112 | [ENV_TYPE_SALT, ENV_TYPE_KUBE], |
| 113 | args, |
| 114 | config |
| 115 | ) |
| 116 | # Start command |
Alex | bab1efe | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 117 | _type, _filename = args_utils.get_package_report_type_and_filename(args) |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 118 | |
Alex | e9547d8 | 2019-06-03 15:22:50 -0500 | [diff] [blame] | 119 | if ' ' in args.exclude_keywords: |
| 120 | _kw = args.exclude_keywords.split(' ') |
| 121 | else: |
| 122 | _kw = [args.exclude_keywords] |
| 123 | |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 124 | # init connection to salt and collect minion data |
Alex | e9908f7 | 2020-05-19 16:04:53 -0500 | [diff] [blame] | 125 | _skip, _skip_file = args_utils.get_skip_args(args) |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 126 | if _env == ENV_TYPE_SALT: |
| 127 | pChecker = checker.SaltCloudPackageChecker( |
| 128 | config, |
| 129 | force_tag=args.force_tag, |
| 130 | exclude_keywords=_kw, |
| 131 | skip_list=_skip, |
| 132 | skip_list_file=_skip_file |
| 133 | ) |
| 134 | elif _env == ENV_TYPE_KUBE: |
| 135 | pChecker = checker.KubeCloudPackageChecker( |
| 136 | config, |
| 137 | force_tag=args.force_tag, |
| 138 | exclude_keywords=_kw, |
| 139 | skip_list=_skip, |
| 140 | skip_list_file=_skip_file |
| 141 | ) |
| 142 | |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 143 | # collect data on installed packages |
| 144 | pChecker.collect_installed_packages() |
| 145 | # diff installed and candidates |
Alex Savatieiev | 3db12a7 | 2019-03-22 16:32:31 -0500 | [diff] [blame] | 146 | pChecker.collect_packages() |
Alex Savatieiev | c905571 | 2019-03-01 14:43:56 -0600 | [diff] [blame] | 147 | # report it |
Alex | 4148552 | 2019-04-12 17:26:18 -0500 | [diff] [blame] | 148 | pChecker.create_report(_filename, rtype=_type, full=args.full) |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 149 | |
| 150 | |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 151 | def do_versions(args, config): |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 152 | """Builds tagged repo structure and parses Packages.gz files |
| 153 | |
| 154 | :args: - parser arguments |
| 155 | :return: - no return value |
| 156 | """ |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 157 | # Check if there is supported env found |
| 158 | args_utils.check_supported_env(ENV_TYPE_LINUX, args, config) |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 159 | # Get the list of tags for the url |
| 160 | r = RepoManager() |
Alex | 74dc135 | 2019-05-17 13:18:24 -0500 | [diff] [blame] | 161 | if args.list_tags: |
| 162 | r.action_for_tag(args.url, args.tag, action="list") |
| 163 | return |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 164 | if args.build_repos: |
| 165 | # if tag is supplied, use it |
| 166 | if args.tag: |
| 167 | r.action_for_tag(args.url, args.tag, action="build") |
| 168 | else: |
| 169 | r.build_repos(args.url) |
| 170 | |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 171 | if args.tag: |
| 172 | # Process only this tag |
| 173 | r.action_for_tag( |
| 174 | args.url, |
| 175 | args.tag, |
| 176 | action="fetch", |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 177 | descriptions=args.gen_desc, |
| 178 | apps=args.gen_apps |
Alex | d9fd85e | 2019-05-16 16:58:24 -0500 | [diff] [blame] | 179 | ) |
| 180 | else: |
| 181 | # All of them |
| 182 | r.parse_repos() |
Alex | 74dc135 | 2019-05-17 13:18:24 -0500 | [diff] [blame] | 183 | |
| 184 | |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 185 | def do_show(args, config): |
Alex | 74dc135 | 2019-05-17 13:18:24 -0500 | [diff] [blame] | 186 | """Shows package (or multiple) history across parsed tags |
| 187 | """ |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 188 | # Check if there is supported env found |
| 189 | args_utils.check_supported_env(ENV_TYPE_LINUX, args, config) |
Alex | 74dc135 | 2019-05-17 13:18:24 -0500 | [diff] [blame] | 190 | # Init manager |
| 191 | r = RepoManager() |
| 192 | # show packages |
| 193 | for p in args.args: |
| 194 | r.show_package(p) |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 195 | |
| 196 | |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 197 | def do_show_app(args, config): |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 198 | """Shows packages for app |
| 199 | """ |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame^] | 200 | # Check if there is supported env found |
| 201 | args_utils.check_supported_env(ENV_TYPE_LINUX, args, config) |
Alex | d0391d4 | 2019-05-21 18:48:55 -0500 | [diff] [blame] | 202 | # Init manager |
| 203 | r = RepoManager() |
| 204 | # show packages |
| 205 | for a in args.args: |
| 206 | r.show_app(a) |