Skip to content

Commit 6860373

Browse files
committed
added function to list all images to pre-pull
1 parent 8e18c22 commit 6860373

File tree

4 files changed

+68
-22
lines changed

4 files changed

+68
-22
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import arrow
1414
import yaml
1515
from aws_library.ec2 import EC2InstanceData, Resources
16+
from aws_library.ec2._models import EC2InstanceBootSpecific
1617
from models_library.docker import (
1718
DockerGenericTag,
1819
DockerLabelKey,
@@ -703,3 +704,13 @@ async def attach_node(
703704
def is_node_ready(node: Node) -> bool:
704705
assert node.status # nosec
705706
return bool(node.status.state is NodeState.ready)
707+
708+
709+
def compute_full_list_of_pre_pulled_images(
710+
ec2_boot_specific: EC2InstanceBootSpecific, app_settings: ApplicationSettings
711+
) -> list[DockerGenericTag]:
712+
assert app_settings.AUTOSCALING_EC2_INSTANCES # nosec
713+
common_images = (
714+
app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_COLD_START_DOCKER_IMAGES_PRE_PULLING
715+
)
716+
return sorted(set(common_images) | set(ec2_boot_specific.pre_pull_images))

services/autoscaling/tests/unit/conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,3 +1243,24 @@ async def _do(
12431243
return instance_ids
12441244

12451245
return _do
1246+
1247+
1248+
@pytest.fixture
1249+
def with_ec2_instances_cold_start_docker_images_pre_pulling(
1250+
app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch, faker: Faker
1251+
) -> EnvVarsDict:
1252+
images = TypeAdapter(list[DockerGenericTag]).validate_python(
1253+
[
1254+
"nginx:latest",
1255+
"itisfoundation/my-very-nice-service-in-common:latest",
1256+
"simcore/services/dynamic/another-nice-one:2.4.5161",
1257+
"asd",
1258+
]
1259+
)
1260+
envs = setenvs_from_dict(
1261+
monkeypatch,
1262+
{
1263+
"EC2_INSTANCES_COLD_START_DOCKER_IMAGES_PRE_PULLING": json.dumps(images),
1264+
},
1265+
)
1266+
return app_environment | envs

services/autoscaling/tests/unit/test_utils_cluster_scaling.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -195,27 +195,6 @@ def ec2_instances_boot_ami_pre_pull(
195195
return app_environment | envs
196196

197197

198-
@pytest.fixture
199-
def ec2_instances_cold_start_docker_images_pre_pulling(
200-
app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch, faker: Faker
201-
) -> EnvVarsDict:
202-
images = TypeAdapter(list[DockerGenericTag]).validate_python(
203-
[
204-
"nginx:latest",
205-
"itisfoundation/my-very-nice-service:latest",
206-
"simcore/services/dynamic/another-nice-one:2.4.5",
207-
"asd",
208-
]
209-
)
210-
envs = setenvs_from_dict(
211-
monkeypatch,
212-
{
213-
"EC2_INSTANCES_COLD_START_DOCKER_IMAGES_PRE_PULLING": json.dumps(images),
214-
},
215-
)
216-
return app_environment | envs
217-
218-
219198
@pytest.fixture
220199
def disabled_registry(monkeypatch: pytest.MonkeyPatch) -> None:
221200
monkeypatch.delenv("REGISTRY_AUTH")
@@ -224,7 +203,7 @@ def disabled_registry(monkeypatch: pytest.MonkeyPatch) -> None:
224203
async def test_ec2_startup_script_with_pre_pulling(
225204
minimal_configuration: None,
226205
ec2_instances_boot_ami_pre_pull: EnvVarsDict,
227-
ec2_instances_cold_start_docker_images_pre_pulling: EnvVarsDict,
206+
with_ec2_instances_cold_start_docker_images_pre_pulling: EnvVarsDict,
228207
app_settings: ApplicationSettings,
229208
):
230209
assert app_settings.AUTOSCALING_EC2_INSTANCES

services/autoscaling/tests/unit/test_utils_docker.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
attach_node,
5151
compute_cluster_total_resources,
5252
compute_cluster_used_resources,
53+
compute_full_list_of_pre_pulled_images,
5354
compute_node_used_resources,
5455
compute_tasks_needed_resources,
5556
find_node_with_name,
@@ -1284,3 +1285,37 @@ async def test_attach_node(
12841285
assert is_node_ready_and_available(host_node, availability=Availability.active)
12851286
# but not osparc ready
12861287
assert not is_node_osparc_ready(updated_node)
1288+
1289+
1290+
def test_compute_full_list_of_pre_pulled_images(
1291+
disabled_rabbitmq: None,
1292+
disabled_ec2: None,
1293+
disabled_ssm: None,
1294+
mocked_redis_server: None,
1295+
enabled_dynamic_mode: EnvVarsDict,
1296+
disable_autoscaling_background_task: None,
1297+
with_ec2_instances_cold_start_docker_images_pre_pulling: EnvVarsDict,
1298+
app_settings: ApplicationSettings,
1299+
):
1300+
assert app_settings.AUTOSCALING_EC2_INSTANCES
1301+
assert (
1302+
app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_COLD_START_DOCKER_IMAGES_PRE_PULLING
1303+
), "this test requires some common docker images"
1304+
1305+
for (
1306+
instance_type,
1307+
instance_boot_specific,
1308+
) in app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_ALLOWED_TYPES.items():
1309+
returned_list = compute_full_list_of_pre_pulled_images(
1310+
instance_boot_specific, app_settings
1311+
)
1312+
assert (
1313+
sorted(returned_list) == returned_list
1314+
), f"the list for {instance_type} should be sorted"
1315+
assert len(returned_list) == len(
1316+
set(returned_list)
1317+
), f"the list for {instance_type} should not have duplicates"
1318+
assert all(
1319+
i in returned_list
1320+
for i in app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_COLD_START_DOCKER_IMAGES_PRE_PULLING
1321+
)

0 commit comments

Comments
 (0)