Skip to content

Commit aaee6ad

Browse files
committed
fixed paths
1 parent 1478651 commit aaee6ad

File tree

2 files changed

+39
-45
lines changed

2 files changed

+39
-45
lines changed

services/autoscaling/tests/unit/test_modules_auto_scaling_computational.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
from models_library.docker import DOCKER_TASK_EC2_INSTANCE_TYPE_PLACEMENT_CONSTRAINT_KEY
3030
from models_library.generated_models.docker_rest_api import (
3131
Availability,
32+
)
33+
from models_library.generated_models.docker_rest_api import Node as DockerNode
34+
from models_library.generated_models.docker_rest_api import (
3235
NodeState,
3336
NodeStatus,
3437
)
35-
from models_library.generated_models.docker_rest_api import Node as DockerNode
3638
from models_library.rabbitmq_messages import RabbitAutoscalingStatusMessage
3739
from pydantic import ByteSize, TypeAdapter
3840
from pytest_mock import MockerFixture, MockType
@@ -133,7 +135,7 @@ def mock_docker_find_node_with_name_returns_fake_node(
133135
mocker: MockerFixture, fake_node: DockerNode
134136
) -> Iterator[mock.Mock]:
135137
return mocker.patch(
136-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.find_node_with_name",
138+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.find_node_with_name",
137139
autospec=True,
138140
return_value=fake_node,
139141
)
@@ -142,7 +144,7 @@ def mock_docker_find_node_with_name_returns_fake_node(
142144
@pytest.fixture
143145
def mock_docker_compute_node_used_resources(mocker: MockerFixture) -> mock.Mock:
144146
return mocker.patch(
145-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.compute_node_used_resources",
147+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.compute_node_used_resources",
146148
autospec=True,
147149
return_value=Resources.create_as_empty(),
148150
)
@@ -190,9 +192,9 @@ def ec2_instance_custom_tags(
190192

191193

192194
@pytest.fixture
193-
def create_dask_task_resources() -> Callable[
194-
[InstanceTypeType | None, Resources], DaskTaskResources
195-
]:
195+
def create_dask_task_resources() -> (
196+
Callable[[InstanceTypeType | None, Resources], DaskTaskResources]
197+
):
196198
def _do(
197199
ec2_instance_type: InstanceTypeType | None, task_resource: Resources
198200
) -> DaskTaskResources:
@@ -771,7 +773,7 @@ async def test_cluster_scaling_up_and_down( # noqa: PLR0915
771773
< app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_TIME_BEFORE_TERMINATION
772774
)
773775
mocked_docker_remove_node = mocker.patch(
774-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.remove_nodes",
776+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.remove_nodes",
775777
return_value=None,
776778
autospec=True,
777779
)
@@ -1478,9 +1480,7 @@ async def test_cluster_adapts_machines_on_the_fly(
14781480
assert (
14791481
scale_up_params1.num_tasks
14801482
>= app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES
1481-
), (
1482-
"this test requires to run a first batch of more services than the maximum number of instances allowed"
1483-
)
1483+
), "this test requires to run a first batch of more services than the maximum number of instances allowed"
14841484
# we have nothing running now
14851485
all_instances = await ec2_client.describe_instances()
14861486
assert not all_instances["Reservations"]
@@ -1572,7 +1572,7 @@ async def test_cluster_adapts_machines_on_the_fly(
15721572

15731573
# first call to auto_scale_cluster will mark 1 node as empty
15741574
with mock.patch(
1575-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.set_node_found_empty",
1575+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.set_node_found_empty",
15761576
autospec=True,
15771577
) as mock_docker_set_node_found_empty:
15781578
await auto_scale_cluster(
@@ -1594,7 +1594,7 @@ async def test_cluster_adapts_machines_on_the_fly(
15941594

15951595
# now we mock the get_node_found_empty so the next call will actually drain the machine
15961596
with mock.patch(
1597-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.get_node_empty_since",
1597+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.get_node_empty_since",
15981598
autospec=True,
15991599
return_value=arrow.utcnow().datetime
16001600
- 1.5
@@ -1629,7 +1629,7 @@ async def test_cluster_adapts_machines_on_the_fly(
16291629

16301630
# this will initiate termination now
16311631
with mock.patch(
1632-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.get_node_last_readyness_update",
1632+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.get_node_last_readyness_update",
16331633
autospec=True,
16341634
return_value=arrow.utcnow().datetime
16351635
- 1.5
@@ -1669,14 +1669,14 @@ async def test_cluster_adapts_machines_on_the_fly(
16691669

16701670
# now this will terminate it and straight away start a new machine type
16711671
with mock.patch(
1672-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.get_node_termination_started_since",
1672+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.get_node_termination_started_since",
16731673
autospec=True,
16741674
return_value=arrow.utcnow().datetime
16751675
- 1.5
16761676
* app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_TIME_BEFORE_TERMINATION,
16771677
):
16781678
mocked_docker_remove_node = mocker.patch(
1679-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.remove_nodes",
1679+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.remove_nodes",
16801680
return_value=None,
16811681
autospec=True,
16821682
)
@@ -1692,9 +1692,7 @@ async def test_cluster_adapts_machines_on_the_fly(
16921692
assert "Instances" in reservation1
16931693
assert len(reservation1["Instances"]) == (
16941694
app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES
1695-
), (
1696-
f"expected {app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES} EC2 instances, found {len(reservation1['Instances'])}"
1697-
)
1695+
), f"expected {app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES} EC2 instances, found {len(reservation1['Instances'])}"
16981696
for instance in reservation1["Instances"]:
16991697
assert "InstanceType" in instance
17001698
assert instance["InstanceType"] == scale_up_params1.expected_instance_type
@@ -1708,9 +1706,9 @@ async def test_cluster_adapts_machines_on_the_fly(
17081706

17091707
reservation2 = all_instances["Reservations"][1]
17101708
assert "Instances" in reservation2
1711-
assert len(reservation2["Instances"]) == 1, (
1712-
f"expected 1 EC2 instances, found {len(reservation2['Instances'])}"
1713-
)
1709+
assert (
1710+
len(reservation2["Instances"]) == 1
1711+
), f"expected 1 EC2 instances, found {len(reservation2['Instances'])}"
17141712
for instance in reservation2["Instances"]:
17151713
assert "InstanceType" in instance
17161714
assert instance["InstanceType"] == scale_up_params2.expected_instance_type

services/autoscaling/tests/unit/test_modules_auto_scaling_dynamic.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def mock_find_node_with_name_returns_fake_node(
113113
mocker: MockerFixture, fake_node: Node
114114
) -> Iterator[mock.Mock]:
115115
return mocker.patch(
116-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.find_node_with_name",
116+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.find_node_with_name",
117117
autospec=True,
118118
return_value=fake_node,
119119
)
@@ -122,15 +122,15 @@ def mock_find_node_with_name_returns_fake_node(
122122
@pytest.fixture
123123
def mock_remove_nodes(mocker: MockerFixture) -> mock.Mock:
124124
return mocker.patch(
125-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.remove_nodes",
125+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.remove_nodes",
126126
autospec=True,
127127
)
128128

129129

130130
@pytest.fixture
131131
def mock_compute_node_used_resources(mocker: MockerFixture) -> mock.Mock:
132132
return mocker.patch(
133-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.compute_node_used_resources",
133+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.compute_node_used_resources",
134134
autospec=True,
135135
return_value=Resources.create_as_empty(),
136136
)
@@ -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 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-
)
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"
526526

527527
# create the service(s)
528528
created_docker_services = await create_services_batch(scale_up_params)
@@ -860,7 +860,7 @@ async def _assert_wait_for_ec2_instances_running() -> list[InstanceTypeDef]:
860860
< app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_TIME_BEFORE_TERMINATION
861861
)
862862
mocked_docker_remove_node = mocker.patch(
863-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.remove_nodes",
863+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.remove_nodes",
864864
return_value=None,
865865
autospec=True,
866866
)
@@ -1281,9 +1281,7 @@ async def test_cluster_adapts_machines_on_the_fly( # noqa: PLR0915
12811281
assert (
12821282
scale_up_params1.num_services
12831283
>= app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES
1284-
), (
1285-
"this test requires to run a first batch of more services than the maximum number of instances allowed"
1286-
)
1284+
), "this test requires to run a first batch of more services than the maximum number of instances allowed"
12871285
# we have nothing running now
12881286
all_instances = await ec2_client.describe_instances()
12891287
assert not all_instances["Reservations"]
@@ -1380,7 +1378,7 @@ async def test_cluster_adapts_machines_on_the_fly( # noqa: PLR0915
13801378

13811379
# first call to auto_scale_cluster will mark 1 node as empty
13821380
with mock.patch(
1383-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.set_node_found_empty",
1381+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.set_node_found_empty",
13841382
autospec=True,
13851383
) as mock_docker_set_node_found_empty:
13861384
await auto_scale_cluster(
@@ -1402,7 +1400,7 @@ async def test_cluster_adapts_machines_on_the_fly( # noqa: PLR0915
14021400

14031401
# now we mock the get_node_found_empty so the next call will actually drain the machine
14041402
with mock.patch(
1405-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.get_node_empty_since",
1403+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.get_node_empty_since",
14061404
autospec=True,
14071405
return_value=arrow.utcnow().datetime
14081406
- 1.5
@@ -1437,7 +1435,7 @@ async def test_cluster_adapts_machines_on_the_fly( # noqa: PLR0915
14371435

14381436
# this will initiate termination now
14391437
with mock.patch(
1440-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.get_node_last_readyness_update",
1438+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.get_node_last_readyness_update",
14411439
autospec=True,
14421440
return_value=arrow.utcnow().datetime
14431441
- 1.5
@@ -1477,14 +1475,14 @@ async def test_cluster_adapts_machines_on_the_fly( # noqa: PLR0915
14771475

14781476
# now this will terminate it and straight away start a new machine type
14791477
with mock.patch(
1480-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.get_node_termination_started_since",
1478+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.get_node_termination_started_since",
14811479
autospec=True,
14821480
return_value=arrow.utcnow().datetime
14831481
- 1.5
14841482
* app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_TIME_BEFORE_TERMINATION,
14851483
):
14861484
mocked_docker_remove_node = mocker.patch(
1487-
"simcore_service_autoscaling.modules.auto_scaling_core.utils_docker.remove_nodes",
1485+
"simcore_service_autoscaling.modules.cluster_scaling._auto_scaling_core.utils_docker.remove_nodes",
14881486
return_value=None,
14891487
autospec=True,
14901488
)
@@ -1500,9 +1498,7 @@ async def test_cluster_adapts_machines_on_the_fly( # noqa: PLR0915
15001498
assert "Instances" in reservation1
15011499
assert len(reservation1["Instances"]) == (
15021500
app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES
1503-
), (
1504-
f"expected {app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES} EC2 instances, found {len(reservation1['Instances'])}"
1505-
)
1501+
), f"expected {app_settings.AUTOSCALING_EC2_INSTANCES.EC2_INSTANCES_MAX_INSTANCES} EC2 instances, found {len(reservation1['Instances'])}"
15061502
for instance in reservation1["Instances"]:
15071503
assert "InstanceType" in instance
15081504
assert instance["InstanceType"] == scale_up_params1.expected_instance_type
@@ -1516,9 +1512,9 @@ async def test_cluster_adapts_machines_on_the_fly( # noqa: PLR0915
15161512

15171513
reservation2 = all_instances["Reservations"][1]
15181514
assert "Instances" in reservation2
1519-
assert len(reservation2["Instances"]) == 1, (
1520-
f"expected 1 EC2 instances, found {len(reservation2['Instances'])}"
1521-
)
1515+
assert (
1516+
len(reservation2["Instances"]) == 1
1517+
), f"expected 1 EC2 instances, found {len(reservation2['Instances'])}"
15221518
for instance in reservation2["Instances"]:
15231519
assert "InstanceType" in instance
15241520
assert instance["InstanceType"] == scale_up_params2.expected_instance_type
@@ -2245,9 +2241,9 @@ async def test_warm_buffers_only_replace_hot_buffer_if_service_is_started_issue7
22452241
# BUG REPRODUCTION
22462242
#
22472243
# start a service that imposes same type as the hot buffer
2248-
assert hot_buffer_instance_type == "t2.xlarge", (
2249-
"the test is hard-coded for this type and accordingly resource. If this changed then the resource shall be changed too"
2250-
)
2244+
assert (
2245+
hot_buffer_instance_type == "t2.xlarge"
2246+
), "the test is hard-coded for this type and accordingly resource. If this changed then the resource shall be changed too"
22512247
scale_up_params = _ScaleUpParams(
22522248
imposed_instance_type=hot_buffer_instance_type,
22532249
service_resources=Resources(

0 commit comments

Comments
 (0)