blob: f9bf3ca943239c0670b6ef645ab6b23429ff2705 [file] [log] [blame]
Alex5cace3b2021-11-10 16:40:37 -06001from cfg_checker.agent.fio_runner import get_fio_options
Alexdcb792f2021-10-04 14:24:21 -05002from cfg_checker.common import logger_cli
3from cfg_checker.common.settings import ENV_TYPE_KUBE
4from cfg_checker.helpers import args_utils
5from cfg_checker.modules.ceph import info, bench
6
7command_help = "Ceph Storage information and benchmarks"
8supported_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
33def 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 )
Alex5cace3b2021-11-10 16:40:37 -060075 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',
Alexb2129542021-11-23 15:49:42 -060092 metavar='task_file',
Alex5cace3b2021-11-10 16:40:37 -060093 help="Task file for benchmark"
94 )
Alex2a7657c2021-11-10 20:51:34 -060095 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 )
Alexb2129542021-11-23 15:49:42 -0600100 ceph_bench_parser.add_argument(
101 '--cleanup-only',
102 action="store_true", default=False,
103 help="Cleanup resources related to benchmark"
104 )
105 ceph_bench_parser.add_argument(
106 '--dump-path',
107 metavar="dump_results", default="/tmp",
108 help="Dump result after each test run to use them later"
109 )
Alexdcb792f2021-10-04 14:24:21 -0500110
111 return _parser
112
113
114def do_info(args, config):
115 # Ceph info
116 # Gather ceph info and create an archive with data
117 args_utils.check_supported_env(ENV_TYPE_KUBE, args, config)
118 # check tgz
119 _tgzfile = "ceph_info_archive.tgz" if not args.tgz else args.tgz
120
121 # _class = _selectClass(_env)
122 ceph_info = info.KubeCephInfo(config)
123
124 logger_cli.info("# Collecting Ceph cluster information")
Alexdcb792f2021-10-04 14:24:21 -0500125 ceph_info.gather_info()
126
127 # Debug, enable if needed to debug report generation
128 # without actuall data collecting each time
129 # ceph_info.dump_info()
130 # ceph_info.load_info()
131 # end debug
132
Alexdcb792f2021-10-04 14:24:21 -0500133 ceph_info.generate_archive(_tgzfile)
Alexdf9cc3a2021-10-12 14:37:28 -0500134 ceph_info.print_summary()
Alexdcb792f2021-10-04 14:24:21 -0500135
136 return
137
138
139def do_report(args, config):
140 # Ceph Report
141 # Gather ceph info and create HTML report with all of the data
142 args_utils.check_supported_env(ENV_TYPE_KUBE, args, config)
143 _filename = args_utils.get_arg(args, 'html')
144 logger_cli.info("# Ceph cluster Configuration report")
Alexdcb792f2021-10-04 14:24:21 -0500145
146 # _class = _selectClass(_env)
147 ceph_info = info.KubeCephInfo(config)
148 # Debug, enable if needed to debug report generation
149 # without actuall data collecting each time
150 # ceph_info.load_info()
151 # end debug
152 ceph_info.gather_info()
153 ceph_info.get_transposed_latency_table()
154 ceph_info.get_latest_health_readout()
155 ceph_info.create_html_report(_filename)
156
157 return
158
159
160def do_bench(args, config):
161 # Ceph Benchmark using multiple pods
Alexb2129542021-11-23 15:49:42 -0600162 # if only cleanup needed do it and exit
163 _cleanup_only = args_utils.get_arg(args, 'cleanup_only')
164 config.resource_prefix = "cfgagent"
165 if _cleanup_only:
166 # Do forced resource cleanup and exit
167 config.bench_mode = "cleanup"
168 config.bench_agent_count = -1
169 ceph_bench = bench.KubeCephBench(config)
170 logger_cli.info(
171 "# Discovering benchmark resources using prefix of '{}'".format(
172 config.resource_prefix
173 )
174 )
175 ceph_bench.prepare_cleanup()
176 ceph_bench.cleanup()
177 return
178
179 # gather Ceph info
180 logger_cli.info("# Collecting Ceph cluster information")
181 ceph_info = info.KubeCephInfo(config)
182
Alex5cace3b2021-11-10 16:40:37 -0600183 # Prepare the tasks and do synced testrun or a single one
Alexb2129542021-11-23 15:49:42 -0600184 logger_cli.info("# Initializing ceph benchmark module")
Alexdcb792f2021-10-04 14:24:21 -0500185 args_utils.check_supported_env(ENV_TYPE_KUBE, args, config)
Alex5cace3b2021-11-10 16:40:37 -0600186 _filename = args_utils.get_arg(args, 'html')
187 # agents count option
Alex2a7657c2021-11-10 20:51:34 -0600188 config.bench_agent_count = args_utils.get_arg(args, "agents")
189 logger_cli.info("-> using {} agents".format(config.bench_agent_count))
190 config.no_cleaning_after_benchmark = args_utils.get_arg(args, "no_cleanup")
Alex5cace3b2021-11-10 16:40:37 -0600191 # storage class
192 _storage_class = args_utils.get_arg(args, "storage_class")
193 logger_cli.info("-> using storage class of '{}'".format(_storage_class))
194 config.bench_storage_class = _storage_class
Alexb2129542021-11-23 15:49:42 -0600195 # dump results options
196 _dump_path = args_utils.get_arg(args, "dump_path")
197 if _dump_path:
198 logger_cli.info("# Results will be dumped to '{}'".format(_dump_path))
199 config.bench_results_dump_path = _dump_path
200 else:
201 logger_cli.info(
202 "# No result dump path set. "
203 "Consider setting it if running long task_file based test runs"
204 )
205 config.bench_results_dump_path = _dump_path
Alex5cace3b2021-11-10 16:40:37 -0600206 # Task files or options
207 _task_file = args_utils.get_arg(args, "task_file", nofail=True)
208 if not _task_file:
209 logger_cli.info("-> running single run")
210 config.bench_mode = "single"
211 else:
212 logger_cli.info("-> running with tasks from '{}'".format(_task_file))
213 config.bench_task_file = _task_file
214 config.bench_mode = "tasks"
215 _opts = get_fio_options()
216 logger_cli.debug("... default/selected options for fio:")
217 for _k in _opts.keys():
218 # TODO: Update options for single run
219 logger_cli.debug(" {} = {}".format(_k, _opts[_k]))
Alexdcb792f2021-10-04 14:24:21 -0500220
Alex3034ba52021-11-13 17:06:45 -0600221 # handle option inavailability from command line for single mode
222
223 # init the Bench class
Alexdcb792f2021-10-04 14:24:21 -0500224 ceph_bench = bench.KubeCephBench(config)
Alexb2129542021-11-23 15:49:42 -0600225 ceph_bench.set_ceph_info_class(ceph_info)
Alexdcb792f2021-10-04 14:24:21 -0500226 # Do the testrun
Alex5cace3b2021-11-10 16:40:37 -0600227 ceph_bench.prepare_agents(_opts)
Alexb2129542021-11-23 15:49:42 -0600228 ceph_bench.wait_ceph_cooldown()
229
230 # DEBUG of report in progress
Alex5cace3b2021-11-10 16:40:37 -0600231 if not ceph_bench.run_benchmark(_opts):
Alex2a7657c2021-11-10 20:51:34 -0600232 # No cleaning and/or report if benchmark was not finished
Alexbfa947c2021-11-11 18:14:28 -0600233 logger_cli.info("# Abnormal benchmark run, no cleaning performed")
Alex5cace3b2021-11-10 16:40:37 -0600234 return
Alexb2129542021-11-23 15:49:42 -0600235 # Remove after DEBUG
236 # ceph_bench.collect_results(_opts)
237 # END DEBUG
238
Alex3034ba52021-11-13 17:06:45 -0600239 # Cleaning
Alex2a7657c2021-11-10 20:51:34 -0600240 if not config.no_cleaning_after_benchmark:
241 ceph_bench.cleanup()
Alexbfa947c2021-11-11 18:14:28 -0600242 else:
243 logger_cli.info(
244 "# '--no-cleaning' option set. Cleaning not conducted."
245 )
Alexdcb792f2021-10-04 14:24:21 -0500246
247 # Create report
Alex5cace3b2021-11-10 16:40:37 -0600248 ceph_bench.create_report(_filename)
Alexdcb792f2021-10-04 14:24:21 -0500249
250 return