Skip to content

Commit

Permalink
sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Oct 16, 2024
1 parent f959a48 commit 462fe38
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/aws-library/src/aws_library/ec2/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ async def get_ec2_instance_capabilities(
self,
instance_type_names: set[InstanceTypeType],
) -> list[EC2InstanceType]:
"""returns the ec2 instance types from a list of instance type names
NOTE: the order might differ!
"""Returns the ec2 instance types from a list of instance type names (sorted by name)
Arguments:
instance_type_names -- the types to filter with
instance_type_names -- the types to filter with. If an empty set, it returns all.
Raises:
Ec2InstanceTypeInvalidError: some invalid types were used as filter
Expand All @@ -95,7 +95,7 @@ async def get_ec2_instance_capabilities(
),
)
)
return list_instances
return sorted(list_instances, key=lambda i: i.name)

@ec2_exception_handler(_logger)
async def launch_instances(
Expand Down
7 changes: 1 addition & 6 deletions packages/aws-library/tests/test_ec2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,7 @@ async def test_get_ec2_instance_capabilities(
)
)
assert instance_types
assert len(instance_types) == len(ec2_allowed_instances)

# all the instance names are found and valid
assert all(i.name in ec2_allowed_instances for i in instance_types)
for instance_type_name in ec2_allowed_instances:
assert any(i.name == instance_type_name for i in instance_types)
assert [_.name for _ in instance_types] == sorted(ec2_allowed_instances)


async def test_get_ec2_instance_capabilities_empty_list_returns_all_options(
Expand Down

0 comments on commit 462fe38

Please sign in to comment.