blob: d3f958109605c11d29d58744a3dae714f1ccc878 [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',
92 metavar='task-file',
93 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 )
Alexdcb792f2021-10-04 14:24:21 -0500100
101 return _parser
102
103
104def 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")
Alexdcb792f2021-10-04 14:24:21 -0500115 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
Alexdcb792f2021-10-04 14:24:21 -0500123 ceph_info.generate_archive(_tgzfile)
Alexdf9cc3a2021-10-12 14:37:28 -0500124 ceph_info.print_summary()
Alexdcb792f2021-10-04 14:24:21 -0500125
126 return
127
128
129def 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")
Alexdcb792f2021-10-04 14:24:21 -0500135
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
150def do_bench(args, config):
151 # Ceph Benchmark using multiple pods
Alex5cace3b2021-11-10 16:40:37 -0600152 # Prepare the tasks and do synced testrun or a single one
153 logger_cli.info("# Initializing benchmark run")
Alexdcb792f2021-10-04 14:24:21 -0500154 args_utils.check_supported_env(ENV_TYPE_KUBE, args, config)
Alex5cace3b2021-11-10 16:40:37 -0600155 _filename = args_utils.get_arg(args, 'html')
156 # agents count option
Alex2a7657c2021-11-10 20:51:34 -0600157 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")
Alex5cace3b2021-11-10 16:40:37 -0600160 # 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]))
Alexdcb792f2021-10-04 14:24:21 -0500178
Alex5cace3b2021-11-10 16:40:37 -0600179 # handle option inavailability
Alexdcb792f2021-10-04 14:24:21 -0500180 ceph_bench = bench.KubeCephBench(config)
181
Alexdcb792f2021-10-04 14:24:21 -0500182 # Load tasks
183
184 # Do the testrun
Alex5cace3b2021-11-10 16:40:37 -0600185 ceph_bench.prepare_agents(_opts)
186 if not ceph_bench.run_benchmark(_opts):
Alex2a7657c2021-11-10 20:51:34 -0600187 # No cleaning and/or report if benchmark was not finished
Alex5cace3b2021-11-10 16:40:37 -0600188 return
Alex2a7657c2021-11-10 20:51:34 -0600189 if not config.no_cleaning_after_benchmark:
190 ceph_bench.cleanup()
Alexdcb792f2021-10-04 14:24:21 -0500191
192 # Create report
Alex5cace3b2021-11-10 16:40:37 -0600193 ceph_bench.create_report(_filename)
Alexdcb792f2021-10-04 14:24:21 -0500194
195 return