Skip to content

Commit a19c327

Browse files
Create a table in each partition's reporting region, instead of just us-east-1 (#6352)
1 parent 0d5be94 commit a19c327

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

tests/integration-tests/conftest.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
)
4141
from conftest_networking import unmarshal_az_override
4242
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
4444
from constants import SCHEDULERS_SUPPORTING_IMDS_SECURED, NodeType
4545
from filelock import FileLock
4646
from framework.credential_providers import aws_credential_provider, register_cli_credentials_for_region
4747
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
4949
from framework.metadata_table_manager import MetadataTableManager
5050
from framework.tests_configuration.config_renderer import read_config_file
5151
from framework.tests_configuration.config_utils import get_all_regions
@@ -258,7 +258,7 @@ def pytest_configure(config):
258258
_setup_custom_logger(config.getoption("tests_log_file"))
259259

260260

261-
def pytest_sessionstart(session):
261+
def pytest_sessionstart(session: pytest.Session):
262262
# The number of seconds before a connection to the instance metadata service should time out.
263263
# When attempting to retrieve credentials on an Amazon EC2 instance that is configured with an IAM role,
264264
# 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):
271271
os.environ["AWS_METADATA_SERVICE_NUM_ATTEMPTS"] = "5"
272272
# Increasing default max attempts retry
273273
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!")
279274

280275

281276
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
309304

310305
def pytest_collection_finish(session):
311306
_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!")
312318

313319

314320
def _log_collected_tests(session):

tests/integration-tests/conftest_utils.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@
2323
import yaml
2424
from conftest_markers import DIMENSIONS_MARKER_ARGS
2525
from filelock import FileLock
26-
from framework.framework_constants import METADATA_DEFAULT_REGION, METADATA_TABLE
26+
from framework.framework_constants import METADATA_TABLE
2727
from framework.metadata_table_manager import MetadataTableManager, PhaseMetadata, TestMetadata
2828
from framework.metrics_publisher import Metric, MetricsPublisher
2929
from time_utils import microseconds
30-
from utils import dict_add_nested_key, dict_has_nested_key
30+
from utils import (
31+
DEFAULT_PARTITION,
32+
DEFAULT_REPORTING_REGION,
33+
PARTITION_MAP,
34+
REPORTING_REGION_MAP,
35+
dict_add_nested_key,
36+
dict_has_nested_key,
37+
)
3138

3239

3340
def add_properties_to_report(item: pytest.Item):
@@ -169,8 +176,9 @@ def create_phase_metrics(item: pytest.Item, rep: pytest.TestReport, dimensions:
169176

170177
def publish_test_metadata(item: pytest.Item, rep: pytest.TestReport):
171178
"""Publish test metadata to the metadata table."""
172-
metadata_table_mgr = MetadataTableManager(METADATA_DEFAULT_REGION, METADATA_TABLE)
173-
logging.info(f"Publishing test metadata: item {item} rep {rep}")
179+
reporting_region = get_reporting_region(get_user_prop(item, "region"))
180+
metadata_table_mgr = MetadataTableManager(reporting_region, METADATA_TABLE)
181+
logging.info(f"Publishing test metadata: item {item} rep {rep} to {METADATA_TABLE} in {reporting_region}")
174182
test_metadata = None
175183
if rep.when == "setup":
176184
# Initialize the test data
@@ -218,3 +226,15 @@ def publish_test_metadata(item: pytest.Item, rep: pytest.TestReport):
218226
item.user_properties.append(("metadata", jsonpickle.encode(test_metadata)))
219227
logging.info(f"Added the metadata during the {rep.when} phase: {get_user_prop(item, 'metadata')}")
220228
metadata_table_mgr.publish_metadata([test_metadata])
229+
230+
231+
def get_reporting_region(region: str):
232+
"""Get partition for the given region. If region is None, consider the region set in the environment."""
233+
curr_partition = next(
234+
(partition for region_prefix, partition in PARTITION_MAP.items() if region.startswith(region_prefix)),
235+
DEFAULT_PARTITION,
236+
)
237+
return next(
238+
(region for partition, region in REPORTING_REGION_MAP.items() if partition == curr_partition),
239+
DEFAULT_REPORTING_REGION,
240+
)

tests/integration-tests/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
"us-iso-": "aws-iso",
3737
"us-isob": "aws-iso-b",
3838
}
39+
DEFAULT_REPORTING_REGION = "us-east-1"
40+
# This map is based on where jenkins is deployed
41+
REPORTING_REGION_MAP = {
42+
"aws-cn": "cn-north-1",
43+
"aws-us-gov": "us-gov-west-1",
44+
"aws-iso": "us-iso-east-1",
45+
"aws-iso-b": "us-isob-east-1",
46+
}
3947

4048

4149
def _format_stack_error(message, stack_events=None, cluster_details=None) -> str:

0 commit comments

Comments
 (0)