Skip to content

Commit b173f1b

Browse files
committed
test passes
1 parent 252e674 commit b173f1b

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ async def assert_autoscaled_dynamic_ec2_instances(
4242
expected_instance_state: InstanceStateNameType,
4343
expected_additional_tag_keys: list[str],
4444
instance_filters: Sequence[FilterTypeDef] | None,
45+
expected_user_data: list[str] | None = None,
4546
) -> list[InstanceTypeDef]:
47+
if expected_user_data is None:
48+
expected_user_data = ["docker swarm join"]
4649
return await assert_ec2_instances(
4750
ec2_client,
4851
expected_num_reservations=expected_num_reservations,
@@ -54,7 +57,7 @@ async def assert_autoscaled_dynamic_ec2_instances(
5457
"io.simcore.autoscaling.monitored_services_labels",
5558
*expected_additional_tag_keys,
5659
],
57-
expected_user_data=["docker swarm join"],
60+
expected_user_data=expected_user_data,
5861
instance_filters=instance_filters,
5962
)
6063

services/autoscaling/src/simcore_service_autoscaling/modules/auto_scaling_core.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,34 @@ async def _start_warm_buffer_instances(
424424
"""starts warm buffer if there are assigned tasks, or if a hot buffer of the same type is needed"""
425425

426426
app_settings = get_application_settings(app)
427-
needed_hot_buffers = (
428-
app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER
429-
)
430-
hot_buffer_instance_type = next(
431-
iter(app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_ALLOWED_TYPES)
432-
)
433-
current_hot_buffers = cluster.buffer_drained_nodes
427+
assert app_settings.AUTOSCALING_EC2_INSTANCES # nosec
434428

435429
instances_to_start = [
436430
i.ec2_instance for i in cluster.buffer_ec2s if i.assigned_tasks
437431
]
432+
433+
if (
434+
len(cluster.buffer_drained_nodes)
435+
< app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER
436+
):
437+
# check if we can migrate warm buffers to hot buffers
438+
hot_buffer_instance_type = cast(
439+
InstanceTypeType,
440+
next(
441+
iter(app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_ALLOWED_TYPES)
442+
),
443+
)
444+
free_starteable_warm_buffers_to_replace_hot_buffers = [
445+
warm_buffer.ec2_instance
446+
for warm_buffer in cluster.buffer_ec2s
447+
if (warm_buffer.ec2_instance.type == hot_buffer_instance_type)
448+
and not warm_buffer.assigned_tasks
449+
]
450+
instances_to_start += free_starteable_warm_buffers_to_replace_hot_buffers[
451+
: app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER
452+
- len(cluster.buffer_drained_nodes)
453+
]
454+
438455
if not instances_to_start:
439456
return cluster
440457

services/autoscaling/tests/unit/test_modules_auto_scaling_dynamic.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
)
5151
from pytest_simcore.helpers.logging_tools import log_context
5252
from pytest_simcore.helpers.monkeypatch_envs import EnvVarsDict
53+
from simcore_service_autoscaling.constants import BUFFER_MACHINE_TAG_KEY
5354
from simcore_service_autoscaling.core.settings import ApplicationSettings
5455
from simcore_service_autoscaling.models import AssociatedInstance, Cluster
5556
from simcore_service_autoscaling.modules.auto_scaling_core import (
@@ -1809,6 +1810,7 @@ async def test_warm_buffers_are_started_to_replace_missing_hot_buffers(
18091810
spied_cluster_analysis: MockType,
18101811
instance_type_filters: Sequence[FilterTypeDef],
18111812
mock_find_node_with_name_returns_fake_node: mock.Mock,
1813+
mock_compute_node_used_resources: mock.Mock,
18121814
mock_docker_tag_node: mock.Mock,
18131815
):
18141816
# pre-requisites
@@ -1874,8 +1876,12 @@ async def test_warm_buffers_are_started_to_replace_missing_hot_buffers(
18741876
),
18751877
),
18761878
expected_instance_state="running",
1877-
expected_additional_tag_keys=list(ec2_instance_custom_tags),
1879+
expected_additional_tag_keys=[
1880+
*list(ec2_instance_custom_tags),
1881+
BUFFER_MACHINE_TAG_KEY,
1882+
],
18781883
instance_filters=instance_type_filters,
1884+
expected_user_data=[],
18791885
)
18801886

18811887
# let's autoscale again, to check the cluster analysis and tag the nodes
@@ -1904,6 +1910,6 @@ async def test_warm_buffers_are_started_to_replace_missing_hot_buffers(
19041910
f"found {len(analyzed_cluster.buffer_ec2s)}"
19051911
)
19061912
assert (
1907-
len(analyzed_cluster.buffer_drained_nodes)
1913+
len(analyzed_cluster.pending_ec2s)
19081914
== app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MACHINES_BUFFER
19091915
)

0 commit comments

Comments
 (0)