5454)
5555from pytest_simcore .helpers .logging_tools import log_context
5656from pytest_simcore .helpers .monkeypatch_envs import EnvVarsDict
57- from simcore_service_autoscaling .constants import BUFFER_MACHINE_TAG_KEY
57+ from simcore_service_autoscaling .constants import (
58+ BUFFER_MACHINE_TAG_KEY ,
59+ MACHINE_PULLING_COMMAND_ID_EC2_TAG_KEY ,
60+ MACHINE_PULLING_EC2_TAG_KEY ,
61+ PRE_PULLED_IMAGES_EC2_TAG_KEY ,
62+ )
5863from simcore_service_autoscaling .core .settings import ApplicationSettings
5964from simcore_service_autoscaling .models import AssociatedInstance , Cluster
6065from simcore_service_autoscaling .modules .cluster_scaling ._auto_scaling_core import (
@@ -365,6 +370,10 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
365370 ec2_instance_custom_tags : dict [str , str ],
366371 instance_type_filters : Sequence [FilterTypeDef ],
367372):
373+ hot_buffer_instance_type = cast (
374+ InstanceTypeType ,
375+ next (iter (app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_ALLOWED_TYPES )),
376+ )
368377 assert app_settings .AUTOSCALING_EC2_INSTANCES
369378 await auto_scale_cluster (
370379 app = initialized_app , auto_scaling_mode = DynamicAutoscalingProvider ()
@@ -373,12 +382,7 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
373382 ec2_client ,
374383 expected_num_reservations = 1 ,
375384 expected_num_instances = app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_MACHINES_BUFFER ,
376- expected_instance_type = cast (
377- InstanceTypeType ,
378- next (
379- iter (app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_ALLOWED_TYPES )
380- ),
381- ),
385+ expected_instance_type = hot_buffer_instance_type ,
382386 expected_instance_state = "running" ,
383387 expected_additional_tag_keys = list (ec2_instance_custom_tags ),
384388 instance_filters = instance_type_filters ,
@@ -391,21 +395,36 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
391395 )
392396 mock_rabbitmq_post_message .reset_mock ()
393397 # calling again should attach the new nodes to the reserve, but nothing should start
398+ # 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+ )
404+ expected_pre_pull_tag_keys = (
405+ [
406+ MACHINE_PULLING_COMMAND_ID_EC2_TAG_KEY ,
407+ MACHINE_PULLING_EC2_TAG_KEY ,
408+ PRE_PULLED_IMAGES_EC2_TAG_KEY ,
409+ ]
410+ if hot_buffer_has_pre_pull
411+ else []
412+ )
394413 await auto_scale_cluster (
395414 app = initialized_app , auto_scaling_mode = DynamicAutoscalingProvider ()
396415 )
397416 await assert_autoscaled_dynamic_ec2_instances (
398417 ec2_client ,
399418 expected_num_reservations = 1 ,
400419 expected_num_instances = app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_MACHINES_BUFFER ,
401- expected_instance_type = cast (
402- InstanceTypeType ,
403- next (
404- iter (app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_ALLOWED_TYPES )
405- ),
406- ),
420+ expected_instance_type = hot_buffer_instance_type ,
407421 expected_instance_state = "running" ,
408- expected_additional_tag_keys = list (ec2_instance_custom_tags ),
422+ expected_additional_tag_keys = list (
423+ ec2_instance_custom_tags .keys () | expected_pre_pull_tag_keys
424+ ),
425+ expected_pre_pulled_images = app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_ALLOWED_TYPES [
426+ hot_buffer_instance_type
427+ ].pre_pull_images ,
409428 instance_filters = instance_type_filters ,
410429 )
411430 assert fake_node .description
@@ -428,7 +447,10 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
428447 },
429448 )
430449
431- # calling it again should not create anything new
450+ # calling it again should not create anything new, pre-pulling should be done
451+ expected_pre_pull_tag_keys = (
452+ [PRE_PULLED_IMAGES_EC2_TAG_KEY ] if hot_buffer_has_pre_pull else []
453+ )
432454 for _ in range (10 ):
433455 await auto_scale_cluster (
434456 app = initialized_app , auto_scaling_mode = DynamicAutoscalingProvider ()
@@ -437,14 +459,15 @@ async def test_cluster_scaling_with_no_services_and_machine_buffer_starts_expect
437459 ec2_client ,
438460 expected_num_reservations = 1 ,
439461 expected_num_instances = app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_MACHINES_BUFFER ,
440- expected_instance_type = cast (
441- InstanceTypeType ,
442- next (
443- iter (app_settings .AUTOSCALING_EC2_INSTANCES .EC2_INSTANCES_ALLOWED_TYPES )
444- ),
445- ),
462+ expected_instance_type = hot_buffer_instance_type ,
446463 expected_instance_state = "running" ,
447- expected_additional_tag_keys = list (ec2_instance_custom_tags ),
464+ expected_additional_tag_keys = list (
465+ ec2_instance_custom_tags .keys () | expected_pre_pull_tag_keys
466+ ),
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 ,
448471 instance_filters = instance_type_filters ,
449472 )
450473
0 commit comments