Skip to content

Commit

Permalink
fix: Remove ENI manual deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
jfuss committed Jun 12, 2024
1 parent bbe98a5 commit 79a2981
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import time
from pathlib import Path

import boto3
Expand Down Expand Up @@ -61,29 +60,6 @@ def clean_all_integ_buckets():
clean_bucket(bucket.name, s3_client)


def _delete_unused_network_interface_by_subnet(ec2_client, subnet_id):
"""Deletes unused network interface under the provided subnet"""
paginator = ec2_client.get_paginator("describe_network_interfaces")
response_iterator = paginator.paginate(
Filters=[
{"Name": "subnet-id", "Values": [subnet_id]},
{"Name": "status", "Values": ["available"]},
]
)
network_interface_ids = []
for page in response_iterator:
network_interface_ids += [ni["NetworkInterfaceId"] for ni in page["NetworkInterfaces"]]

for ni_id in network_interface_ids:
try:
ec2_client.delete_network_interface(NetworkInterfaceId=ni_id)
except ClientError as e:
LOG.error("Unable to delete network interface %s", ni_id, exc_info=e)
time.sleep(0.5)

LOG.info("Deleted %s unused network interfaces under subnet %s", len(network_interface_ids), subnet_id)


@pytest.fixture()
def setup_companion_stack_once(tmpdir_factory, get_prefix):
tests_integ_dir = Path(__file__).resolve().parents[1]
Expand All @@ -95,15 +71,6 @@ def setup_companion_stack_once(tmpdir_factory, get_prefix):
companion_stack = Stack(stack_name, companion_stack_tempalte_path, cfn_client, output_dir)
companion_stack.create_or_update(_stack_exists(stack_name))

ec2_client = ClientProvider().ec2_client
precreated_subnet_ids = [
resource["PhysicalResourceId"]
for resource in companion_stack.stack_resources["StackResourceSummaries"]
if resource["LogicalResourceId"].startswith("PreCreatedSubnet")
]
for subnet_id in precreated_subnet_ids:
_delete_unused_network_interface_by_subnet(ec2_client, subnet_id)


@pytest.fixture()
def get_serverless_application_repository_app():
Expand Down

0 comments on commit 79a2981

Please sign in to comment.