From 5700f74c8c1b5e68177992760451276b8661405f Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Wed, 12 Aug 2020 11:27:07 -0400 Subject: [PATCH] Handle lease not present error --- builder/azure/arm/step_delete_additional_disks.go | 5 +++-- builder/azure/arm/step_deploy_template.go | 7 +++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builder/azure/arm/step_delete_additional_disks.go b/builder/azure/arm/step_delete_additional_disks.go index eb7a8b706..df3cc930d 100644 --- a/builder/azure/arm/step_delete_additional_disks.go +++ b/builder/azure/arm/step_delete_additional_disks.go @@ -35,12 +35,13 @@ func NewStepDeleteAdditionalDisks(client *AzureClient, ui packer.Ui) *StepDelete func (s *StepDeleteAdditionalDisk) deleteBlob(storageContainerName string, blobName string) error { blob := s.client.BlobStorageClient.GetContainerReference(storageContainerName).GetBlobReference(blobName) - if _, err := blob.BreakLease(nil); err != nil { + _, err := blob.BreakLease(nil) + if err != nil && !strings.Contains(err.Error(), "LeaseNotPresentWithLeaseOperation") { s.say(s.client.LastError.Error()) return err } - err := blob.Delete(nil) + err = blob.Delete(nil) if err != nil { s.say(s.client.LastError.Error()) } diff --git a/builder/azure/arm/step_deploy_template.go b/builder/azure/arm/step_deploy_template.go index ace8de1e8..255903098 100644 --- a/builder/azure/arm/step_deploy_template.go +++ b/builder/azure/arm/step_deploy_template.go @@ -258,12 +258,11 @@ func (s *StepDeployTemplate) deleteImage(ctx context.Context, imageType string, var blobName = strings.Join(xs[2:], "/") blob := s.client.BlobStorageClient.GetContainerReference(storageAccountName).GetBlobReference(blobName) - if _, err := blob.BreakLease(nil); err != nil { + _, err = blob.BreakLease(nil) + if err != nil && !strings.Contains(err.Error(), "LeaseNotPresentWithLeaseOperation") { s.say(s.client.LastError.Error()) return err } - err = blob.Delete(nil) - - return err + return blob.Delete(nil) }