Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions test/dlc_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,9 @@ def ec2_instance(
key_filename = test_utils.generate_ssh_keypair(ec2_client, ec2_key_name)

def delete_ssh_keypair():
if test_utils.is_pr_context():
test_utils.destroy_ssh_keypair(ec2_client, key_filename)
else:
with open(KEYS_TO_DESTROY_FILE, "a") as destroy_keys:
destroy_keys.write(f"{key_filename}\n")
# test_utils.destroy_ssh_keypair(ec2_client, key_filename)
with open(KEYS_TO_DESTROY_FILE, "a") as destroy_keys:
destroy_keys.write(f"{key_filename}\n")

request.addfinalizer(delete_ssh_keypair)
print(f"EC2 instance AMI-ID: {ec2_instance_ami}")
Expand Down
17 changes: 10 additions & 7 deletions test/testrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,16 @@ def delete_key_pairs(keyfile):

:param keyfile: file with all of the keys to delete
"""
with open(keyfile) as key_destroy_file:
for key_file in key_destroy_file:
LOGGER.info(key_file)
ec2_client = boto3.client("ec2", config=Config(retries={"max_attempts": 10}))
if ".pem" in key_file:
_resp, keyname = destroy_ssh_keypair(ec2_client, key_file)
LOGGER.info(f"Deleted {keyname}")
try:
with open(keyfile) as key_destroy_file:
for key_file in key_destroy_file:
LOGGER.info(f"destroying {key_file} listed in {key_destroy_file}")
ec2_client = boto3.client("ec2", config=Config(retries={"max_attempts": 10}))
if ".pem" in key_file:
_resp, keyname = destroy_ssh_keypair(ec2_client, key_file)
LOGGER.info(f"Deleted {keyname}")
except Exception as e:
LOGGER.error(f"Failed to delete key pair with exception: {e}")


def build_bai_docker_container():
Expand Down