Skip to content

Commit 64a1bc1

Browse files
committed
movinf files around
1 parent e8e99b7 commit 64a1bc1

File tree

7 files changed

+68
-54
lines changed

7 files changed

+68
-54
lines changed

services/autoscaling/src/simcore_service_autoscaling/core/application.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
APP_STARTED_DYNAMIC_BANNER_MSG,
1818
)
1919
from ..api.routes import setup_api_routes
20-
from ..modules.auto_scaling_task import setup as setup_auto_scaler_background_task
20+
from ..modules.cluster_scaling.auto_scaling_task import (
21+
setup as setup_auto_scaler_background_task,
22+
)
2123
from ..modules.buffer_machines_pool_task import setup as setup_buffer_machines_pool_task
2224
from ..modules.docker import setup as setup_docker
2325
from ..modules.ec2 import setup as setup_ec2

services/autoscaling/src/simcore_service_autoscaling/modules/cluster_scaling/__init__.py

Whitespace-only changes.

services/autoscaling/src/simcore_service_autoscaling/modules/auto_scaling_core.py renamed to services/autoscaling/src/simcore_service_autoscaling/modules/cluster_scaling/auto_scaling_core.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,44 @@
2424
from servicelib.utils_formatting import timedelta_as_minute_second
2525
from types_aiobotocore_ec2.literals import InstanceTypeType
2626

