Skip to content

Commit 1d4eabe

Browse files
committed
removed depenedency
1 parent d136a2d commit 1d4eabe

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async def _analyze_current_cluster(
9292

9393
buffer_ec2_instances = await get_ec2_client(app).get_instances(
9494
key_names=[app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_KEY_NAME],
95-
tags=get_deactivated_buffer_ec2_tags(app, auto_scaling_mode),
95+
tags=get_deactivated_buffer_ec2_tags(auto_scaling_mode.get_ec2_tags(app)),
9696
state_names=["stopped"],
9797
)
9898

@@ -476,7 +476,7 @@ async def _start_warm_buffer_instances(
476476
# NOTE: first start the instance and then set the tags in case the instance cannot start (e.g. InsufficientInstanceCapacity)
477477
await get_ec2_client(app).set_instances_tags(
478478
started_instances,
479-
tags=get_activated_buffer_ec2_tags(app, auto_scaling_mode),
479+
tags=get_activated_buffer_ec2_tags(auto_scaling_mode.get_ec2_tags(app)),
480480
)
481481
started_instance_ids = [i.id for i in started_instances]
482482

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async def _analyse_current_state(
119119

120120
all_buffer_instances = await ec2_client.get_instances(
121121
key_names=[app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_KEY_NAME],
122-
tags=get_deactivated_buffer_ec2_tags(app, auto_scaling_mode),
122+
tags=get_deactivated_buffer_ec2_tags(auto_scaling_mode.get_ec2_tags(app)),
123123
state_names=["stopped", "pending", "running", "stopping"],
124124
)
125125
buffers_manager = BufferPoolManager()
@@ -265,7 +265,9 @@ async def _add_remove_buffer_instances(
265265
name=ec2_type,
266266
resources=Resources.create_as_empty(), # fake resources
267267
),
268-
tags=get_deactivated_buffer_ec2_tags(app, auto_scaling_mode),
268+
tags=get_deactivated_buffer_ec2_tags(
269+
auto_scaling_mode.get_ec2_tags(app)
270+
),
269271
startup_script=ec2_buffer_startup_script(
270272
ec2_boot_specific, app_settings
271273
),

services/autoscaling/src/simcore_service_autoscaling/utils/buffer_machines_pool_core.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from aws_library.ec2 import AWS_TAG_VALUE_MAX_LENGTH, AWSTagKey, AWSTagValue, EC2Tags
66
from common_library.json_serialization import json_dumps
7-
from fastapi import FastAPI
87
from models_library.docker import DockerGenericTag
98
from pydantic import TypeAdapter
109

@@ -15,27 +14,20 @@
1514
PRE_PULLED_IMAGES_EC2_TAG_KEY,
1615
PRE_PULLED_IMAGES_RE,
1716
)
18-
from ..modules.auto_scaling_mode_base import BaseAutoscaling
1917

2018
_NAME_EC2_TAG_KEY: Final[AWSTagKey] = TypeAdapter(AWSTagKey).validate_python("Name")
2119

2220

23-
def get_activated_buffer_ec2_tags(
24-
app: FastAPI, auto_scaling_mode: BaseAutoscaling
25-
) -> EC2Tags:
26-
return auto_scaling_mode.get_ec2_tags(app) | ACTIVATED_BUFFER_MACHINE_EC2_TAGS
21+
def get_activated_buffer_ec2_tags(base_ec2_tags: EC2Tags) -> EC2Tags:
22+
return base_ec2_tags | ACTIVATED_BUFFER_MACHINE_EC2_TAGS
2723

2824

29-
def get_deactivated_buffer_ec2_tags(
30-
app: FastAPI, auto_scaling_mode: BaseAutoscaling
31-
) -> EC2Tags:
32-
base_ec2_tags = (
33-
auto_scaling_mode.get_ec2_tags(app) | DEACTIVATED_BUFFER_MACHINE_EC2_TAGS
25+
def get_deactivated_buffer_ec2_tags(base_ec2_tags: EC2Tags) -> EC2Tags:
26+
new_base_ec2_tags = base_ec2_tags | DEACTIVATED_BUFFER_MACHINE_EC2_TAGS
27+
new_base_ec2_tags[_NAME_EC2_TAG_KEY] = TypeAdapter(AWSTagValue).validate_python(
28+
f"{new_base_ec2_tags[_NAME_EC2_TAG_KEY]}-buffer"
3429
)
35-
base_ec2_tags[_NAME_EC2_TAG_KEY] = TypeAdapter(AWSTagValue).validate_python(
36-
f"{base_ec2_tags[_NAME_EC2_TAG_KEY]}-buffer"
37-
)
38-
return base_ec2_tags
30+
return new_base_ec2_tags
3931

4032

4133
def is_buffer_machine(tags: EC2Tags) -> bool:

services/autoscaling/tests/unit/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ async def _do(
11851185
resource_tags: list[TagTypeDef] = [
11861186
{"Key": tag_key, "Value": tag_value}
11871187
for tag_key, tag_value in get_deactivated_buffer_ec2_tags(
1188-
initialized_app, DynamicAutoscaling()
1188+
DynamicAutoscaling().get_ec2_tags(initialized_app)
11891189
).items()
11901190
]
11911191
if pre_pull_images is not None and instance_state_name == "stopped":

services/autoscaling/tests/unit/test_utils_buffer_machines_pool_core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_get_activated_buffer_ec2_tags_dynamic(
3939
):
4040
auto_scaling_mode = DynamicAutoscaling()
4141
activated_buffer_tags = get_activated_buffer_ec2_tags(
42-
initialized_app, auto_scaling_mode
42+
auto_scaling_mode.get_ec2_tags(initialized_app)
4343
)
4444
assert (
4545
auto_scaling_mode.get_ec2_tags(initialized_app)
@@ -57,7 +57,7 @@ def test_get_deactivated_buffer_ec2_tags_dynamic(
5757
):
5858
auto_scaling_mode = DynamicAutoscaling()
5959
deactivated_buffer_tags = get_deactivated_buffer_ec2_tags(
60-
initialized_app, auto_scaling_mode
60+
auto_scaling_mode.get_ec2_tags(initialized_app)
6161
)
6262
# when deactivated the buffer EC2 name has an additional -buffer suffix
6363
expected_tags = (
@@ -81,7 +81,7 @@ def test_get_activated_buffer_ec2_tags_computational(
8181
):
8282
auto_scaling_mode = ComputationalAutoscaling()
8383
activated_buffer_tags = get_activated_buffer_ec2_tags(
84-
initialized_app, auto_scaling_mode
84+
auto_scaling_mode.get_ec2_tags(initialized_app)
8585
)
8686
assert (
8787
auto_scaling_mode.get_ec2_tags(initialized_app)
@@ -99,7 +99,7 @@ def test_get_deactivated_buffer_ec2_tags_computational(
9999
):
100100
auto_scaling_mode = ComputationalAutoscaling()
101101
deactivated_buffer_tags = get_deactivated_buffer_ec2_tags(
102-
initialized_app, auto_scaling_mode
102+
auto_scaling_mode.get_ec2_tags(initialized_app)
103103
)
104104
# when deactivated the buffer EC2 name has an additional -buffer suffix
105105
expected_tags = (

0 commit comments

Comments
 (0)