40
40
)
41
41
from conftest_networking import unmarshal_az_override
42
42
from conftest_tests_config import apply_cli_dimensions_filtering , parametrize_from_config , remove_disabled_tests
43
- from conftest_utils import add_filename_markers
43
+ from conftest_utils import add_filename_markers , get_reporting_region
44
44
from constants import SCHEDULERS_SUPPORTING_IMDS_SECURED , NodeType
45
45
from filelock import FileLock
46
46
from framework .credential_providers import aws_credential_provider , register_cli_credentials_for_region
47
47
from framework .fixture_utils import xdist_session_fixture
48
- from framework .framework_constants import METADATA_DEFAULT_REGION , METADATA_TABLE
48
+ from framework .framework_constants import METADATA_TABLE
49
49
from framework .metadata_table_manager import MetadataTableManager
50
50
from framework .tests_configuration .config_renderer import read_config_file
51
51
from framework .tests_configuration .config_utils import get_all_regions
@@ -258,7 +258,7 @@ def pytest_configure(config):
258
258
_setup_custom_logger (config .getoption ("tests_log_file" ))
259
259
260
260
261
- def pytest_sessionstart (session ):
261
+ def pytest_sessionstart (session : pytest . Session ):
262
262
# The number of seconds before a connection to the instance metadata service should time out.
263
263
# When attempting to retrieve credentials on an Amazon EC2 instance that is configured with an IAM role,
264
264
# a connection to the instance metadata service will time out after 1 second by default. If you know you're
@@ -271,11 +271,6 @@ def pytest_sessionstart(session):
271
271
os .environ ["AWS_METADATA_SERVICE_NUM_ATTEMPTS" ] = "5"
272
272
# Increasing default max attempts retry
273
273
os .environ ["AWS_MAX_ATTEMPTS" ] = "10"
274
- try :
275
- # Setup the metadata table in case it doesn't exist
276
- MetadataTableManager (METADATA_DEFAULT_REGION , METADATA_TABLE ).create_metadata_table ()
277
- except Exception as exc :
278
- logging .info (f"There was a '{ type (exc )} ' error with '{ exc } ' when creating the table!" )
279
274
280
275
281
276
def pytest_fixture_setup (fixturedef : FixtureDef [Any ], request : SubRequest ) -> Optional [object ]:
@@ -309,6 +304,17 @@ def pytest_collection_modifyitems(session: pytest.Session, config: pytest.Config
309
304
310
305
def pytest_collection_finish (session ):
311
306
_log_collected_tests (session )
307
+ # Create the metadata table after the regions are collected
308
+ try :
309
+ region = session .config .getoption ("regions" ) or get_all_regions (session .config .getoption ("tests_config" ))
310
+ region = [unmarshal_az_override (az ) for az in region ]
311
+ # Use the first element of the list of regions, since there must be at least one
312
+ reporting_region = get_reporting_region (region [0 ])
313
+ logging .info (f"Metadata reporting region { reporting_region } " )
314
+ # Setup the metadata table in case it doesn't exist
315
+ MetadataTableManager (reporting_region , METADATA_TABLE ).create_metadata_table ()
316
+ except Exception as exc :
317
+ logging .info (f"There was a '{ type (exc )} ' error with '{ exc } ' when creating the table!" )
312
318
313
319
314
320
def _log_collected_tests (session ):
0 commit comments