Alex | 5cace3b | 2021-11-10 16:40:37 -0600 | [diff] [blame] | 1 | from cfg_checker.agent.fio_runner import get_fio_options |
Alex | dcb792f | 2021-10-04 14:24:21 -0500 | [diff] [blame] | 2 | from cfg_checker.common import logger_cli |
| 3 | from cfg_checker.common.settings import ENV_TYPE_KUBE |
| 4 | from cfg_checker.helpers import args_utils |
| 5 | from cfg_checker.modules.ceph import info, bench |
| 6 | |
| 7 | command_help = "Ceph Storage information and benchmarks" |
| 8 | supported_envs = [ENV_TYPE_KUBE] |
| 9 | |
| 10 | |
| 11 | # def _selectClass(_env, strClassHint="checker"): |
| 12 | # _class = None |
| 13 | # if _env == ENV_TYPE_SALT: |
| 14 | # if strClassHint == "info": |
| 15 | # _class = info.SaltCephInfo |
| 16 | # elif strClassHint == "bench": |
| 17 | # _class = bench.SaltCephInfo |
| 18 | # elif _env == ENV_TYPE_KUBE: |
| 19 | # if strClassHint == "info": |
| 20 | # _class = info.KubeCephInfo |
| 21 | # elif strClassHint == "bench": |
| 22 | # _class = bench.KubeCephBench |
| 23 | # if not _class: |
| 24 | # raise CheckerException( |
| 25 | # "Unknown hint for selecting Ceph handler Class: '{}'".format( |
| 26 | # strClassHint |
| 27 | # ) |
| 28 | # ) |
| 29 | # else: |
| 30 | # return _class |
| 31 | |
| 32 | |
| 33 | def init_parser(_parser): |
| 34 | # network subparser |
| 35 | ceph_subparsers = _parser.add_subparsers(dest='type') |
| 36 | |
| 37 | ceph_info_parser = ceph_subparsers.add_parser( |
| 38 | 'info', |
| 39 | help="Gather Ceph Cluster information" |
| 40 | ) |
| 41 | |
| 42 | ceph_info_parser.add_argument( |
| 43 | '--detailed', |
| 44 | action="store_true", default=False, |
| 45 | help="Print additional details" |
| 46 | ) |
| 47 | |
| 48 | ceph_info_parser.add_argument( |
| 49 | '--tgz', |
| 50 | metavar='ceph_tgz_filename', |
| 51 | help="HTML filename to save report" |
| 52 | ) |
| 53 | |
| 54 | ceph_report_parser = ceph_subparsers.add_parser( |
| 55 | 'report', |
| 56 | help="Generate network check report" |
| 57 | ) |
| 58 | |
| 59 | ceph_report_parser.add_argument( |
| 60 | '--html', |
| 61 | metavar='ceph_html_filename', |
| 62 | help="HTML filename to save report" |
| 63 | ) |
| 64 | |
| 65 | ceph_bench_parser = ceph_subparsers.add_parser( |
| 66 | 'bench', |
| 67 | help="Run ceph benchmark" |
| 68 | ) |
| 69 | |
| 70 | ceph_bench_parser.add_argument( |
| 71 | '--task-list', |
| 72 | metavar='ceph_tasks_filename', |
| 73 | help="List file with data for Ceph bench testrun" |
| 74 | ) |
Alex | 5cace3b | 2021-11-10 16:40:37 -0600 | [diff] [blame] | 75 | ceph_bench_parser.add_argument( |
| 76 | '--agents', |
| 77 | type=int, metavar='agent_count', default=5, |
| 78 | help="List file with data for Ceph bench testrun" |
| 79 | ) |
| 80 | ceph_bench_parser.add_argument( |
| 81 | '--html', |
| 82 | metavar='ceph_html_filename', |
| 83 | help="HTML filename to save report" |
| 84 | ) |
| 85 | ceph_bench_parser.add_argument( |
| 86 | '--storage-class', |
| 87 | metavar='storage_class', |
| 88 | help="Storage class to be used in benchmark" |
| 89 | ) |
| 90 | ceph_bench_parser.add_argument( |
| 91 | '--task-file', |
| 92 | metavar='task-file', |
| 93 | help="Task file for benchmark" |
| 94 | ) |
Alex | 2a7657c | 2021-11-10 20:51:34 -0600 | [diff] [blame] | 95 | ceph_bench_parser.add_argument( |
| 96 | '--no-cleanup', |
| 97 | action="store_true", default=False, |
| 98 | help="Do not cleanup services, agents, pvc, and pv" |
| 99 | ) |
Alex | dcb792f | 2021-10-04 14:24:21 -0500 | [diff] [blame] | 100 | |
| 101 | return _parser |
| 102 | |
| 103 | |
| 104 | def do_info(args, config): |
| 105 | # Ceph info |
| 106 | # Gather ceph info and create an archive with data |
| 107 | args_utils.check_supported_env(ENV_TYPE_KUBE, args, config) |
| 108 | # check tgz |
| 109 | _tgzfile = "ceph_info_archive.tgz" if not args.tgz else args.tgz |
| 110 | |
| 111 | # _class = _selectClass(_env) |
| 112 | ceph_info = info.KubeCephInfo(config) |
| 113 | |
| 114 | logger_cli.info("# Collecting Ceph cluster information") |
Alex | dcb792f | 2021-10-04 14:24:21 -0500 | [diff] [blame] | 115 | ceph_info.gather_info() |
| 116 | |
| 117 | # Debug, enable if needed to debug report generation |
| 118 | # without actuall data collecting each time |
| 119 | # ceph_info.dump_info() |
| 120 | # ceph_info.load_info() |
| 121 | # end debug |
| 122 | |
Alex | dcb792f | 2021-10-04 14:24:21 -0500 | [diff] [blame] | 123 | ceph_info.generate_archive(_tgzfile) |
Alex | df9cc3a | 2021-10-12 14:37:28 -0500 | [diff] [blame] | 124 | ceph_info.print_summary() |
Alex | dcb792f | 2021-10-04 14:24:21 -0500 | [diff] [blame] | 125 | |
| 126 | return |
| 127 | |
| 128 | |
| 129 | def do_report(args, config): |
| 130 | # Ceph Report |
| 131 | # Gather ceph info and create HTML report with all of the data |
| 132 | args_utils.check_supported_env(ENV_TYPE_KUBE, args, config) |
| 133 | _filename = args_utils.get_arg(args, 'html') |
| 134 | logger_cli.info("# Ceph cluster Configuration report") |
Alex | dcb792f | 2021-10-04 14:24:21 -0500 | [diff] [blame] | 135 | |
| 136 | # _class = _selectClass(_env) |
| 137 | ceph_info = info.KubeCephInfo(config) |
| 138 | # Debug, enable if needed to debug report generation |
| 139 | # without actuall data collecting each time |
| 140 | # ceph_info.load_info() |
| 141 | # end debug |
| 142 | ceph_info.gather_info() |
| 143 | ceph_info.get_transposed_latency_table() |
| 144 | ceph_info.get_latest_health_readout() |
| 145 | ceph_info.create_html_report(_filename) |
| 146 | |
| 147 | return |
| 148 | |
| 149 | |
| 150 | def do_bench(args, config): |
| 151 | # Ceph Benchmark using multiple pods |
Alex | 5cace3b | 2021-11-10 16:40:37 -0600 | [diff] [blame] | 152 | # Prepare the tasks and do synced testrun or a single one |
| 153 | logger_cli.info("# Initializing benchmark run") |
Alex | dcb792f | 2021-10-04 14:24:21 -0500 | [diff] [blame] | 154 | args_utils.check_supported_env(ENV_TYPE_KUBE, args, config) |
Alex | 5cace3b | 2021-11-10 16:40:37 -0600 | [diff] [blame] | 155 | _filename = args_utils.get_arg(args, 'html') |
| 156 | # agents count option |
Alex | 2a7657c | 2021-11-10 20:51:34 -0600 | [diff] [blame] | 157 | config.bench_agent_count = args_utils.get_arg(args, "agents") |
| 158 | logger_cli.info("-> using {} agents".format(config.bench_agent_count)) |
| 159 | config.no_cleaning_after_benchmark = args_utils.get_arg(args, "no_cleanup") |
Alex | 5cace3b | 2021-11-10 16:40:37 -0600 | [diff] [blame] | 160 | # storage class |
| 161 | _storage_class = args_utils.get_arg(args, "storage_class") |
| 162 | logger_cli.info("-> using storage class of '{}'".format(_storage_class)) |
| 163 | config.bench_storage_class = _storage_class |
| 164 | # Task files or options |
| 165 | _task_file = args_utils.get_arg(args, "task_file", nofail=True) |
| 166 | if not _task_file: |
| 167 | logger_cli.info("-> running single run") |
| 168 | config.bench_mode = "single" |
| 169 | else: |
| 170 | logger_cli.info("-> running with tasks from '{}'".format(_task_file)) |
| 171 | config.bench_task_file = _task_file |
| 172 | config.bench_mode = "tasks" |
| 173 | _opts = get_fio_options() |
| 174 | logger_cli.debug("... default/selected options for fio:") |
| 175 | for _k in _opts.keys(): |
| 176 | # TODO: Update options for single run |
| 177 | logger_cli.debug(" {} = {}".format(_k, _opts[_k])) |
Alex | dcb792f | 2021-10-04 14:24:21 -0500 | [diff] [blame] | 178 | |
Alex | 3034ba5 | 2021-11-13 17:06:45 -0600 | [diff] [blame^] | 179 | # handle option inavailability from command line for single mode |
| 180 | |
| 181 | # init the Bench class |
Alex | dcb792f | 2021-10-04 14:24:21 -0500 | [diff] [blame] | 182 | ceph_bench = bench.KubeCephBench(config) |
Alex | dcb792f | 2021-10-04 14:24:21 -0500 | [diff] [blame] | 183 | # Do the testrun |
Alex | 5cace3b | 2021-11-10 16:40:37 -0600 | [diff] [blame] | 184 | ceph_bench.prepare_agents(_opts) |
| 185 | if not ceph_bench.run_benchmark(_opts): |
Alex | 2a7657c | 2021-11-10 20:51:34 -0600 | [diff] [blame] | 186 | # No cleaning and/or report if benchmark was not finished |
Alex | bfa947c | 2021-11-11 18:14:28 -0600 | [diff] [blame] | 187 | logger_cli.info("# Abnormal benchmark run, no cleaning performed") |
Alex | 5cace3b | 2021-11-10 16:40:37 -0600 | [diff] [blame] | 188 | return |
Alex | 3034ba5 | 2021-11-13 17:06:45 -0600 | [diff] [blame^] | 189 | # Cleaning |
Alex | 2a7657c | 2021-11-10 20:51:34 -0600 | [diff] [blame] | 190 | if not config.no_cleaning_after_benchmark: |
| 191 | ceph_bench.cleanup() |
Alex | bfa947c | 2021-11-11 18:14:28 -0600 | [diff] [blame] | 192 | else: |
| 193 | logger_cli.info( |
| 194 | "# '--no-cleaning' option set. Cleaning not conducted." |
| 195 | ) |
Alex | dcb792f | 2021-10-04 14:24:21 -0500 | [diff] [blame] | 196 | |
| 197 | # Create report |
Alex | 5cace3b | 2021-11-10 16:40:37 -0600 | [diff] [blame] | 198 | ceph_bench.create_report(_filename) |
Alex | dcb792f | 2021-10-04 14:24:21 -0500 | [diff] [blame] | 199 | |
| 200 | return |