From 9b83329a04918791bcdb97f3187637c192c5d7c1 Mon Sep 17 00:00:00 2001 From: Thilak KN Date: Fri, 24 Apr 2026 20:09:47 +0530 Subject: [PATCH] fix(resources_aws): improve the aws credentials sourcing logic by offloading the selection logic to boto3. --- os_tests/libs/resources_aws.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/os_tests/libs/resources_aws.py b/os_tests/libs/resources_aws.py index f7e83135..32f5b99b 100644 --- a/os_tests/libs/resources_aws.py +++ b/os_tests/libs/resources_aws.py @@ -4,6 +4,7 @@ import time import sys import re +import os try: import boto3 from botocore.exceptions import ClientError @@ -23,8 +24,9 @@ def __init__(self, params, vendor="redhat"): LOG.info('Init EC2VM resource') config = Config(retries=dict(max_attempts=10, )) self.profile_name = params.get('profile_name') - if self.profile_name is None: - LOG.info('No profile_name provided, leave boto3 to detect authentication methods') + # Let boto3 choose where it can source the auth credentials from + if self.profile_name is None or os.environ.get('AWS_ACCESS_KEY_ID') is not None: + LOG.info('Let boto3 detect authentication methods and source credentials') self.session = boto3.session.Session(region_name=params.get("region")) else: LOG.info('Load profile_name: {}'.format(self.profile_name)) @@ -687,8 +689,8 @@ def __init__(self, params): LOG.info('Init EC2Volume resource') config = Config(retries=dict(max_attempts=10, )) self.profile_name = params.get('profile_name') - if self.profile_name is None: - LOG.info('No profile_name provided, leave boto3 to detect authentication methods') + if self.profile_name is None or os.environ.get('AWS_ACCESS_KEY_ID') is not None: + LOG.info('Let boto3 detect authentication methods and source credentials') self.session = boto3.session.Session(region_name=params.get("region")) else: LOG.info('Load profile_name: {}'.format(self.profile_name)) @@ -877,8 +879,8 @@ def __init__(self, params): LOG.info('Init EC2NIC resource') config = Config(retries=dict(max_attempts=10, )) self.profile_name = params.get('profile_name') - if self.profile_name is None: - LOG.info('No profile_name provided, leave boto3 to detect authentication methods') + if self.profile_name is None or os.environ.get('AWS_ACCESS_KEY_ID') is not None: + LOG.info('Let boto3 detect authentication methods and source credentials') self.session = boto3.session.Session(region_name=params.get("region")) else: LOG.info('Load profile_name: {}'.format(self.profile_name))