@@ -257,6 +257,21 @@ def parse_env(envs):
257257 return env_dict
258258
259259
260+ def parse_regionwise_loadtest_config (regionwise_loadtest_config ):
261+ logger .debug ("Parsing regionwise load test configuration" )
262+ regional_load_test_config = []
263+ for region_load in regionwise_loadtest_config :
264+ region_name = region_load .get ("region" )
265+ if region_name is None or not isinstance (region_name , str ):
266+ raise RequiredArgumentMissingError ("Region name is required of type string" )
267+ engine_instances = region_load .get ("engineInstances" )
268+ if engine_instances is None or not isinstance (engine_instances , int ):
269+ raise InvalidArgumentValueError ("Engine instances is required of type integer" )
270+ regional_load_test_config .append ({"region" : region_name .lower (), "engineInstances" : engine_instances })
271+ logger .debug ("Successfully parsed regionwise load test configuration: %s" , regional_load_test_config )
272+ return regional_load_test_config
273+
274+
260275def create_autostop_criteria_from_args (autostop , error_rate , time_window ):
261276 if (autostop is None and error_rate is None and time_window is None ):
262277 return None
@@ -304,9 +319,12 @@ def convert_yaml_to_test(data):
304319 new_body ["subnetId" ] = data ["subnetId" ]
305320
306321 new_body ["loadTestConfiguration" ] = {}
307- new_body ["loadTestConfiguration" ]["engineInstances" ] = data .get (
308- "engineInstances" , 1
309- )
322+ new_body ["loadTestConfiguration" ]["engineInstances" ] = data .get ("engineInstances" )
323+ if data .get ("regionalLoadTestConfig" ) is not None :
324+ new_body ["loadTestConfiguration" ]["regionalLoadTestConfig" ] = parse_regionwise_loadtest_config (
325+ data .get ("regionalLoadTestConfig" )
326+ )
327+
310328 if data .get ("certificates" ):
311329 new_body ["certificate" ] = parse_cert (data .get ("certificates" ))
312330 if data .get ("secrets" ):
@@ -399,6 +417,7 @@ def create_or_update_test_with_config(
399417 split_csv = None ,
400418 disable_public_ip = None ,
401419 autostop_criteria = None ,
420+ regionwise_engines = None ,
402421):
403422 logger .info (
404423 "Creating a request body for create or update test using config and parameters."
@@ -480,7 +499,25 @@ def create_or_update_test_with_config(
480499 "loadTestConfiguration"
481500 ]["engineInstances" ]
482501 else :
483- new_body ["loadTestConfiguration" ]["engineInstances" ] = 1
502+ new_body ["loadTestConfiguration" ]["engineInstances" ] = body .get (
503+ "loadTestConfiguration" , {}
504+ ).get ("engineInstances" , 1 )
505+ if regionwise_engines :
506+ new_body ["loadTestConfiguration" ]["regionalLoadTestConfig" ] = regionwise_engines
507+ elif (
508+ yaml_test_body .get ("loadTestConfiguration" , {}).get ("regionalLoadTestConfig" )
509+ is not None
510+ ):
511+ new_body ["loadTestConfiguration" ]["regionalLoadTestConfig" ] = yaml_test_body [
512+ "loadTestConfiguration"
513+ ]["regionalLoadTestConfig" ]
514+ else :
515+ new_body ["loadTestConfiguration" ]["regionalLoadTestConfig" ] = body .get (
516+ "loadTestConfiguration" , {}
517+ ).get ("regionalLoadTestConfig" )
518+ validate_engine_data_with_regionwiseload_data (
519+ new_body ["loadTestConfiguration" ]["engineInstances" ],
520+ new_body ["loadTestConfiguration" ]["regionalLoadTestConfig" ])
484521 # quick test is not supported in CLI
485522 new_body ["loadTestConfiguration" ]["quickStartTest" ] = False
486523
@@ -554,6 +591,7 @@ def create_or_update_test_without_config(
554591 split_csv = None ,
555592 disable_public_ip = None ,
556593 autostop_criteria = None ,
594+ regionwise_engines = None ,
557595):
558596 logger .info (
559597 "Creating a request body for test using parameters and old test body (in case of update)."
@@ -610,6 +648,15 @@ def create_or_update_test_without_config(
610648 new_body ["loadTestConfiguration" ]["engineInstances" ] = body .get (
611649 "loadTestConfiguration" , {}
612650 ).get ("engineInstances" , 1 )
651+ if regionwise_engines :
652+ new_body ["loadTestConfiguration" ]["regionalLoadTestConfig" ] = regionwise_engines
653+ else :
654+ new_body ["loadTestConfiguration" ]["regionalLoadTestConfig" ] = body .get (
655+ "loadTestConfiguration" , {}
656+ ).get ("regionalLoadTestConfig" )
657+ validate_engine_data_with_regionwiseload_data (
658+ new_body ["loadTestConfiguration" ]["engineInstances" ],
659+ new_body ["loadTestConfiguration" ]["regionalLoadTestConfig" ])
613660 # quick test is not supported in CLI
614661 new_body ["loadTestConfiguration" ]["quickStartTest" ] = False
615662 if split_csv is not None :
@@ -804,6 +851,19 @@ def upload_files_helper(
804851 load_test_config_file = load_test_config_file , existing_test_files = files , wait = wait )
805852
806853
854+ def validate_engine_data_with_regionwiseload_data (engine_instances , regionwise_engines ):
855+ if regionwise_engines is None :
856+ return
857+ total_engines = 0
858+ for region in regionwise_engines :
859+ total_engines += region ["engineInstances" ]
860+ if total_engines != engine_instances :
861+ raise InvalidArgumentValueError (
862+ f"Sum of engine instances in regionwise load test configuration ({ total_engines } ) "
863+ f"should be equal to total engine instances ({ engine_instances } )"
864+ )
865+
866+
807867def validate_failure_criteria (failure_criteria ):
808868 parts = failure_criteria .split ("(" )
809869 if len (parts ) != 2 :
0 commit comments