Skip to content

Commit c899568

Browse files
committed
rm default and adds explicit
1 parent 63bdc45 commit c899568

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

packages/aws-library/src/aws_library/ec2/_client.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from collections.abc import Iterable, Sequence
44
from dataclasses import dataclass
5-
from typing import cast
5+
from typing import Literal, cast
66

77
import aioboto3
88
import botocore.exceptions
@@ -30,9 +30,6 @@
3030
_logger = logging.getLogger(__name__)
3131

3232

33-
ALL = None
34-
35-
3633
@dataclass()
3734
class SimcoreEC2API:
3835
client: EC2Client
@@ -69,25 +66,24 @@ async def ping(self) -> bool:
6966
@ec2_exception_handler(_logger)
7067
async def get_ec2_instance_capabilities(
7168
self,
72-
instance_type_names: set[InstanceTypeType] | None = ALL,
69+
instance_type_names: set[InstanceTypeType] | Literal["ALL"],
7370
) -> list[EC2InstanceType]:
7471
"""Returns the ec2 instance types from a list of instance type names (sorted by name)
7572
7673
Arguments:
77-
instance_type_names -- the types to filter with
74+
instance_type_names -- the types to filter with or "ALL", to return all EC2 possible instances
7875
7976
Raises:
8077
Ec2InstanceTypeInvalidError: some invalid types were used as filter
8178
ClustersKeeperRuntimeError: unexpected error communicating with EC2
8279
8380
"""
84-
if instance_type_names is None:
85-
assert ALL is None # nosec
81+
if instance_type_names == "ALL":
8682
selection_or_all_if_empty = []
8783
else:
8884
selection_or_all_if_empty = list(instance_type_names)
8985
if len(selection_or_all_if_empty) == 0:
90-
msg = "`instance_type_names` cannot be an empty set. Set as None if all"
86+
msg = "`instance_type_names` cannot be an empty set. Use either a selection or 'ALL'"
9187
raise ValueError(msg)
9288

9389
instance_types = await self.client.describe_instance_types(

packages/aws-library/tests/test_ec2_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ async def test_get_ec2_instance_capabilities(
122122
async def test_get_ec2_instance_capabilities_returns_all_options(
123123
simcore_ec2_api: SimcoreEC2API,
124124
):
125-
instance_types = await simcore_ec2_api.get_ec2_instance_capabilities()
125+
instance_types = await simcore_ec2_api.get_ec2_instance_capabilities("ALL")
126126
assert instance_types
127127
# NOTE: this might need adaptation when moto is updated
128128
assert 700 < len(instance_types) < 828

packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/clusters_keeper/ec2_instances.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Literal
2+
13
from models_library.api_schemas_clusters_keeper import CLUSTERS_KEEPER_RPC_NAMESPACE
24
from models_library.api_schemas_clusters_keeper.ec2_instances import EC2InstanceTypeGet
35
from models_library.rabbitmq_basic_types import RPCMethodName
@@ -7,7 +9,7 @@
79

810

911
async def get_instance_type_details(
10-
client: RabbitMQRPCClient, *, instance_type_names: set[str]
12+
client: RabbitMQRPCClient, *, instance_type_names: set[str] | Literal["ALL"]
1113
) -> list[EC2InstanceTypeGet]:
1214
"""**Remote method**
1315

services/clusters-keeper/src/simcore_service_clusters_keeper/rpc/ec2_instances.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Literal
2+
13
from aws_library.ec2 import EC2InstanceType
24
from fastapi import FastAPI
35
from models_library.api_schemas_clusters_keeper.ec2_instances import EC2InstanceTypeGet
@@ -10,7 +12,7 @@
1012

1113
@router.expose()
1214
async def get_instance_type_details(
13-
app: FastAPI, *, instance_type_names: set[str]
15+
app: FastAPI, *, instance_type_names: set[str] | Literal["ALL"]
1416
) -> list[EC2InstanceTypeGet]:
1517
instance_capabilities: list[EC2InstanceType] = await get_ec2_client(
1618
app

services/clusters-keeper/tests/unit/test_rpc_ec2_instances.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def test_get_instance_type_details_all_options(
3737
# an empty set returns all options
3838

3939
rpc_response = await get_instance_type_details(
40-
clusters_keeper_rabbitmq_rpc_client, instance_type_names=set()
40+
clusters_keeper_rabbitmq_rpc_client, instance_type_names="ALL"
4141
)
4242
assert rpc_response
4343
assert isinstance(rpc_response, list)

0 commit comments

Comments
 (0)