Skip to content

Commit

Permalink
ensure dict are correctly setup
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Dec 10, 2023
1 parent 5ae5e13 commit 53f68bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _convert_to_env_dict(entries: dict[str, Any]) -> str:
f"WORKERS_EC2_INSTANCES_SECURITY_GROUP_IDS={_convert_to_env_list(app_settings.CLUSTERS_KEEPER_WORKERS_EC2_INSTANCES.WORKERS_EC2_INSTANCES_SECURITY_GROUP_IDS)}",
f"WORKERS_EC2_INSTANCES_SUBNET_ID={app_settings.CLUSTERS_KEEPER_WORKERS_EC2_INSTANCES.WORKERS_EC2_INSTANCES_SUBNET_ID}",
f"WORKERS_EC2_INSTANCES_TIME_BEFORE_TERMINATION={app_settings.CLUSTERS_KEEPER_WORKERS_EC2_INSTANCES.WORKERS_EC2_INSTANCES_TIME_BEFORE_TERMINATION}",
f"WORKERS_EC2_INSTANCES_CUSTOM_TAGS={app_settings.CLUSTERS_KEEPER_WORKERS_EC2_INSTANCES.WORKERS_EC2_INSTANCES_CUSTOM_TAGS | additional_custom_tags}",
f"WORKERS_EC2_INSTANCES_CUSTOM_TAGS={_convert_to_env_dict(app_settings.CLUSTERS_KEEPER_WORKERS_EC2_INSTANCES.WORKERS_EC2_INSTANCES_CUSTOM_TAGS | additional_custom_tags)}",
f"LOG_LEVEL={app_settings.LOG_LEVEL}",
]

Expand Down
31 changes: 29 additions & 2 deletions services/clusters-keeper/tests/unit/test_utils_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
from typing import Any

import pytest
from aws_library.ec2.models import EC2InstanceBootSpecific, EC2InstanceData
from aws_library.ec2.models import (
AWSTagKey,
AWSTagValue,
EC2InstanceBootSpecific,
EC2InstanceData,
)
from faker import Faker
from models_library.api_schemas_clusters_keeper.clusters import ClusterState
from pytest_simcore.helpers.utils_envs import EnvVarsDict
Expand Down Expand Up @@ -45,8 +50,14 @@ def test_create_startup_script(
clusters_keeper_docker_compose: dict[str, Any],
ec2_boot_specs: EC2InstanceBootSpecific,
):
additional_custom_tags = {
AWSTagKey("pytest-tag-key"): AWSTagValue("pytest-tag-value")
}
startup_script = create_startup_script(
app_settings, cluster_machines_name_prefix, ec2_boot_specs
app_settings,
cluster_machines_name_prefix=cluster_machines_name_prefix,
ec2_boot_specific=ec2_boot_specs,
additional_custom_tags=additional_custom_tags,
)
assert isinstance(startup_script, str)
assert len(ec2_boot_specs.custom_boot_scripts) > 0
Expand Down Expand Up @@ -104,6 +115,22 @@ def test_create_startup_script(
re.search(rf"{i}=\[(\\\".+\\\")*\]", startup_script) for i in list_settings
)

# check dicts have \' in front
dict_settings = [
"WORKERS_EC2_INSTANCES_ALLOWED_TYPES",
"WORKERS_EC2_INSTANCES_CUSTOM_TAGS",
]
assert all(
re.search(rf"{i}=\'{{(\".+\":\s\".*\")+}}\'", startup_script)
for i in dict_settings
)

# check the additional tags are in
assert all(
f'"{key}": "{value}"' in startup_script
for key, value in additional_custom_tags.items()
)


@pytest.mark.parametrize(
"ec2_state, expected_cluster_state",
Expand Down

0 comments on commit 53f68bd

Please sign in to comment.