Skip to content

Commit 82ec279

Browse files
committed
pylint
1 parent 57245f6 commit 82ec279

File tree

5 files changed

+44
-34
lines changed

5 files changed

+44
-34
lines changed

services/autoscaling/src/simcore_service_autoscaling/modules/auto_scaling_core.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ async def _activate_and_notify(
369369
),
370370
post_tasks_log_message(
371371
app,
372-
drained_node.assigned_tasks,
373-
"cluster adjusted, service should start shortly...",
372+
tasks=drained_node.assigned_tasks,
373+
message="cluster adjusted, service should start shortly...",
374374
level=logging.INFO,
375375
),
376376
post_tasks_progress_message(
@@ -792,8 +792,8 @@ async def _launch_instances(
792792
except EC2TooManyInstancesError:
793793
await post_tasks_log_message(
794794
app,
795-
tasks,
796-
"The maximum number of machines in the cluster was reached. Please wait for your running jobs "
795+
tasks=tasks,
796+
message="The maximum number of machines in the cluster was reached. Please wait for your running jobs "
797797
"to complete and try again later or contact osparc support if this issue does not resolve.",
798798
level=logging.ERROR,
799799
)
@@ -834,8 +834,8 @@ async def _launch_instances(
834834
if isinstance(r, EC2TooManyInstancesError):
835835
await post_tasks_log_message(
836836
app,
837-
tasks,
838-
"Exceptionally high load on computational cluster, please try again later.",
837+
tasks=tasks,
838+
message="Exceptionally high load on computational cluster, please try again later.",
839839
level=logging.ERROR,
840840
)
841841
elif isinstance(r, BaseException):
@@ -850,12 +850,14 @@ async def _launch_instances(
850850
f"{sum(n for n in capped_needed_machines.values())} new machines launched"
851851
", it might take up to 3 minutes to start, Please wait..."
852852
)
853-
await post_tasks_log_message(app, tasks, log_message, level=logging.INFO)
853+
await post_tasks_log_message(
854+
app, tasks=tasks, message=log_message, level=logging.INFO
855+
)
854856
if last_issue:
855857
await post_tasks_log_message(
856858
app,
857-
tasks,
858-
"Unexpected issues detected, probably due to high load, please contact support",
859+
tasks=tasks,
860+
message="Unexpected issues detected, probably due to high load, please contact support",
859861
level=logging.ERROR,
860862
)
861863

@@ -1088,7 +1090,9 @@ async def _notify_based_on_machine_type(
10881090
f" est. remaining time: {timedelta_as_minute_second(estimated_time_to_completion)})...please wait..."
10891091
)
10901092
if tasks:
1091-
await post_tasks_log_message(app, tasks, message=msg, level=logging.INFO)
1093+
await post_tasks_log_message(
1094+
app, tasks=tasks, message=msg, level=logging.INFO
1095+
)
10921096
await post_tasks_progress_message(
10931097
app,
10941098
tasks=tasks,
@@ -1189,8 +1193,8 @@ async def _scale_up_cluster(
11891193
):
11901194
await post_tasks_log_message(
11911195
app,
1192-
unassigned_tasks,
1193-
"service is pending due to missing resources, scaling up cluster now...",
1196+
tasks=unassigned_tasks,
1197+
message="service is pending due to missing resources, scaling up cluster now...",
11941198
level=logging.INFO,
11951199
)
11961200
new_pending_instances = await _launch_instances(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def _get_task_ids(task: DockerTask | DaskTask) -> tuple[UserID, ProjectID, NodeI
3737

3838
async def post_tasks_log_message(
3939
app: FastAPI,
40+
*,
4041
tasks: list[DockerTask] | list[DaskTask],
4142
message: str,
42-
*,
4343
level: int = logging.INFO,
4444
) -> None:
4545
if not tasks:

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
""" Free helper functions for docker API
2-
3-
"""
1+
"""Free helper functions for docker API"""
42

53
import asyncio
64
import collections
@@ -384,7 +382,7 @@ async def compute_cluster_used_resources(
384382
list_of_used_resources = await logged_gather(
385383
*(compute_node_used_resources(docker_client, node) for node in nodes)
386384
)
387-
counter = collections.Counter({k: 0 for k in Resources.model_fields})
385+
counter = collections.Counter({k: 0 for k in list(Resources.model_fields)})
388386
for result in list_of_used_resources:
389387
counter.update(result.model_dump())
390388

@@ -413,7 +411,7 @@ async def get_docker_swarm_join_bash_command(*, join_as_drained: bool) -> str:
413411
decoded_stdout = stdout.decode()
414412
if match := re.search(_DOCKER_SWARM_JOIN_PATTERN, decoded_stdout):
415413
capture = match.groupdict()
416-
return f"{capture['command']} --availability={'drain' if join_as_drained else 'active'} {capture['token']} {capture['address']}"
414+
return f"{capture['command']} --availability={'drain' if join_as_drained else 'active'} {capture['token']} {capture['address']}"
417415
msg = f"expected docker '{_DOCKER_SWARM_JOIN_RE}' command not found: received {decoded_stdout}!"
418416
raise RuntimeError(msg)
419417

@@ -445,7 +443,7 @@ def write_compose_file_command(
445443
) -> str:
446444
compose = {
447445
"services": {
448-
f"{image_tag.split('/')[-1].replace(':','-')}": {"image": image_tag}
446+
f"{image_tag.split('/')[-1].replace(':', '-')}": {"image": image_tag}
449447
for n, image_tag in enumerate(docker_tags)
450448
},
451449
}

services/autoscaling/tests/unit/test_modules_auto_scaling_dynamic.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,9 +1787,7 @@ async def test__activate_drained_nodes_with_no_tasks(
17871787
):
17881788
# no tasks, does nothing and returns True
17891789
empty_cluster = cluster()
1790-
updated_cluster = await _activate_drained_nodes(
1791-
initialized_app, empty_cluster, DynamicAutoscaling()
1792-
)
1790+
updated_cluster = await _activate_drained_nodes(initialized_app, empty_cluster)
17931791
assert updated_cluster == empty_cluster
17941792

17951793
active_cluster = cluster(
@@ -1801,9 +1799,7 @@ async def test__activate_drained_nodes_with_no_tasks(
18011799
create_associated_instance(drained_host_node, True) # noqa: FBT003
18021800
],
18031801
)
1804-
updated_cluster = await _activate_drained_nodes(
1805-
initialized_app, active_cluster, DynamicAutoscaling()
1806-
)
1802+
updated_cluster = await _activate_drained_nodes(initialized_app, active_cluster)
18071803
assert updated_cluster == active_cluster
18081804
mock_docker_tag_node.assert_not_called()
18091805

@@ -1855,7 +1851,7 @@ async def test__activate_drained_nodes_with_no_drained_nodes(
18551851
active_nodes=[create_associated_instance(host_node, True)] # noqa: FBT003
18561852
)
18571853
updated_cluster = await _activate_drained_nodes(
1858-
initialized_app, cluster_without_drained_nodes, DynamicAutoscaling()
1854+
initialized_app, cluster_without_drained_nodes
18591855
)
18601856
assert updated_cluster == cluster_without_drained_nodes
18611857
mock_docker_tag_node.assert_not_called()
@@ -1916,7 +1912,7 @@ async def test__activate_drained_nodes_with_drained_node(
19161912
)
19171913

19181914
updated_cluster = await _activate_drained_nodes(
1919-
initialized_app, cluster_with_drained_nodes, DynamicAutoscaling()
1915+
initialized_app, cluster_with_drained_nodes
19201916
)
19211917
# they are the same nodes, but the availability might have changed here
19221918
assert updated_cluster.active_nodes != cluster_with_drained_nodes.drained_nodes

services/autoscaling/tests/unit/test_utils_rabbitmq.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
from servicelib.rabbitmq import BIND_TO_ALL_TOPICS, RabbitMQClient
2525
from settings_library.rabbit import RabbitSettings
2626
from simcore_service_autoscaling.utils.rabbitmq import (
27-
post_task_log_message,
28-
post_task_progress_message,
27+
post_tasks_log_message,
28+
post_tasks_progress_message,
2929
)
3030
from tenacity.asyncio import AsyncRetrying
3131
from tenacity.retry import retry_if_exception_type
@@ -88,7 +88,9 @@ async def test_post_task_log_message(
8888
assert len(service_tasks) == 1
8989

9090
log_message = faker.pystr()
91-
await post_task_log_message(initialized_app, service_tasks[0], log_message, 0)
91+
await post_tasks_log_message(
92+
initialized_app, tasks=service_tasks, message=log_message, level=0
93+
)
9294

9395
async for attempt in AsyncRetrying(**_TENACITY_RETRY_PARAMS):
9496
with attempt:
@@ -135,7 +137,9 @@ async def test_post_task_log_message_does_not_raise_if_service_has_no_labels(
135137

136138
# this shall not raise any exception even if the task does not contain
137139
# the necessary labels
138-
await post_task_log_message(initialized_app, service_tasks[0], faker.pystr(), 0)
140+
await post_tasks_log_message(
141+
initialized_app, tasks=service_tasks, message=faker.pystr(), level=0
142+
)
139143

140144

141145
async def test_post_task_progress_message(
@@ -178,7 +182,12 @@ async def test_post_task_progress_message(
178182
assert len(service_tasks) == 1
179183

180184
progress_value = faker.pyfloat(min_value=0)
181-
await post_task_progress_message(initialized_app, service_tasks[0], progress_value)
185+
await post_tasks_progress_message(
186+
initialized_app,
187+
tasks=service_tasks,
188+
progress=progress_value,
189+
progress_type=ProgressType.CLUSTER_UP_SCALING,
190+
)
182191

183192
async for attempt in AsyncRetrying(**_TENACITY_RETRY_PARAMS):
184193
with attempt:
@@ -225,6 +234,9 @@ async def test_post_task_progress_does_not_raise_if_service_has_no_labels(
225234

226235
# this shall not raise any exception even if the task does not contain
227236
# the necessary labels
228-
await post_task_progress_message(
229-
initialized_app, service_tasks[0], faker.pyfloat(min_value=0)
237+
await post_tasks_progress_message(
238+
initialized_app,
239+
tasks=service_tasks,
240+
progress=faker.pyfloat(min_value=0),
241+
progress_type=ProgressType.CLUSTER_UP_SCALING,
230242
)

0 commit comments

Comments
 (0)