Skip to content

Commit

Permalink
fix: make stable testing and resolve runtime error
Browse files Browse the repository at this point in the history
  • Loading branch information
1101-1 committed Oct 23, 2024
1 parent 4fb7e5c commit 6ab45f4
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 268 deletions.
21 changes: 12 additions & 9 deletions plugins/aws/fix_plugin_aws/resource/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,12 @@ class AwsEc2InstanceType(AwsResource, BaseInstanceType):
supported_boot_modes: List[str] = field(factory=list)

@classmethod
def collect_resource_types(cls, builder: GraphBuilder, *instances) -> None:
def collect_resource_types(cls, builder: GraphBuilder, instance_types: List[str]) -> None:
spec = AwsApiSpec(service_name, "describe-instance-types", "InstanceTypes")
# Default behavior: in case the class has an ApiSpec, call the api and call collect.
log.debug(f"Collecting {cls.__name__} in region {builder.region.name}")
try:
filters = [{"Name": "instance-type", "Values": list(instances)}]
filters = [{"Name": "instance-type", "Values": instance_types}]
items = builder.client.list(
aws_service=spec.service,
action=spec.api_action,
Expand Down Expand Up @@ -1421,15 +1421,18 @@ def collect_resources(cls: Type[AwsResource], builder: GraphBuilder) -> None:
)
if not items:
return
ec2_instance_types = set()
ec2_instance_types = []
checked_types = set()
for item in items:
instances = item.get("Instances", [])
for instance in instances:
if "InstanceType" in instance:
ec2_instance_types.add(instance["InstanceType"])
for instance in item.get("Instances", []):
if instance_type := instance.get("InstanceType"):
if instance_type not in checked_types:
ec2_instance_types.append(instance_type)
checked_types.add(instance_type)
if ec2_instance_types:
# collect ec2 instance types
AwsEc2InstanceType.collect_resource_types(builder, ec2_instance_types)
builder.submit_work(
service_name, AwsEc2InstanceType.collect_resource_types, builder, ec2_instance_types
)
cls.collect(items, builder)
except Boto3Error as e:
msg = f"Error while collecting {cls.__name__} in region {builder.region.name}: {e}"
Expand Down
3 changes: 2 additions & 1 deletion plugins/aws/test/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ def round_trip_for(
to_collect = [cls] + collect_also if collect_also else [cls]
builder = build_graph(to_collect, region_name=region_name)
assert len(builder.graph.nodes) > 0
for node, data in builder.graph.nodes(data=True):
nodes_to_process = list(builder.graph.nodes(data=True))
for node, data in nodes_to_process:
node.connect_in_graph(builder, data.get("source", {}))
check_single_node(node)
first = next(iter(builder.resources_of(cls)))
Expand Down
2 changes: 1 addition & 1 deletion plugins/aws/test/resources/ec2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def validate_delete_args(**kwargs: Any) -> None:


def test_instance() -> None:
round_trip_for(AwsEc2Instance)
round_trip_for(AwsEc2Instance, collect_also=[AwsEc2InstanceType])


def test_delete_instances() -> None:
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6ab45f4

Please sign in to comment.