fix: Recognize final DELETE_COMPLETE event with verbose flag (#7979)

This commit is contained in:
devops hipster in training 2020-07-24 17:51:10 +10:00 committed by GitHub
parent e68e116c9a
commit e980625f58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 1 deletions

View File

@ -113,7 +113,7 @@ module.exports = {
(!this.options.verbose ||
(stackStatus &&
(stackStatus.endsWith('ROLLBACK_COMPLETE') ||
stackStatus === 'DELETE_FAILED')))
['DELETE_FAILED', 'DELETE_COMPLETE'].includes(stackStatus))))
) {
// empty console.log for a prettier output
if (!this.options.verbose) this.serverless.cli.consoleLog('');

View File

@ -761,6 +761,86 @@ describe('monitorStack', () => {
}
);
it(
'should throw an error if stack status is DELETE_COMPLETE and should output all ' +
'stack events information with the --verbose option',
() => {
awsPlugin.options.verbose = true;
const describeStackEventsStub = sinon.stub(awsPlugin.provider, 'request');
const cfDataMock = {
StackId: 'new-service-dev',
};
const createStartEvent = {
StackEvents: [
{
EventId: '1a2b3c4d',
StackName: 'new-service-dev',
LogicalResourceId: 'new-service-dev',
ResourceType: 'AWS::CloudFormation::Stack',
Timestamp: new Date(),
ResourceStatus: 'CREATE_IN_PROGRESS',
},
],
};
const createItemFailedEvent = {
StackEvents: [
{
EventId: '1e2f3g4h',
StackName: 'new-service-dev',
LogicalResourceId: 'myBucket',
ResourceType: 'AWS::S3::Bucket',
Timestamp: new Date(),
ResourceStatus: 'CREATE_FAILED',
ResourceStatusReason: 'Invalid Property for X',
},
],
};
const createItemDeleteEvent = {
StackEvents: [
{
EventId: '1i2j3k4l',
StackName: 'new-service-dev',
LogicalResourceId: 'myBucket',
ResourceType: 'AWS::S3::Bucket',
Timestamp: new Date(),
ResourceStatus: 'DELETE_IN_PROGRESS',
},
],
};
const createFailedEvent = {
StackEvents: [
{
EventId: '1m2n3o4p',
StackName: 'new-service-dev',
LogicalResourceId: 'new-service-dev',
ResourceType: 'AWS::CloudFormation::Stack',
Timestamp: new Date(),
ResourceStatus: 'DELETE_COMPLETE',
},
],
};
describeStackEventsStub.onCall(0).resolves(createStartEvent);
describeStackEventsStub.onCall(1).resolves(createItemFailedEvent);
describeStackEventsStub.onCall(2).resolves(createItemDeleteEvent);
describeStackEventsStub.onCall(3).resolves(createFailedEvent);
return awsPlugin.monitorStack('create', cfDataMock, { frequency: 10 }).catch(e => {
let errorMessage = 'An error occurred: ';
errorMessage += 'myBucket - Invalid Property for X.';
expect(e.name).to.be.equal('ServerlessError');
expect(e.message).to.be.equal(errorMessage);
expect(describeStackEventsStub.callCount).to.be.equal(4);
expect(
describeStackEventsStub.calledWithExactly('CloudFormation', 'describeStackEvents', {
StackName: cfDataMock.StackId,
})
).to.be.equal(true);
awsPlugin.provider.request.restore();
});
}
);
it('should record an error and fail if status is UPDATE_ROLLBACK_IN_PROGRESS', () => {
const describeStackEventsStub = sinon.stub(awsPlugin.provider, 'request');
const cfDataMock = {