generated from hashicorp/packer-plugin-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Deploy template error handling cleanup #296
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d7ea378
Seperate cleanup for Virtual Machines and KeyVaults to reduce noise d…
JenGoldstrich cab8d84
Add isVirtualMachineDeployment param to existing tests
JenGoldstrich 996058f
implement Wilken's feedback
JenGoldstrich 6803fea
Not sure why this change is generated by Mac
JenGoldstrich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,9 +64,10 @@ func TestStepDeployTemplateShouldTakeStepArgumentsFromStateBag(t *testing.T) { | |
|
||
return nil | ||
}, | ||
say: func(message string) {}, | ||
error: func(e error) {}, | ||
name: "--deployment-name--", | ||
say: func(message string) {}, | ||
error: func(e error) {}, | ||
name: "--deployment-name--", | ||
templateType: VirtualMachineTemplate, | ||
} | ||
|
||
stateBag := createTestStateBagStepValidateTemplate() | ||
|
@@ -89,9 +90,10 @@ func TestStepDeployTemplateShouldTakeStepArgumentsFromStateBag(t *testing.T) { | |
|
||
func TestStepDeployTemplateDeleteImageShouldFailWhenImageUrlCannotBeParsed(t *testing.T) { | ||
var testSubject = &StepDeployTemplate{ | ||
say: func(message string) {}, | ||
error: func(e error) {}, | ||
name: "--deployment-name--", | ||
say: func(message string) {}, | ||
error: func(e error) {}, | ||
name: "--deployment-name--", | ||
templateType: VirtualMachineTemplate, | ||
} | ||
// Invalid URL per https://golang.org/src/net/url/url_test.go | ||
err := testSubject.deleteImage(context.TODO(), "http://[fe80::1%en0]/", "Unit Test: ResourceGroupName", false) | ||
|
@@ -102,9 +104,10 @@ func TestStepDeployTemplateDeleteImageShouldFailWhenImageUrlCannotBeParsed(t *te | |
|
||
func TestStepDeployTemplateDeleteImageShouldFailWithInvalidImage(t *testing.T) { | ||
var testSubject = &StepDeployTemplate{ | ||
say: func(message string) {}, | ||
error: func(e error) {}, | ||
name: "--deployment-name--", | ||
say: func(message string) {}, | ||
error: func(e error) {}, | ||
name: "--deployment-name--", | ||
templateType: VirtualMachineTemplate, | ||
} | ||
err := testSubject.deleteImage(context.TODO(), "storage.blob.core.windows.net/abc", "Unit Test: ResourceGroupName", false) | ||
if err == nil { | ||
|
@@ -114,7 +117,7 @@ func TestStepDeployTemplateDeleteImageShouldFailWithInvalidImage(t *testing.T) { | |
|
||
func TestStepDeployTemplateCleanupShouldDeleteManagedOSImageInExistingResourceGroup(t *testing.T) { | ||
var deleteDiskCounter = 0 | ||
var testSubject = createTestStepDeployTemplateDeleteOSImage(&deleteDiskCounter) | ||
var testSubject = createTestStepDeployTemplateDeleteOSImage(&deleteDiskCounter, VirtualMachineTemplate) | ||
|
||
stateBag := createTestStateBagStepDeployTemplate() | ||
stateBag.Put(constants.ArmIsManagedImage, true) | ||
|
@@ -132,7 +135,7 @@ func TestStepDeployTemplateCleanupShouldDeleteManagedOSImageInExistingResourceGr | |
|
||
func TestStepDeployTemplateCleanupShouldDeleteManagedOSImageInTemporaryResourceGroup(t *testing.T) { | ||
var deleteDiskCounter = 0 | ||
var testSubject = createTestStepDeployTemplateDeleteOSImage(&deleteDiskCounter) | ||
var testSubject = createTestStepDeployTemplateDeleteOSImage(&deleteDiskCounter, VirtualMachineTemplate) | ||
|
||
stateBag := createTestStateBagStepDeployTemplate() | ||
stateBag.Put(constants.ArmIsManagedImage, true) | ||
|
@@ -150,7 +153,7 @@ func TestStepDeployTemplateCleanupShouldDeleteManagedOSImageInTemporaryResourceG | |
|
||
func TestStepDeployTemplateCleanupShouldDeleteVHDOSImageInExistingResourceGroup(t *testing.T) { | ||
var deleteDiskCounter = 0 | ||
var testSubject = createTestStepDeployTemplateDeleteOSImage(&deleteDiskCounter) | ||
var testSubject = createTestStepDeployTemplateDeleteOSImage(&deleteDiskCounter, VirtualMachineTemplate) | ||
|
||
stateBag := createTestStateBagStepDeployTemplate() | ||
stateBag.Put(constants.ArmIsManagedImage, false) | ||
|
@@ -168,7 +171,7 @@ func TestStepDeployTemplateCleanupShouldDeleteVHDOSImageInExistingResourceGroup( | |
|
||
func TestStepDeployTemplateCleanupShouldVHDOSImageInTemporaryResourceGroup(t *testing.T) { | ||
var deleteDiskCounter = 0 | ||
var testSubject = createTestStepDeployTemplateDeleteOSImage(&deleteDiskCounter) | ||
var testSubject = createTestStepDeployTemplateDeleteOSImage(&deleteDiskCounter, VirtualMachineTemplate) | ||
|
||
stateBag := createTestStateBagStepDeployTemplate() | ||
stateBag.Put(constants.ArmIsManagedImage, false) | ||
|
@@ -184,6 +187,24 @@ func TestStepDeployTemplateCleanupShouldVHDOSImageInTemporaryResourceGroup(t *te | |
} | ||
} | ||
|
||
func TestStepDeployTemplateCleanupShouldNotDeleteDiskForKeyVaultDeployments(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice test |
||
var deleteDiskCounter = 0 | ||
var testSubject = createTestStepDeployTemplateDeleteOSImage(&deleteDiskCounter, KeyVaultTemplate) | ||
|
||
stateBag := createTestStateBagStepDeployTemplate() | ||
stateBag.Put(constants.ArmIsManagedImage, false) | ||
stateBag.Put(constants.ArmIsSIGImage, false) | ||
stateBag.Put(constants.ArmIsExistingResourceGroup, true) | ||
stateBag.Put(constants.ArmIsResourceGroupCreated, true) | ||
stateBag.Put(constants.ArmKeepOSDisk, false) | ||
stateBag.Put("ui", packersdk.TestUi(t)) | ||
|
||
testSubject.Cleanup(stateBag) | ||
if deleteDiskCounter != 0 { | ||
t.Fatalf("Expected DeployTemplate Cleanup to not invoke deleteDisk, but invoked %d times", deleteDiskCounter) | ||
} | ||
} | ||
|
||
func createTestStateBagStepDeployTemplate() multistep.StateBag { | ||
stateBag := new(multistep.BasicStateBag) | ||
|
||
|
@@ -194,7 +215,7 @@ func createTestStateBagStepDeployTemplate() multistep.StateBag { | |
return stateBag | ||
} | ||
|
||
func createTestStepDeployTemplateDeleteOSImage(deleteDiskCounter *int) *StepDeployTemplate { | ||
func createTestStepDeployTemplateDeleteOSImage(deleteDiskCounter *int, templateType DeploymentTemplateType) *StepDeployTemplate { | ||
return &StepDeployTemplate{ | ||
deploy: func(context.Context, string, string) error { return nil }, | ||
say: func(message string) {}, | ||
|
@@ -212,5 +233,6 @@ func createTestStepDeployTemplateDeleteOSImage(deleteDiskCounter *int) *StepDepl | |
deleteDeployment: func(ctx context.Context, state multistep.StateBag) error { | ||
return nil | ||
}, | ||
templateType: templateType, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We regularly fail to delete attached network resources related to the resource being still attached, this leads to a lot of spam in the output, here I've changed this to only log the error when we fail for real, since almost every build I run fails this check at least once for at least two different resources.