-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix bootstrap tests failing in non-default region #10152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
S3 Image Test Results (AMD64 / ARM64) 2 files 2 suites 3m 8s ⏱️ Results for commit 707ebf9. ♻️ This comment has been updated with latest results. |
TO BE REVERTED BEFORE MERGE
LocalStack Community integration with Pro 2 files 2 suites 1h 22m 38s ⏱️ Results for commit b3686f1. ♻️ This comment has been updated with latest results. |
818483b
to
b34b0c4
Compare
b34b0c4
to
3b4bab4
Compare
@@ -164,7 +170,7 @@ def create_lambda_function( | |||
infra.add_custom_setup( | |||
lambda: load_python_lambda_to_s3( | |||
s3_client=aws_client.s3, | |||
bucket_name=infra.get_asset_bucket(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
localstack/localstack/testing/scenario/provisioning.py
Lines 102 to 105 in b3686f1
def get_asset_bucket(self): | |
account = self.aws_client.sts.get_caller_identity()["Account"] | |
region = self.aws_client.sts.meta.region_name | |
return f"localstack-testing-{account}-{region}" |
I'm not certain about the intended purpose of get_asset_bucket()
helper so I've not changed its behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense in this case, but we probably want to allow infrastructure_setup
to take account/region. Then this helper would be OK I think? cc @dominikschubert
See
localstack/tests/bootstrap/conftest.py
Lines 22 to 37 in 896ba4b
def _infrastructure_setup( | |
namespace: str, force_synth: Optional[bool] = False, port: int = constants.DEFAULT_PORT_EDGE | |
) -> InfraProvisioner: | |
""" | |
:param namespace: repo-unique identifier for this CDK app. | |
A directory with this name will be created at `tests/aws/cdk_templates/<namespace>/` | |
:param force_synth: set to True to always re-synth the CDK app | |
:return: an instantiated CDK InfraProvisioner which can be used to deploy a CDK app | |
""" | |
return InfraProvisioner( | |
base_path=cdk_template_path, | |
aws_client=aws_client_factory(endpoint_url=f"http://localhost:{port}"), | |
namespace=namespace, | |
force_synth=force_synth, | |
persist_output=True, | |
) |
We build a new client factory here without accepting region/account configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make a note of it, since I'll soon try to rework the provisioner a bit for asset support as well 👍 For now the solution seems fine, the bucket naming was mostly done for compatibility with live-AWS which isn't really relevant for bootstrap tests here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this issue. I agree this should be fixed, but I am unsure if the change you have made is correct. I have approved since it works, but this might need to be upstreamed into the CDK setup code to cover more cases. What do you think @dominikschubert?
@@ -164,7 +170,7 @@ def create_lambda_function( | |||
infra.add_custom_setup( | |||
lambda: load_python_lambda_to_s3( | |||
s3_client=aws_client.s3, | |||
bucket_name=infra.get_asset_bucket(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense in this case, but we probably want to allow infrastructure_setup
to take account/region. Then this helper would be OK I think? cc @dominikschubert
See
localstack/tests/bootstrap/conftest.py
Lines 22 to 37 in 896ba4b
def _infrastructure_setup( | |
namespace: str, force_synth: Optional[bool] = False, port: int = constants.DEFAULT_PORT_EDGE | |
) -> InfraProvisioner: | |
""" | |
:param namespace: repo-unique identifier for this CDK app. | |
A directory with this name will be created at `tests/aws/cdk_templates/<namespace>/` | |
:param force_synth: set to True to always re-synth the CDK app | |
:return: an instantiated CDK InfraProvisioner which can be used to deploy a CDK app | |
""" | |
return InfraProvisioner( | |
base_path=cdk_template_path, | |
aws_client=aws_client_factory(endpoint_url=f"http://localhost:{port}"), | |
namespace=namespace, | |
force_synth=force_synth, | |
persist_output=True, | |
) |
We build a new client factory here without accepting region/account configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -164,7 +170,7 @@ def create_lambda_function( | |||
infra.add_custom_setup( | |||
lambda: load_python_lambda_to_s3( | |||
s3_client=aws_client.s3, | |||
bucket_name=infra.get_asset_bucket(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make a note of it, since I'll soon try to rework the provisioner a bit for asset support as well 👍 For now the solution seems fine, the bucket naming was mostly done for compatibility with live-AWS which isn't really relevant for bootstrap tests here
Summary
This PR fixes the following bootstrap test when run in non-default account ID/region:
tests.bootstrap.test_cosmetic_configuration.TestLocalStackHost.test_scenario
Changes
The S3 bucket had the account ID and region hardcoded in the name within the CDK template. When the tests were run in a different account ID or region, the bucket name would be different causing the test to fail.
Tests
See
ci/circleci: bootstrap-tests
job for commit 707ebf9 🟢 - this run used non-default test credentials to demonstrate that the tests pass