Skip to content

Commit fbbc8b7

Browse files
committed
test for pre-pulling on hot buffers
1 parent 8dc6c03 commit fbbc8b7

File tree

3 files changed

+56
-26
lines changed

3 files changed

+56
-26
lines changed

packages/pytest-simcore/src/pytest_simcore/helpers/aws_ec2.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import base64
22
from collections.abc import Sequence
33

4-
from common_library.json_serialization import json_dumps
4+
from common_library.json_serialization import json_loads
55
from models_library.docker import DockerGenericTag
66
from types_aiobotocore_ec2 import EC2Client
77
from types_aiobotocore_ec2.literals import InstanceStateNameType, InstanceTypeType
@@ -46,6 +46,7 @@ async def assert_autoscaled_dynamic_ec2_instances(
4646
expected_instance_type: InstanceTypeType,
4747
expected_instance_state: InstanceStateNameType,
4848
expected_additional_tag_keys: list[str],
49+
expected_pre_pulled_images: list[DockerGenericTag] | None = None,
4950
instance_filters: Sequence[FilterTypeDef] | None,
5051
expected_user_data: list[str] | None = None,
5152
check_reservation_index: int | None = None,
@@ -64,6 +65,7 @@ async def assert_autoscaled_dynamic_ec2_instances(
6465
*expected_additional_tag_keys,
6566
],
6667
expected_user_data=expected_user_data,
68+
expected_pre_pulled_images=expected_pre_pulled_images,
6769
instance_filters=instance_filters,
6870
check_reservation_index=check_reservation_index,
6971
)
@@ -143,8 +145,8 @@ def _by_pre_pull_image(ec2_tag: TagTypeDef) -> bool:
143145
)
144146
assert "Value" in instance_pre_pulled_images_aws_tag
145147
assert (
146-
instance_pre_pulled_images_aws_tag["Value"]
147-
== f"{json_dumps(expected_pre_pulled_images)}"
148+
json_loads(instance_pre_pulled_images_aws_tag["Value"]).sort()
149+
== expected_pre_pulled_images.sort()
148150
)
149151

150152
assert "PrivateDnsName" in instance

services/autoscaling/src/simcore_service_autoscaling/core/application.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from common_library.json_serialization import json_dumps
34
from fastapi import FastAPI
45
from servicelib.fastapi.tracing import (
56
initialize_fastapi_app_tracing,
@@ -32,7 +33,7 @@
3233
from ..modules.ssm import setup as setup_ssm
3334
from .settings import ApplicationSettings
3435

35-
logger = logging.getLogger(__name__)
36+
_logger = logging.getLogger(__name__)
3637

3738

3839
def create_app(settings: ApplicationSettings, tracing_config: TracingConfig) -> FastAPI:
@@ -49,6 +50,10 @@ def create_app(settings: ApplicationSettings, tracing_config: TracingConfig) ->
4950
app.state.settings = settings
5051
app.state.tracing_config = tracing_config
5152
assert app.state.settings.API_VERSION == API_VERSION # nosec
53+
_logger.info(
54+
"Application settings: %s",
55+
json_dumps(settings, indent=2, sort_keys=True),
56+
)
5257

5358
# PLUGINS SETUP
5459
if tracing_config.tracing_enabled:

services/autoscaling/tests/unit/test_modules_cluster_scaling_dynamic.py

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@
5454
)
5555
from pytest_simcore.helpers.logging_tools import log_context
5656
from 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+
)
5863
from simcore_service_autoscaling.core.settings import ApplicationSettings
5964
from simcore_service_autoscaling.models import AssociatedInstance, Cluster
6065
from 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

Comments
 (0)