Skip to content

Conversation

viren-nadkarni
Copy link
Member

@viren-nadkarni viren-nadkarni commented Jan 31, 2024

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

@viren-nadkarni viren-nadkarni self-assigned this Jan 31, 2024
@viren-nadkarni viren-nadkarni added the semver: patch Non-breaking changes which can be included in patch releases label Jan 31, 2024
Copy link

github-actions bot commented Jan 31, 2024

S3 Image Test Results (AMD64 / ARM64)

  2 files    2 suites   3m 8s ⏱️
386 tests 335 ✅  51 💤 0 ❌
772 runs  670 ✅ 102 💤 0 ❌

Results for commit 707ebf9.

♻️ This comment has been updated with latest results.

TO BE REVERTED BEFORE MERGE
Copy link

github-actions bot commented Jan 31, 2024

LocalStack Community integration with Pro

    2 files      2 suites   1h 22m 38s ⏱️
2 618 tests 2 370 ✅ 248 💤 0 ❌
2 620 runs  2 370 ✅ 250 💤 0 ❌

Results for commit b3686f1.

♻️ This comment has been updated with latest results.

@viren-nadkarni viren-nadkarni force-pushed the bootstrap-tests-xaccount branch from 818483b to b34b0c4 Compare February 1, 2024 06:46
@viren-nadkarni viren-nadkarni force-pushed the bootstrap-tests-xaccount branch from b34b0c4 to 3b4bab4 Compare February 1, 2024 06:57
@@ -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(),
Copy link
Member Author

@viren-nadkarni viren-nadkarni Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

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

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.

Copy link
Member

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

@viren-nadkarni viren-nadkarni marked this pull request as ready for review February 1, 2024 10:46
Copy link
Contributor

@simonrw simonrw left a 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(),
Copy link
Contributor

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

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.

Copy link
Member

@dominikschubert dominikschubert left a 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(),
Copy link
Member

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

@viren-nadkarni viren-nadkarni merged commit 75042c5 into master Feb 5, 2024
@viren-nadkarni viren-nadkarni deleted the bootstrap-tests-xaccount branch February 5, 2024 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants