Alex | dcb792f | 2021-10-04 14:24:21 -0500 | [diff] [blame^] | 1 | from cfg_checker.common import logger_cli |
| 2 | from cfg_checker.common.settings import ENV_TYPE_KUBE |
| 3 | from cfg_checker.helpers import args_utils |
| 4 | from cfg_checker.modules.ceph import info, bench |
| 5 | |
| 6 | command_help = "Ceph Storage information and benchmarks" |
| 7 | supported_envs = [ENV_TYPE_KUBE] |
| 8 | |
| 9 | |
| 10 | # def _selectClass(_env, strClassHint="checker"): |
| 11 | # _class = None |
| 12 | # if _env == ENV_TYPE_SALT: |
| 13 | # if strClassHint == "info": |
| 14 | # _class = info.SaltCephInfo |
| 15 | # elif strClassHint == "bench": |
| 16 | # _class = bench.SaltCephInfo |
| 17 | # elif _env == ENV_TYPE_KUBE: |
| 18 | # if strClassHint == "info": |
| 19 | # _class = info.KubeCephInfo |
| 20 | # elif strClassHint == "bench": |
| 21 | # _class = bench.KubeCephBench |
| 22 | # if not _class: |
| 23 | # raise CheckerException( |
| 24 | # "Unknown hint for selecting Ceph handler Class: '{}'".format( |
| 25 | # strClassHint |
| 26 | # ) |
| 27 | # ) |
| 28 | # else: |
| 29 | # return _class |
| 30 | |
| 31 | |
| 32 | def init_parser(_parser): |
| 33 | # network subparser |
| 34 | ceph_subparsers = _parser.add_subparsers(dest='type') |
| 35 | |
| 36 | ceph_info_parser = ceph_subparsers.add_parser( |
| 37 | 'info', |
| 38 | help="Gather Ceph Cluster information" |
| 39 | ) |
| 40 | |
| 41 | ceph_info_parser.add_argument( |
| 42 | '--detailed', |
| 43 | action="store_true", default=False, |
| 44 | help="Print additional details" |
| 45 | ) |
| 46 | |
| 47 | ceph_info_parser.add_argument( |
| 48 | '--tgz', |
| 49 | metavar='ceph_tgz_filename', |
| 50 | help="HTML filename to save report" |
| 51 | ) |
| 52 | |
| 53 | ceph_report_parser = ceph_subparsers.add_parser( |
| 54 | 'report', |
| 55 | help="Generate network check report" |
| 56 | ) |
| 57 | |
| 58 | ceph_report_parser.add_argument( |
| 59 | '--html', |
| 60 | metavar='ceph_html_filename', |
| 61 | help="HTML filename to save report" |
| 62 | ) |
| 63 | |
| 64 | ceph_bench_parser = ceph_subparsers.add_parser( |
| 65 | 'bench', |
| 66 | help="Run ceph benchmark" |
| 67 | ) |
| 68 | |
| 69 | ceph_bench_parser.add_argument( |
| 70 | '--task-list', |
| 71 | metavar='ceph_tasks_filename', |
| 72 | help="List file with data for Ceph bench testrun" |
| 73 | ) |
| 74 | |
| 75 | return _parser |
| 76 | |
| 77 | |
| 78 | def do_info(args, config): |
| 79 | # Ceph info |
| 80 | # Gather ceph info and create an archive with data |
| 81 | args_utils.check_supported_env(ENV_TYPE_KUBE, args, config) |
| 82 | # check tgz |
| 83 | _tgzfile = "ceph_info_archive.tgz" if not args.tgz else args.tgz |
| 84 | |
| 85 | # _class = _selectClass(_env) |
| 86 | ceph_info = info.KubeCephInfo(config) |
| 87 | |
| 88 | logger_cli.info("# Collecting Ceph cluster information") |
| 89 | logger_cli.warning( |
| 90 | "\nWARNING: 'ceph info' has 'Work in progress' status!\n" |
| 91 | ) |
| 92 | |
| 93 | ceph_info.gather_info() |
| 94 | |
| 95 | # Debug, enable if needed to debug report generation |
| 96 | # without actuall data collecting each time |
| 97 | # ceph_info.dump_info() |
| 98 | # ceph_info.load_info() |
| 99 | # end debug |
| 100 | |
| 101 | ceph_info.print_summary() |
| 102 | ceph_info.generate_archive(_tgzfile) |
| 103 | |
| 104 | return |
| 105 | |
| 106 | |
| 107 | def do_report(args, config): |
| 108 | # Ceph Report |
| 109 | # Gather ceph info and create HTML report with all of the data |
| 110 | args_utils.check_supported_env(ENV_TYPE_KUBE, args, config) |
| 111 | _filename = args_utils.get_arg(args, 'html') |
| 112 | logger_cli.info("# Ceph cluster Configuration report") |
| 113 | logger_cli.warning( |
| 114 | "\nWARNING: 'ceph info' has 'Work in progress' status!\n" |
| 115 | ) |
| 116 | |
| 117 | # _class = _selectClass(_env) |
| 118 | ceph_info = info.KubeCephInfo(config) |
| 119 | # Debug, enable if needed to debug report generation |
| 120 | # without actuall data collecting each time |
| 121 | # ceph_info.load_info() |
| 122 | # end debug |
| 123 | ceph_info.gather_info() |
| 124 | ceph_info.get_transposed_latency_table() |
| 125 | ceph_info.get_latest_health_readout() |
| 126 | ceph_info.create_html_report(_filename) |
| 127 | |
| 128 | return |
| 129 | |
| 130 | |
| 131 | def do_bench(args, config): |
| 132 | # Ceph Benchmark using multiple pods |
| 133 | # Prepare the tasks and do synced testrun |
| 134 | # TODO: html option to create a fancy report |
| 135 | args_utils.check_supported_env(ENV_TYPE_KUBE, args, config) |
| 136 | |
| 137 | ceph_bench = bench.KubeCephBench(config) |
| 138 | |
| 139 | logger_cli.error("ERROR: To be implemented...") |
| 140 | |
| 141 | # Load tasks |
| 142 | |
| 143 | # Do the testrun |
| 144 | ceph_bench.prepare_pods() |
| 145 | ceph_bench.run_benchmark() |
| 146 | |
| 147 | # Create report |
| 148 | ceph_bench.create_report() |
| 149 | |
| 150 | return |