@@ -342,6 +342,30 @@ async def test_cluster_scaling_with_no_services_does_nothing(
342342 )
343343
344344
345+ @pytest .fixture
346+ def hot_buffer_has_pre_pull (
347+ app_settings : ApplicationSettings ,
348+ hot_buffer_instance_type : InstanceTypeType ,
349+ ) -> bool :
350+ assert app_settings .AUTOSCALING_EC2_INSTANCES
351+ return bool (
352+ app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_ALLOWED_TYPES [
353+ hot_buffer_instance_type
354+ ].pre_pull_images
355+ )
356+
357+
358+ @pytest .fixture
359+ def hot_buffer_expected_pre_pulled_images (
360+ app_settings : ApplicationSettings ,
361+ hot_buffer_instance_type : InstanceTypeType ,
362+ ) -> list [DockerGenericTag ]:
363+ assert app_settings .AUTOSCALING_EC2_INSTANCES
364+ return app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_ALLOWED_TYPES [
365+ hot_buffer_instance_type
366+ ].pre_pull_images
367+
368+
345369@pytest .mark .parametrize (
346370 # NOTE: only the main test test_cluster_scaling_up_and_down is run with all options
347371 "with_docker_join_drained" ,
@@ -369,11 +393,10 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
369393 ec2_client : EC2Client ,
370394 ec2_instance_custom_tags : dict [str , str ],
371395 instance_type_filters : Sequence [FilterTypeDef ],
396+ hot_buffer_instance_type : InstanceTypeType ,
397+ hot_buffer_has_pre_pull : bool ,
398+ hot_buffer_expected_pre_pulled_images : list [DockerGenericTag ],
372399):
373- hot_buffer_instance_type = cast (
374- InstanceTypeType ,
375- next (iter (app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_ALLOWED_TYPES )),
376- )
377400 assert app_settings .AUTOSCALING_EC2_INSTANCES
378401 await auto_scale_cluster (
379402 app = initialized_app , auto_scaling_mode = DynamicAutoscalingProvider ()
@@ -396,11 +419,6 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
396419 mock_rabbitmq_post_message .reset_mock ()
397420 # calling again should attach the new nodes to the reserve, but nothing should start
398421 # it will also trigger pre-pulling of images if there is pre-pulling
399- hot_buffer_has_pre_pull = bool (
400- app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_ALLOWED_TYPES [
401- hot_buffer_instance_type
402- ].pre_pull_images
403- )
404422 expected_pre_pull_tag_keys = (
405423 [
406424 MACHINE_PULLING_COMMAND_ID_EC2_TAG_KEY ,
@@ -422,9 +440,7 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
422440 expected_additional_tag_keys = list (
423441 ec2_instance_custom_tags .keys () | expected_pre_pull_tag_keys
424442 ),
425- expected_pre_pulled_images = app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_ALLOWED_TYPES [
426- hot_buffer_instance_type
427- ].pre_pull_images ,
443+ expected_pre_pulled_images = hot_buffer_expected_pre_pulled_images ,
428444 instance_filters = instance_type_filters ,
429445 )
430446 assert fake_node .description
@@ -464,10 +480,7 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
464480 expected_additional_tag_keys = list (
465481 ec2_instance_custom_tags .keys () | expected_pre_pull_tag_keys
466482 ),
467- expected_pre_pulled_images = app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_ALLOWED_TYPES [
468- hot_buffer_instance_type
469- ].pre_pull_images
470- or None ,
483+ expected_pre_pulled_images = hot_buffer_expected_pre_pulled_images or None ,
471484 instance_filters = instance_type_filters ,
472485 )
473486
@@ -2124,6 +2137,8 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
21242137 ],
21252138 create_services_batch : Callable [[_ScaleUpParams ], Awaitable [list [Service ]]],
21262139 hot_buffer_instance_type : InstanceTypeType ,
2140+ hot_buffer_has_pre_pull : bool ,
2141+ hot_buffer_expected_pre_pulled_images : list [DockerGenericTag ],
21272142 spied_cluster_analysis : MockType ,
21282143 instance_type_filters : Sequence [FilterTypeDef ],
21292144 stopped_instance_type_filters : Sequence [FilterTypeDef ],
@@ -2161,7 +2176,7 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
21612176 expected_additional_tag_keys = list (ec2_instance_custom_tags ),
21622177 instance_filters = instance_type_filters ,
21632178 )
2164- # this brings a new analysis
2179+ # this brings a new analysis and will start pre-pulling images
21652180 await auto_scale_cluster (
21662181 app = initialized_app , auto_scaling_mode = DynamicAutoscalingProvider ()
21672182 )
@@ -2204,14 +2219,21 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
22042219 return_value = fake_hot_buffer_nodes ,
22052220 )
22062221
2222+ # there we are done pre-pulling images
22072223 await auto_scale_cluster (app = initialized_app , auto_scaling_mode = auto_scaling_mode )
2224+ expected_pre_pull_tag_keys = (
2225+ [PRE_PULLED_IMAGES_EC2_TAG_KEY ] if hot_buffer_has_pre_pull else []
2226+ )
22082227 await assert_autoscaled_dynamic_ec2_instances (
22092228 ec2_client ,
22102229 expected_num_reservations = 1 ,
22112230 expected_num_instances = num_hot_buffer ,
22122231 expected_instance_type = hot_buffer_instance_type ,
22132232 expected_instance_state = "running" ,
2214- expected_additional_tag_keys = list (ec2_instance_custom_tags ),
2233+ expected_additional_tag_keys = list (
2234+ ec2_instance_custom_tags .keys () | expected_pre_pull_tag_keys
2235+ ),
2236+ expected_pre_pulled_images = hot_buffer_expected_pre_pulled_images or None ,
22152237 instance_filters = instance_type_filters ,
22162238 )
22172239 spied_cluster = assert_cluster_state (
@@ -2246,7 +2268,10 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
22462268 expected_num_instances = num_hot_buffer ,
22472269 expected_instance_type = hot_buffer_instance_type ,
22482270 expected_instance_state = "running" ,
2249- expected_additional_tag_keys = list (ec2_instance_custom_tags ),
2271+ expected_additional_tag_keys = list (
2272+ ec2_instance_custom_tags .keys () | expected_pre_pull_tag_keys
2273+ ),
2274+ expected_pre_pulled_images = hot_buffer_expected_pre_pulled_images or None ,
22502275 instance_filters = instance_type_filters ,
22512276 )
22522277 await assert_autoscaled_dynamic_warm_pools_ec2_instances (
@@ -2292,7 +2317,10 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
22922317 expected_num_instances = num_hot_buffer ,
22932318 expected_instance_type = hot_buffer_instance_type ,
22942319 expected_instance_state = "running" ,
2295- expected_additional_tag_keys = list (ec2_instance_custom_tags ),
2320+ expected_additional_tag_keys = list (
2321+ ec2_instance_custom_tags .keys () | expected_pre_pull_tag_keys
2322+ ),
2323+ expected_pre_pulled_images = hot_buffer_expected_pre_pulled_images or None ,
22962324 instance_filters = instance_type_filters ,
22972325 )
22982326 await assert_autoscaled_dynamic_warm_pools_ec2_instances (
0 commit comments