mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cloudformation): answer DescribeStackEvents on a missing stack with AWS's wording (#4301)
DescribeStackEvents reported a missing stack as "Stack with id <name> does not exist", the DescribeStacks wording; AWS says "Stack [<name>] does not exist" for this operation, and clients tell the two apart by text. The CDK's stack-event poller swallows exactly the bracketed form once the stack it watches has been deleted, so Floci's wording escaped as an error from the monitor's final poll and cdk destroy --all stopped after its first stack (exit 1, remaining stacks left in place). With the wording alone corrected, the same two-stack destroy --all destroys both and exits 0; the by-name ValidationError after a delete stays, as on AWS. Closes #4235
This commit is contained in:
1 parent
6d95dfe3e1
commit
35605937c8
2 files changed
+83
-1
No files matched your search
+9
-1
@@ -1068,11 +1068,19 @@ public class CloudFormationService implements ResourceProvider {
|
||||
|
||||
// ── DescribeStackEvents ───────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* The missing-stack message is the one AWS uses for this operation, {@code Stack [name] does
|
||||
* not exist}, which differs from DescribeStacks' {@code Stack with id name does not exist}.
|
||||
* Clients tell the two apart by text: the CDK's stack-event poller swallows exactly the
|
||||
* bracketed form once a stack it is watching has been deleted (its stack lookup swallows the
|
||||
* other), so any other wording escapes the poller and fails {@code cdk destroy --all} after
|
||||
* the first stack.
|
||||
*/
|
||||
public List<StackEvent> describeStackEvents(String stackName, String region) {
|
||||
Stack stack = resolveStackForDescribe(stackName, region);
|
||||
if (stack == null) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Stack with id " + stackName + " does not exist", 400);
|
||||
"Stack [" + stackName + "] does not exist", 400);
|
||||
}
|
||||
List<StackEvent> events = stack.eventsSnapshot();
|
||||
Collections.reverse(events);
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
/**
|
||||
* What a client polling a deleted stack by name gets back, per operation. The two wordings are
|
||||
* AWS's and clients match on them: the CDK's stack lookup treats DescribeStacks'
|
||||
* {@code Stack with id X does not exist} as "gone", and its event poller treats DescribeStackEvents'
|
||||
* {@code Stack [X] does not exist} the same way; either wording on the wrong operation escapes
|
||||
* as an error, which is how {@code cdk destroy --all} used to stop after the first stack (#4235).
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudFormationDeletedStackByNameIntegrationTest {
|
||||
|
||||
private static final String CFN_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/cloudformation/aws4_request";
|
||||
|
||||
@Test
|
||||
void describeStackEventsOnADeletedStackUsesTheBracketedWording() {
|
||||
String stackName = "deleted-by-name-" + Long.toString(System.nanoTime(), 36);
|
||||
cfn("CreateStack", stackName, "{\"Resources\":{\"P\":{\"Type\":\"AWS::SSM::Parameter\","
|
||||
+ "\"Properties\":{\"Type\":\"String\",\"Value\":\"v\"}}}}").then().statusCode(200);
|
||||
cfn("DeleteStack", stackName, null).then().statusCode(200);
|
||||
awaitGone(stackName);
|
||||
|
||||
cfn("DescribeStackEvents", stackName, null).then().statusCode(400)
|
||||
.body(containsString("<Code>ValidationError</Code>"))
|
||||
.body(containsString("<Message>Stack [" + stackName + "] does not exist</Message>"));
|
||||
cfn("DescribeStacks", stackName, null).then().statusCode(400)
|
||||
.body(containsString("<Code>ValidationError</Code>"))
|
||||
.body(containsString("<Message>Stack with id " + stackName + " does not exist</Message>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeStackEventsOnAStackThatNeverExistedUsesTheSameWording() {
|
||||
cfn("DescribeStackEvents", "never-created", null).then().statusCode(400)
|
||||
.body(containsString("<Message>Stack [never-created] does not exist</Message>"));
|
||||
}
|
||||
|
||||
private static Response cfn(String action, String stackName, String template) {
|
||||
RequestSpecification request = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", action)
|
||||
.formParam("StackName", stackName);
|
||||
if (template != null) {
|
||||
request = request.formParam("TemplateBody", template);
|
||||
}
|
||||
return request.when().post("/");
|
||||
}
|
||||
|
||||
/** Deletion runs on an executor; wait until the name no longer resolves. */
|
||||
private static void awaitGone(String stackName) {
|
||||
long deadline = System.currentTimeMillis() + 30_000;
|
||||
while (System.currentTimeMillis() < deadline) {
|
||||
if (cfn("DescribeStacks", stackName, null).statusCode() == 400) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("stack " + stackName + " still resolves by name after its delete");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user