Skip to content

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Feb 23, 2023

Work on APIGW Resource parity, improve UpdateResource parity (patch operations validation), remove moto patches to move them into provider directly (we still manipulates moto entities directly as its tightly integrated, but extend moto with our own store), and fix deleting child resources when deleting a resource that was used as a parent.

Example:
/ -> /pets -> /pets/dogs
We delete /pets, /pets/dogs should be deleted as well because it declared /pets to be its parent.
We do this by mapping children IDs when they are created with a parent ID. When deleting a resource, we check if it is in the parent list, and then recursively delete resources.

  • remove patches on Resource entity
  • create AWS validated tests with snapshots for resource manipulation
  • fix parity for UpdateResource (validation)
  • fix recursively deleting all child Resource when deleting a parent Resource with DeleteResource

note: I might delete the fixture for creating resource in a following PR, as we clean up all related resources when deleting the RestAPI.
note2: more tests are coming for deleting the resource with more children in a following PR. (#7746)
note3: I'd like to do a store refactor to allow easier validation of resources, see #7750

\cc @whummer

@bentsku bentsku temporarily deployed to localstack-ext-tests February 23, 2023 13:32 — with GitHub Actions Inactive
@github-actions
Copy link

github-actions bot commented Feb 23, 2023

LocalStack integration with Pro

       3 files  ±0         3 suites  ±0   1h 30m 58s ⏱️ - 2m 46s
1 762 tests +3  1 392 ✔️ +4  370 💤  - 1  0 ±0 
2 480 runs  +3  1 768 ✔️ +4  712 💤  - 1  0 ±0 

Results for commit 36b13dc. ± Comparison against base commit 145291f.

♻️ This comment has been updated with latest results.

@bentsku bentsku temporarily deployed to localstack-ext-tests February 23, 2023 20:37 — with GitHub Actions Inactive
@coveralls
Copy link

coveralls commented Feb 23, 2023

Coverage Status

Coverage: 85.091% (+0.06%) from 85.033% when pulling 36b13dc on apigw-parity-work-2 into 145291f on master.

@bentsku bentsku temporarily deployed to localstack-ext-tests February 24, 2023 09:50 — with GitHub Actions Inactive
@bentsku bentsku temporarily deployed to localstack-ext-tests February 24, 2023 12:13 — with GitHub Actions Inactive
@bentsku bentsku temporarily deployed to localstack-ext-tests February 24, 2023 15:01 — with GitHub Actions Inactive
@bentsku bentsku temporarily deployed to localstack-ext-tests February 24, 2023 16:01 — with GitHub Actions Inactive
@bentsku bentsku changed the title wip: work on APIGW Resource, improve parity work on APIGW Resource, improve parity Feb 24, 2023
@bentsku bentsku marked this pull request as ready for review February 24, 2023 18:31
@bentsku bentsku added the aws:apigateway Amazon API Gateway label Feb 24, 2023
@bentsku bentsku self-assigned this Feb 24, 2023
@bentsku bentsku changed the title work on APIGW Resource, improve parity improve parity for APIGW Resource Feb 24, 2023
@bentsku bentsku temporarily deployed to localstack-ext-tests February 25, 2023 09:59 — with GitHub Actions Inactive
Copy link
Contributor

@calvernaz calvernaz 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 doing this, I know working with the split state doesn't make it easier. LGTM 🚀

I have some comments, that can be handle in next iterations

@@ -89,6 +93,16 @@ def on_after_init(self):
def _get_moto_backend(context: RequestContext) -> apigw_models.APIGatewayBackend:
return apigw_models.apigateway_backends[context.account_id][context.region]

@staticmethod
def _remove_rest_api(context: RequestContext, rest_api_id: str) -> None:
store = get_apigateway_store(account_id=context.account_id, region=context.region)
Copy link
Contributor

Choose a reason for hiding this comment

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

it removes from Localstack store, should we check on Moto's as well ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The call_moto should take care of that as the rest API is contained there, I'm not sure how this could happen in moto

@@ -73,6 +75,25 @@ def _factory(*args, **kwargs):
delete_rest_api_retry(apigateway_client, rest_api_id)


@pytest.fixture
def apigw_create_rest_resource(apigateway_client):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious about how to create this fixture. Deleting the API container should remove most of the resources created under path, templates, etc - backend integration lingers tho. Any particular use case where this didn't happen? meaning deleting the API wasn't removing resources?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm deleting it, it was me not exactly knowing how it would behave. Thanks!

def _remove_rest_api(context: RequestContext, rest_api_id: str) -> None:
store = get_apigateway_store(account_id=context.account_id, region=context.region)
# clean up this way until we properly encapsulate RestApi in the store
store.authorizers.pop(rest_api_id, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we want to move the state from moto to localstack, in a next iteration we can functionality to the store to delete an API, basically wrapping a method to all the operation below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I'm not sure about adding methods to the store, I've seen it done in some cases, not sure what the proper way of doing it is, any idea @thrau?

Copy link
Member

Choose a reason for hiding this comment

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

there's something in the old S3 provider which wraps the moto backend with accessor/helper functions. other than that i know of no such patterns.
if you have split brain between moto and localstack stores, and it's a pain, we can look into establishing a pattern.

@@ -844,6 +972,17 @@ def filter_function(item):
# ---------------


def get_moto_rest_api(context: RequestContext, rest_api_id: str) -> MotoRestAPI:
Copy link
Contributor

Choose a reason for hiding this comment

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

we do have this method self._get_moto_backend(context) on the provider similar to this one. This one seems to handle mis-lookups, should we highlight that and remove usages of the former?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, the self._get_moto_backend(context) was from my first PR, but not sure it still makes sense now, this new method handles a bit more. If we ever need to access the moto backend to access other kind of resources and not RestAPI, we can create a new method for that resource with the proper exception message. Thanks for picking this up!

@bentsku bentsku force-pushed the apigw-parity-work-2 branch from 835ca2a to 36b13dc Compare February 27, 2023 13:53
@bentsku bentsku temporarily deployed to localstack-ext-tests February 27, 2023 13:53 — with GitHub Actions Inactive
@bentsku bentsku merged commit 9c85f6d into master Feb 28, 2023
@bentsku bentsku deleted the apigw-parity-work-2 branch February 28, 2023 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:apigateway Amazon API Gateway
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants