33import logging
44import os
55import pathlib
6- import shutil
76import sys
87import tempfile
98import traceback
109from pathlib import Path
10+ import shutil
1111
1212import docker
1313import redis
@@ -110,6 +110,11 @@ def main():
110110 exit (1 )
111111
112112 running_platform = args .platform_name
113+ tls_enabled = args .tls
114+ tls_skip_verify = args .tls_skip_verify
115+ tls_cert = args .cert
116+ tls_key = args .key
117+ tls_cacert = args .cacert
113118 docker_client = docker .from_env ()
114119 home = str (Path .home ())
115120 logging .info ("Running the benchmark specs." )
@@ -124,6 +129,11 @@ def main():
124129 testsuite_spec_files ,
125130 {},
126131 running_platform ,
132+ tls_enabled ,
133+ tls_skip_verify ,
134+ tls_cert ,
135+ tls_key ,
136+ tls_cacert ,
127137 )
128138
129139
@@ -134,6 +144,11 @@ def prepare_memtier_benchmark_parameters(
134144 server ,
135145 local_benchmark_output_filename ,
136146 oss_cluster_api_enabled ,
147+ tls_enabled = False ,
148+ tls_skip_verify = False ,
149+ tls_cert = None ,
150+ tls_key = None ,
151+ tls_cacert = None ,
137152):
138153 benchmark_command = [
139154 full_benchmark_path ,
@@ -144,6 +159,17 @@ def prepare_memtier_benchmark_parameters(
144159 "--json-out-file" ,
145160 local_benchmark_output_filename ,
146161 ]
162+ if tls_enabled :
163+ benchmark_command .append ("--tls" )
164+ if tls_cert is not None and tls_cert != "" :
165+ benchmark_command .extend (["--cert" , tls_cert ])
166+ if tls_key is not None and tls_key != "" :
167+ benchmark_command .extend (["--key" , tls_key ])
168+ if tls_cacert is not None and tls_cacert != "" :
169+ benchmark_command .extend (["--cacert" , tls_cacert ])
170+ if tls_skip_verify :
171+ benchmark_command .append ("--tls-skip-verify" )
172+
147173 if oss_cluster_api_enabled is True :
148174 benchmark_command .append ("--cluster-mode" )
149175 benchmark_command_str = " " .join (benchmark_command )
@@ -163,14 +189,29 @@ def process_self_contained_coordinator_stream(
163189 testsuite_spec_files ,
164190 topologies_map ,
165191 running_platform ,
192+ tls_enabled = False ,
193+ tls_skip_verify = False ,
194+ tls_cert = None ,
195+ tls_key = None ,
196+ tls_cacert = None ,
166197):
167198 overall_result = True
168199 total_test_suite_runs = 0
169200 for test_file in testsuite_spec_files :
170201 client_containers = []
171202
172203 with open (test_file , "r" ) as stream :
173- benchmark_config , test_name = get_final_benchmark_config (None , stream , "" )
204+ _ , benchmark_config , test_name = get_final_benchmark_config (
205+ None , stream , ""
206+ )
207+
208+ if tls_enabled :
209+ test_name = test_name + "-tls"
210+ logging .info (
211+ "Given that TLS is enabled, appending -tls to the testname: {}." .format (
212+ test_name
213+ )
214+ )
174215
175216 for topology_spec_name in benchmark_config ["redis-topologies" ]:
176217 test_result = False
@@ -189,8 +230,22 @@ def process_self_contained_coordinator_stream(
189230
190231 port = args .db_server_port
191232 host = args .db_server_host
192- r = redis .StrictRedis (host = host , port = port )
233+
234+ ssl_cert_reqs = "required"
235+ if tls_skip_verify :
236+ ssl_cert_reqs = None
237+ r = redis .StrictRedis (
238+ host = host ,
239+ port = port ,
240+ ssl = tls_enabled ,
241+ ssl_cert_reqs = ssl_cert_reqs ,
242+ ssl_keyfile = tls_key ,
243+ ssl_certfile = tls_cert ,
244+ ssl_ca_certs = tls_cacert ,
245+ ssl_check_hostname = False ,
246+ )
193247 r .ping ()
248+
194249 ceil_client_cpu_limit = extract_client_cpu_limit (benchmark_config )
195250 client_cpuset_cpus , current_cpu_pos = generate_cpuset_cpus (
196251 ceil_client_cpu_limit , current_cpu_pos
@@ -202,6 +257,17 @@ def process_self_contained_coordinator_stream(
202257 benchmark_tool_workdir = client_mnt_point
203258
204259 metadata = {}
260+ if tls_enabled :
261+ metadata ["tls" ] = "true"
262+ if tls_cert is not None and tls_cert != "" :
263+ _ , tls_cert = cp_to_workdir (temporary_dir_client , tls_cert )
264+ if tls_cacert is not None and tls_cacert != "" :
265+ _ , tls_cacert = cp_to_workdir (
266+ temporary_dir_client , tls_cacert
267+ )
268+ if tls_key is not None and tls_key != "" :
269+ _ , tls_key = cp_to_workdir (temporary_dir_client , tls_key )
270+
205271 if "preload_tool" in benchmark_config ["dbconfig" ]:
206272 data_prepopulation_step (
207273 benchmark_config ,
@@ -213,6 +279,11 @@ def process_self_contained_coordinator_stream(
213279 temporary_dir_client ,
214280 test_name ,
215281 host ,
282+ tls_enabled ,
283+ tls_skip_verify ,
284+ tls_cert ,
285+ tls_key ,
286+ tls_cacert ,
216287 )
217288
218289 benchmark_tool = extract_client_tool (benchmark_config )
@@ -263,7 +334,12 @@ def process_self_contained_coordinator_stream(
263334 port ,
264335 host ,
265336 local_benchmark_output_filename ,
266- benchmark_tool_workdir ,
337+ False ,
338+ tls_enabled ,
339+ tls_skip_verify ,
340+ tls_cert ,
341+ tls_key ,
342+ tls_cacert ,
267343 )
268344
269345 client_container_image = extract_client_container_image (
@@ -389,6 +465,18 @@ def process_self_contained_coordinator_stream(
389465 overall_result &= test_result
390466
391467
468+ def cp_to_workdir (benchmark_tool_workdir , srcfile ):
469+ head , filename = os .path .split (srcfile )
470+ dstfile = "{}/{}" .format (benchmark_tool_workdir , filename )
471+ shutil .copyfile (srcfile , dstfile )
472+ logging .info (
473+ "Copying to workdir the following file {}. Final workdir file {}" .format (
474+ srcfile , dstfile
475+ )
476+ )
477+ return dstfile , filename
478+
479+
392480def data_prepopulation_step (
393481 benchmark_config ,
394482 benchmark_tool_workdir ,
@@ -399,6 +487,11 @@ def data_prepopulation_step(
399487 temporary_dir ,
400488 test_name ,
401489 host ,
490+ tls_enabled = False ,
491+ tls_skip_verify = False ,
492+ tls_cert = None ,
493+ tls_key = None ,
494+ tls_cacert = None ,
402495):
403496 # setup the benchmark
404497 (
@@ -426,6 +519,11 @@ def data_prepopulation_step(
426519 host ,
427520 local_benchmark_output_filename ,
428521 False ,
522+ tls_enabled ,
523+ tls_skip_verify ,
524+ tls_cert ,
525+ tls_key ,
526+ tls_cacert ,
429527 )
430528
431529 logging .info (
0 commit comments