27-
from ..constants import DOCKER_JOIN_COMMAND_EC2_TAG_KEY, DOCKER_JOIN_COMMAND_NAME
28-
from ..core.errors import (
27+
from ...constants import DOCKER_JOIN_COMMAND_EC2_TAG_KEY, DOCKER_JOIN_COMMAND_NAME
28+
from ...core.errors import (
2929
Ec2InvalidDnsNameError,
3030
TaskBestFittingInstanceNotFoundError,
3131
TaskRequirementsAboveRequiredEC2InstanceTypeError,
3232
TaskRequiresUnauthorizedEC2InstanceTypeError,
3333
)
34-
from ..core.settings import ApplicationSettings, get_application_settings
35-
from ..models import (
34+
from ...core.settings import ApplicationSettings, get_application_settings
35+
from ...models import (
3636
AssignedTasksToInstanceType,
3737
AssociatedInstance,
3838
Cluster,
3939
NonAssociatedInstance,
4040
)
41-
from ..utils import utils_docker, utils_ec2
42-
from ..utils.auto_scaling_core import (
41+
from ...utils import utils_docker, utils_ec2
42+
from ...utils.auto_scaling_core import (
4343
associate_ec2_instances_with_nodes,
4444
ec2_startup_script,
4545
find_selected_instance_type_for_task,
4646
get_machine_buffer_type,
4747
node_host_name_from_ec2_private_dns,
4848
sort_drained_nodes,
4949
)
50-
from ..utils.buffer_machines_pool_core import (
50+
from ...utils.buffer_machines_pool_core import (
5151
get_activated_buffer_ec2_tags,
5252
get_deactivated_buffer_ec2_tags,
5353
is_buffer_machine,
5454
)
55-
from ..utils.rabbitmq import (
55+
from ...utils.rabbitmq import (
5656
post_autoscaling_status_message,
5757
post_tasks_log_message,
5858
post_tasks_progress_message,
5959
)
60-
from .auto_scaling_mode_base import BaseAutoscaling
61-
from .docker import get_docker_client
62-
from .ec2 import get_ec2_client
63-
from .instrumentation import get_instrumentation, has_instrumentation
64-
from .ssm import get_ssm_client
60+
from ..auto_scaling_mode_base import BaseAutoscaling
61+
from ..docker import get_docker_client
62+
from ..ec2 import get_ec2_client
63+
from ..instrumentation import get_instrumentation, has_instrumentation
64+
from ..ssm import get_ssm_client
6565

6666
_logger = logging.getLogger(__name__)
6767

services/autoscaling/src/simcore_service_autoscaling/modules/auto_scaling_task.py renamed to services/autoscaling/src/simcore_service_autoscaling/modules/cluster_scaling/auto_scaling_task.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
from servicelib.background_task import create_periodic_task
88
from servicelib.redis import exclusive
99

10-
from ..core.settings import ApplicationSettings
11-
from ..utils.redis import create_lock_key_and_value
10+
from ...core.settings import ApplicationSettings
11+
from ...utils.redis import create_lock_key_and_value
1212
from .auto_scaling_core import auto_scale_cluster
13-
from .auto_scaling_mode_computational import ComputationalAutoscaling
14-
from .auto_scaling_mode_dynamic import DynamicAutoscaling
15-
from .redis import get_redis_client
13+
from ..auto_scaling_mode_computational import ComputationalAutoscaling
14+
from ..auto_scaling_mode_dynamic import DynamicAutoscaling
15+
from ..redis import get_redis_client
1616

1717
_TASK_NAME: Final[str] = "Autoscaling EC2 instances"
1818

services/autoscaling/tests/unit/conftest.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
Cluster,
7979
DaskTaskResources,
8080
)
81-
from simcore_service_autoscaling.modules import auto_scaling_core
81+
from simcore_service_autoscaling.modules.cluster_scaling import auto_scaling_core
8282
from simcore_service_autoscaling.modules.auto_scaling_mode_dynamic import (
8383
DynamicAutoscaling,
8484
)
@@ -754,9 +754,9 @@ async def _() -> None:
754754
assert tasks, f"no tasks available for {found_service['Spec']['Name']}"
755755
assert len(tasks) == 1
756756
service_task = tasks[0]
757-
assert (
758-
service_task["Status"]["State"] in expected_states
759-
), f"service {found_service['Spec']['Name']}'s task is {service_task['Status']['State']}"
757+
assert service_task["Status"]["State"] in expected_states, (
758+
f"service {found_service['Spec']['Name']}'s task is {service_task['Status']['State']}"
759+
)
760760
ctx.logger.info(
761761
"%s",
762762
f"service {found_service['Spec']['Name']} is now {service_task['Status']['State']} {'.' * number_of_success['count']}",
@@ -983,7 +983,9 @@ def _creator(
983983
assert (
984984
datetime.timedelta(seconds=10)
985985
< app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_TIME_BEFORE_TERMINATION
986-
), "this tests relies on the fact that the time before termination is above 10 seconds"
986+
), (
987+
"this tests relies on the fact that the time before termination is above 10 seconds"
988+
)
987989
assert app_settings.AUTOSCALING_EC2_INSTANCES
988990
seconds_delta = (
989991
-datetime.timedelta(seconds=10)
@@ -1124,12 +1126,12 @@ def ec2_instances_allowed_types_with_only_1_buffered(
11241126
allowed_ec2_types.items(),
11251127
)
11261128
)
1127-
assert (
1128-
allowed_ec2_types_with_buffer_defined
1129-
), "one type with buffer is needed for the tests!"
1130-
assert (
1131-
len(allowed_ec2_types_with_buffer_defined) == 1
1132-
), "more than one type with buffer is disallowed in this test!"
1129+
assert allowed_ec2_types_with_buffer_defined, (
1130+
"one type with buffer is needed for the tests!"
1131+
)
1132+
assert len(allowed_ec2_types_with_buffer_defined) == 1, (
1133+
"more than one type with buffer is disallowed in this test!"
1134+
)
11331135
return {
11341136
TypeAdapter(InstanceTypeType).validate_python(k): v
11351137
for k, v in allowed_ec2_types_with_buffer_defined.items()
@@ -1153,9 +1155,9 @@ def _by_buffer_count(
11531155
filter(_by_buffer_count, allowed_ec2_types.items())
11541156
)
11551157
assert allowed_ec2_types_with_buffer_defined, "you need one type with buffer"
1156-
assert (
1157-
len(allowed_ec2_types_with_buffer_defined) == 1
1158-
), "more than one type with buffer is disallowed in this test!"
1158+
assert len(allowed_ec2_types_with_buffer_defined) == 1, (
1159+
"more than one type with buffer is disallowed in this test!"
1160+
)
11591161
return next(iter(allowed_ec2_types_with_buffer_defined.values())).buffer_count
11601162

11611163

services/autoscaling/tests/unit/test_modules_auto_scaling_computational.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
from pytest_simcore.helpers.monkeypatch_envs import EnvVarsDict, setenvs_from_dict
4242
from simcore_service_autoscaling.core.settings import ApplicationSettings
4343
from simcore_service_autoscaling.models import EC2InstanceData
44-
from simcore_service_autoscaling.modules.auto_scaling_core import auto_scale_cluster
44+
from simcore_service_autoscaling.modules.cluster_scaling.auto_scaling_core import (
45+
auto_scale_cluster,
46+
)
4547
from simcore_service_autoscaling.modules.auto_scaling_mode_computational import (
4648
ComputationalAutoscaling,
4749
)
@@ -185,9 +187,9 @@ def ec2_instance_custom_tags(
185187

186188

187189
@pytest.fixture
188-
def create_dask_task_resources() -> (
189-
Callable[[InstanceTypeType | None, Resources], DaskTaskResources]
190-
):
190+
def create_dask_task_resources() -> Callable[
191+
[InstanceTypeType | None, Resources], DaskTaskResources
192+
]:
191193
def _do(
192194
ec2_instance_type: InstanceTypeType | None, task_resource: Resources
193195
) -> DaskTaskResources:
@@ -1473,7 +1475,9 @@ async def test_cluster_adapts_machines_on_the_fly(
14731475
assert (
14741476
scale_up_params1.num_tasks
14751477
>= app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES
1476-
), "this test requires to run a first batch of more services than the maximum number of instances allowed"
1478+
), (
1479+
"this test requires to run a first batch of more services than the maximum number of instances allowed"
1480+
)
14771481
# we have nothing running now
14781482
all_instances = await ec2_client.describe_instances()
14791483
assert not all_instances["Reservations"]
@@ -1685,7 +1689,9 @@ async def test_cluster_adapts_machines_on_the_fly(
16851689
assert "Instances" in reservation1
16861690
assert len(reservation1["Instances"]) == (
16871691
app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES
1688-
), f"expected {app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES} EC2 instances, found {len(reservation1['Instances'])}"
1692+
), (
1693+
f"expected {app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES} EC2 instances, found {len(reservation1['Instances'])}"
1694+
)
16891695
for instance in reservation1["Instances"]:
16901696
assert "InstanceType" in instance
16911697
assert instance["InstanceType"] == scale_up_params1.expected_instance_type
@@ -1699,9 +1705,9 @@ async def test_cluster_adapts_machines_on_the_fly(
16991705

17001706
reservation2 = all_instances["Reservations"][1]
17011707
assert "Instances" in reservation2
1702-
assert (
1703-
len(reservation2["Instances"]) == 1
1704-
), f"expected 1 EC2 instances, found {len(reservation2['Instances'])}"
1708+
assert len(reservation2["Instances"]) == 1, (
1709+
f"expected 1 EC2 instances, found {len(reservation2['Instances'])}"
1710+
)
17051711
for instance in reservation2["Instances"]:
17061712
assert "InstanceType" in instance
17071713
assert instance["InstanceType"] == scale_up_params2.expected_instance_type

services/autoscaling/tests/unit/test_modules_auto_scaling_dynamic.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from simcore_service_autoscaling.constants import BUFFER_MACHINE_TAG_KEY
5454
from simcore_service_autoscaling.core.settings import ApplicationSettings
5555
from simcore_service_autoscaling.models import AssociatedInstance, Cluster
56-
from simcore_service_autoscaling.modules.auto_scaling_core import (
56+
from simcore_service_autoscaling.modules.cluster_scaling.auto_scaling_core import (
5757
_activate_drained_nodes,
5858
_find_terminateable_instances,
5959
_try_scale_down_cluster,
@@ -520,9 +520,9 @@ async def _test_cluster_scaling_up_and_down( # noqa: PLR0915
520520
all_instances = await ec2_client.describe_instances(Filters=instance_type_filters)
521521
assert not all_instances["Reservations"]
522522

523-
assert (
524-
scale_up_params.expected_num_instances == 1
525-
), "This test is not made to work with more than 1 expected instance. so please adapt if needed"
523+
assert scale_up_params.expected_num_instances == 1, (
524+
"This test is not made to work with more than 1 expected instance. so please adapt if needed"
525+
)
526526

527527
# create the service(s)
528528
created_docker_services = await create_services_batch(scale_up_params)
@@ -1283,7 +1283,9 @@ async def test_cluster_adapts_machines_on_the_fly( # noqa: PLR0915
12831283
assert (
12841284
scale_up_params1.num_services
12851285
>= app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES
1286-
), "this test requires to run a first batch of more services than the maximum number of instances allowed"
1286+
), (
1287+
"this test requires to run a first batch of more services than the maximum number of instances allowed"
1288+
)
12871289
# we have nothing running now
12881290
all_instances = await ec2_client.describe_instances()
12891291
assert not all_instances["Reservations"]
@@ -1500,7 +1502,9 @@ async def test_cluster_adapts_machines_on_the_fly( # noqa: PLR0915
15001502
assert "Instances" in reservation1
15011503
assert len(reservation1["Instances"]) == (
15021504
app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES
1503-
), f"expected {app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES} EC2 instances, found {len(reservation1['Instances'])}"
1505+
), (
1506+
f"expected {app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES} EC2 instances, found {len(reservation1['Instances'])}"
1507+
)
15041508
for instance in reservation1["Instances"]:
15051509
assert "InstanceType" in instance
15061510
assert instance["InstanceType"] == scale_up_params1.expected_instance_type
@@ -1514,9 +1518,9 @@ async def test_cluster_adapts_machines_on_the_fly( # noqa: PLR0915
15141518

15151519
reservation2 = all_instances["Reservations"][1]
15161520
assert "Instances" in reservation2
1517-
assert (
1518-
len(reservation2["Instances"]) == 1
1519-
), f"expected 1 EC2 instances, found {len(reservation2['Instances'])}"
1521+
assert len(reservation2["Instances"]) == 1, (
1522+
f"expected 1 EC2 instances, found {len(reservation2['Instances'])}"
1523+
)
15201524
for instance in reservation2["Instances"]:
15211525
assert "InstanceType" in instance
15221526
assert instance["InstanceType"] == scale_up_params2.expected_instance_type
@@ -2245,9 +2249,9 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
22452249
# BUG REPRODUCTION
22462250
#
22472251
# start a service that imposes same type as the hot buffer
2248-
assert (
2249-
hot_buffer_instance_type == "t2.xlarge"
2250-
), "the test is hard-coded for this type and accordingly resource. If this changed then the resource shall be changed too"
2252+
assert hot_buffer_instance_type == "t2.xlarge", (
2253+
"the test is hard-coded for this type and accordingly resource. If this changed then the resource shall be changed too"
2254+
)
22512255
scale_up_params = _ScaleUpParams(
22522256
imposed_instance_type=hot_buffer_instance_type,
22532257
service_resources=Resources(

0 commit comments

Comments
 (0)