Skip to content
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

Fixing some of the contract tests for Domain. #22

Merged
merged 2 commits into from
Aug 24, 2020

Conversation

jonjara
Copy link
Contributor

@jonjara jonjara commented Aug 17, 2020

Issue #, if available:

Description of changes:
Adding in some fixes that make the handlers to adhere to https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html.

contract_invalid_create still doesn't pass and I am going to reach out to CloudFormation to get guidance on this test

NOTES:

  • I am manually adding in arns to the ListHandlers but we will not do this when ListDomains populates the arn in it's sdk response. The reason it's needed is because the primary identifier needs to be populated after a list operation
  • Also removing domainOwner from some of the operations because I am assuming that for for update/read permissions policies and describe domain, we are always doing so in the account the CFN stack is in.

Testing

handler_create.py::contract_create_delete PASSED                         [  6%]
handler_create.py::contract_invalid_create PASSED                        [ 12%]
handler_create.py::contract_create_duplicate SKIPPED                     [ 18%]
handler_create.py::contract_create_read_success PASSED                   [ 25%]
handler_create.py::contract_create_list_success PASSED                   [ 31%]
handler_delete.py::contract_delete_read PASSED                           [ 37%]
handler_delete.py::contract_delete_list PASSED                           [ 43%]
handler_delete.py::contract_delete_update PASSED                         [ 50%]
handler_delete.py::contract_delete_delete PASSED                         [ 56%]
handler_delete.py::contract_delete_create SKIPPED                        [ 62%]
handler_misc.py::contract_check_asserts_work PASSED                      [ 68%]
handler_read.py::contract_read_without_create PASSED                     [ 75%]
handler_update.py::contract_update_read_success PASSED                   [ 81%]
handler_update.py::contract_update_list_success PASSED                   [ 87%]
handler_update_invalid.py::contract_update_create_only_property PASSED   [ 93%]
handler_update_invalid.py::contract_update_non_existent_resource PASSED  [100%]

When I run the tests that ERROR by themselves they pass

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment on lines 45 to 39
if (!doesDomainExist(request.getDesiredResourceState(), proxyClient, request)) {
throw new CfnNotFoundException(request.getDesiredResourceState().getDomainName(), ResourceModel.TYPE_NAME);
}

Choose a reason for hiding this comment

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

This is interesting to me as I know that a bunch of other CFN resources will not throw an exception if we are trying to delete something that is already deleted.... Do you know if this would show up in the console? Or if this is magically handled by CFN to be OK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just ran a test, internally the exception gets thrown. From the logs:

Resource of type 'domain-name' with identifier 'AWS::CodeArtifact::Domain' was not found. in a DELETE action on a AWS::CodeArtifact::Domain: software.amazon.cloudformation.exceptions.CfnNotFoundException: Resource of type 'poc-domain' with identifier 'AWS::CodeArtifact::Domain' was not found.

In the console, the stack ends up in DELETE_COMPLETE, so it seems to be handled

return streamOfOrEmpty(awsResponse.domains())
.map(domain -> ResourceModel.builder()
.arn(buildArn("us-west-2", domain.owner(), domain.name()))

Choose a reason for hiding this comment

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

why are we hardcoding us-west-2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cfn test does not override regions and defaults to us-west-2, I hardcoded this and forgot to remove it :(

Comment on lines 190 to 197
final String partition = "aws";
if (region.contains("us-gov-")) {
partition.concat("-us-gov");
}

if (region.contains("cn-")) {
partition.concat("-cn");
}

Choose a reason for hiding this comment

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

I get that this is temporary until we can get the ListDomains to return the Arns, but i am surprised at the very least that there isnt some magic "give me my partition" in the CFN toolkit here. I know if you create a Region object (from sddv2) you can get the partition.

Comment on lines 91 to 93
String accountId = request.getAwsAccountId();
return GetDomainPermissionsPolicyRequest.builder()
.domain(model.getDomainName())
.domainOwner(accountId)
.build();

Choose a reason for hiding this comment

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

kinda odd that we were first using the caller's accountId instead of just grabbing it from the model itself

and now we are just omitting it. I get that the caller should be the domain owner in this case. But if we decide that anyone can create an independent resource for a DomainPolicy, we might pass in the domain Owner to that method and that would then need to be translated accordingly

@jonjara jonjara force-pushed the domain-contract-tests branch 4 times, most recently from 82e2fcb to f20a56b Compare August 19, 2020 23:25
@jonjara jonjara force-pushed the domain-contract-tests branch from f20a56b to 54f130c Compare August 20, 2020 05:45
Copy link

@joeymarylander joeymarylander left a comment

Choose a reason for hiding this comment

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

My comments are just nits. If you want to include them in another PR thats fine. If you ignore them, ill probably forget and tell you to do them in another PR haha, so up to you how you want to handle them


public abstract class BaseHandlerStd extends BaseHandler<CallbackContext> {

public static final ObjectMapper MAPPER = new ObjectMapper();

Choose a reason for hiding this comment

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

nit, this should be private, or if you're using this in subclasses, then protected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updating

Comment on lines +89 to 96
try {
proxyClient.injectCredentialsAndInvokeV2(
Translator.translateToReadRequest(model, request), proxyClient.client()::describeDomain);
return true;
} catch (ResourceNotFoundException e) {
return false;
}
}

Choose a reason for hiding this comment

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

not sure if this little green squares mean you have weird whitespace or something. Maybe accidentally had a couple of tabs instead of spaces?

@@ -24,44 +23,43 @@
final Logger logger) {

this.logger = logger;
ResourceModel model = request.getDesiredResourceState();
// STEP 1.0 [initialize a proxy context]
ProgressEvent<ResourceModel, CallbackContext> test = proxy

Choose a reason for hiding this comment

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

nit, i'd call this something other than test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, I was supposed to change this to something meaningful..

@jonjara jonjara force-pushed the domain-contract-tests branch from 4dc59b0 to 53ba117 Compare August 24, 2020 18:06
@jonjara jonjara merged commit 78a850c into aws-cloudformation:main Aug 24, 2020
Comment on lines +44 to 46
"type": "object",
"minLength": 2,
"maxLength": 5120
Copy link
Contributor

@PatMyron PatMyron Nov 3, 2020

Choose a reason for hiding this comment

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

#60
minLength/maxLength is specifically for string types
issue to catch these automatically

Suggested change
"type": "object",
"minLength": 2,
"maxLength": 5120
"type": "object",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants