Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/aws-library/src/aws_library/ec2/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from textwrap import dedent


def compose_user_data(docker_join_bash_command: str) -> str:
def compose_user_data(bash_command: str) -> str:
return dedent(
f"""\
#!/bin/bash
{docker_join_bash_command}
{bash_command}
"""
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import logging
from collections import OrderedDict
from collections.abc import Callable
from textwrap import dedent

from aws_library.ec2.models import (
AWSTagKey,
Expand Down Expand Up @@ -60,15 +59,6 @@ def get_ec2_tags_computational(app_settings: ApplicationSettings) -> EC2Tags:
} | app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_CUSTOM_TAGS


def compose_user_data(docker_join_bash_command: str) -> str:
return dedent(
f"""\
#!/bin/bash
{docker_join_bash_command}
"""
)


def closest_instance_policy(
ec2_instance: EC2InstanceType,
resources: Resources,
Expand Down
9 changes: 0 additions & 9 deletions services/autoscaling/tests/unit/test_utils_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@

import pytest
from aws_library.ec2.models import EC2InstanceType, Resources
from faker import Faker
from pydantic import ByteSize
from simcore_service_autoscaling.core.errors import (
ConfigurationError,
Ec2InstanceNotFoundError,
)
from simcore_service_autoscaling.utils.utils_ec2 import (
closest_instance_policy,
compose_user_data,
find_best_fitting_ec2_instance,
)

Expand Down Expand Up @@ -63,10 +61,3 @@ async def test_find_best_fitting_ec2_instance_closest_instance_policy(
)

assert found_instance.resources == expected_ec2_instance.resources


def test_compose_user_data(faker: Faker):
command = faker.text()
user_data = compose_user_data(command)
assert user_data.startswith("#!/bin/bash")
assert command in user_data
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ services:
DASK_SCHEDULER_AUTH: '{"type":"tls","tls_ca_file":"${DASK_TLS_CA_FILE}","tls_client_cert":"${DASK_TLS_CERT}","tls_client_key":"${DASK_TLS_KEY}"}'
EC2_INSTANCES_ALLOWED_TYPES: ${WORKERS_EC2_INSTANCES_ALLOWED_TYPES}
EC2_INSTANCES_CUSTOM_TAGS: ${WORKERS_EC2_INSTANCES_CUSTOM_TAGS}
EC2_INSTANCES_ATTACHED_IAM_PROFILE: ""
EC2_INSTANCES_ATTACHED_IAM_PROFILE: ${EC2_INSTANCES_ATTACHED_IAM_PROFILE}
EC2_INSTANCES_KEY_NAME: ${WORKERS_EC2_INSTANCES_KEY_NAME}
EC2_INSTANCES_MACHINES_BUFFER: 0
EC2_INSTANCES_MAX_INSTANCES: ${WORKERS_EC2_INSTANCES_MAX_INSTANCES}
Expand Down Expand Up @@ -188,6 +188,7 @@ services:
networks:
cluster:


configs:
prometheus-config:
file: ./prometheus.yml
Expand All @@ -200,6 +201,7 @@ volumes:
redis-data:
prometheus-data:


secrets:
dask_tls_ca:
file: ${DASK_TLS_CA_FILE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def _convert_to_env_dict(entries: dict[str, Any]) -> str:
f"WORKERS_EC2_INSTANCES_SUBNET_ID={app_settings.CLUSTERS_KEEPER_WORKERS_EC2_INSTANCES.WORKERS_EC2_INSTANCES_SUBNET_ID}",
f"WORKERS_EC2_INSTANCES_TIME_BEFORE_DRAINING={app_settings.CLUSTERS_KEEPER_WORKERS_EC2_INSTANCES.WORKERS_EC2_INSTANCES_TIME_BEFORE_DRAINING}",
f"WORKERS_EC2_INSTANCES_TIME_BEFORE_TERMINATION={app_settings.CLUSTERS_KEEPER_WORKERS_EC2_INSTANCES.WORKERS_EC2_INSTANCES_TIME_BEFORE_TERMINATION}",
f"EC2_INSTANCES_ATTACHED_IAM_PROFILE={app_settings.CLUSTERS_KEEPER_PRIMARY_EC2_INSTANCES.PRIMARY_EC2_INSTANCES_ATTACHED_IAM_PROFILE}",
]


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from textwrap import dedent
from typing import Final

from aws_library.ec2.models import AWSTagKey, AWSTagValue, EC2Tags
Expand Down Expand Up @@ -70,14 +69,3 @@ def ec2_instances_for_user_wallet_filter(
| {AWSTagKey("user_id"): AWSTagValue(f"{user_id}")}
| {AWSTagKey("wallet_id"): AWSTagValue(f"{wallet_id}")}
)


def compose_user_data(bash_command: str) -> str:
return dedent(
f"""\
#!/bin/bash
echo "started user data bash script"
{bash_command}
echo "completed user data bash script"
"""
)
13 changes: 0 additions & 13 deletions services/clusters-keeper/tests/unit/test_utils_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from simcore_service_clusters_keeper.utils.ec2 import (
_APPLICATION_TAG_KEY,
all_created_ec2_instances_filter,
compose_user_data,
creation_ec2_tags,
get_cluster_name,
)
Expand Down Expand Up @@ -93,15 +92,3 @@ def test_all_created_ec2_instances_filter(
assert all(
tag_key_name in EXPECTED_TAG_KEY_NAMES for tag_key_name in received_tags
), f"non expected tag key names in {received_tags.keys()}, expected {EXPECTED_TAG_KEY_NAMES}"


@pytest.fixture
def bash_command(faker: Faker) -> str:
return faker.pystr()


def test_compose_user_data(bash_command: str):
received_user_data = compose_user_data(bash_command)
assert received_user_data
assert received_user_data.startswith("#!/bin/bash\n")
assert bash_command in received_user_data