contract_delete_create failure comparing auto-assigned ID
See original GitHub issueHi, when I run cfn test, I get a failure with contract_delete_create.
The issue is that the API I’m wrapping (SendGrid) assigns a UserId to each resource that is created (Subuser) - this is distinct from the name that the resource is created with / referred to by (SubuserName). So, when a resource is deleted and then re-created, it gets a different UserId, and delete_create fails when they don’t match.
{‘UserId’: 15238207} != {‘UserId’: 15238208}
I’ve marked UserId as a readOnlyProperty, and tried other combinations with primaryIdentifier, additionalIdentifier, etc. I’m looking for a way for it not to be compared in this test. Is there a way to specify in the schema, or does the test need to be changed?
I see a related bug at #329 but that’s marked as closed and I’m still seeing this issue.
$ sam --version SAM CLI, version 0.43.0 $ cfn --version cfn 0.1.2
Test output is below, and the resource schema follows.
__________ contract_delete_create ____________________________________________________________________
resource_client = <rpdk.core.contract.resource_client.ResourceClient object at 0x1058ca650>
deleted_resource = ({'Email': 'zaa@aaaaaa.com', 'Ips': None, 'Password': None, 'SubuserName': 'aaa@aaaaaa.com', ...}, {'Email': 'zaa@aaaa..., 'Ips': ['149.72.51.36'], 'Password': 'aaA0aA0aA0aA0aA0aA0aA0aA0aA0aA0aA0aA01', 'SubuserName': 'aaa@aaaaaa.com', ...})
@pytest.mark.create
@pytest.mark.delete
def contract_delete_create(resource_client, deleted_resource):
deleted_model, request = deleted_resource
response = test_create_success(resource_client, request)
# read-only properties should be excluded from the comparison
prune_properties(deleted_model, resource_client.read_only_paths)
prune_properties(response["resourceModel"], resource_client.read_only_paths)
> assert deleted_model == response["resourceModel"]
E AssertionError: assert {'Email': 'za...aaa.com', ...} == {'Email': 'zaa...aaa.com', ...}
E Omitting 4 identical items, use -vv to show
E Differing items:
E {'UserId': 15237106} != {'UserId': 15237108}
E Full diff:
E {'Email': 'zaa@aaaaaa.com',
E 'Ips': None,
E 'Password': None,...
E
E ...Full output truncated (6 lines hidden), use '-vv' to show
/usr/local/lib/python3.7/site-packages/rpdk/core/contract/suite/handler_delete.py:89: AssertionError
--------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------
Sending request
{
"credentials": {
...
},
"action": "CREATE",
"request": {
"clientRequestToken": "913aa4e8-66ce-487e-9799-6938c0ee9d73",
"desiredResourceState": {
"Email": "zaa@aaaaaa.com",
"Ips": [
"149.72.51.36"
],
"Password": "aaA0aA0aA0aA0aA0aA0aA0aA0aA0aA0aA0aA01",
"SubuserName": "aaa@aaaaaa.com",
"UserId": 0.0
},
"previousResourceState": null,
"logicalResourceIdentifier": null
},
"callbackContext": null
}
Received response
{'status': 'SUCCESS', 'message': '', 'callbackDelaySeconds': 0, 'resourceModel': {'SubuserName': 'aaa@aaaaaa.com', 'Email': 'zaa@aaaaaa.com', 'Password': None, 'Ips': None, 'UserId': 15237108}}
------------------------------------------------------------------- Captured stdout teardown -------------------------------------------------------------------
Sending request
{
"credentials": {
...
},
"action": "DELETE",
"request": {
"clientRequestToken": "b75bf4a7-f57a-4c91-aafd-58cbda719662",
"desiredResourceState": {
"SubuserName": "aaa@aaaaaa.com",
"Email": "zaa@aaaaaa.com",
"Password": null,
"Ips": null,
"UserId": 15237106
},
"previousResourceState": null,
"logicalResourceIdentifier": null
},
"callbackContext": null
}
Received response
{'status': 'SUCCESS', 'message': '', 'callbackDelaySeconds': 0, 'resourceModel': {'SubuserName': 'aaa@aaaaaa.com', 'Email': 'zaa@aaaaaa.com', 'Password': None, 'Ips': None, 'UserId': 15237106}}
schema.json
{
"typeName": "Nextdoor::SendGridUser::Test",
"description": "Test cfn resource provider for SendGrid subusers.",
"sourceUrl": "https://github.com/aws-cloudformation/aws-cloudformation-rpdk.git",
"definitions": {
},
"properties": {
"SubuserName": {
"description": "foo",
"type": "string",
"pattern": "^[a-z]{3}@[a-z]{6}\\.com$"
},
"Email": {
"type": "string",
"pattern": "^[a-z]{3}@[a-z]{6}\\.com$"
},
"Password": {
"type": "string",
"pattern": "^a([a-z][A-Z][0-9]){12}1$"
},
"Ips": {
"type": "array",
"items": {
"type": "string",
"pattern": "^149\\.72\\.51\\.36$"
},
"maxItems": 1,
"minItems": 1
},
"UserId": {
"type": "number"
}
},
"required": [
"SubuserName",
"Email",
"Password",
"Ips",
"UserId"
],
"readOnlyProperties": [
"/properties/UserId"
],
"writeOnlyProperties": [
"/properties/Password"
],
"createOnlyProperties": [
"/properties/SubuserName",
"/properties/UserId"
],
"primaryIdentifier": [
"/properties/SubuserName"
],
"additionalIdentifiers": [
[
"/properties/UserId"
]
],
"handlers": {
"create": {
"permissions": [""]
},
"read": {
"permissions": [""]
},
"delete": {
"permissions": [""]
},
"list": {
"permissions": [""]
}
},
"additionalProperties": false
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
I’m not sure this will solve your issue:
I assume you want to remove UserId from the required properties (you don’t have to specify it in CloudFormation to use the resource, it’s autogenerated).
You probably also want to switch UserId and SubuserName as primaryIdentifier / additionalIdentifiers
And now, much later I restarted the same environment (this re-activating a venv) and now everything passes. This is puzzling. Closing. Thanks for your help, I think the upgrade must have helped.