Răsfoiți Sursa

Display errors if resource not found when deleting volumes (file share or storage account)

Signed-off-by: Guillaume Tardif <[email protected]>
Guillaume Tardif 5 ani în urmă
părinte
comite
18ad20f1c5
1 a modificat fișierele cu 12 adăugiri și 5 ștergeri
  1. 12 5
      aci/volumes.go

+ 12 - 5
aci/volumes.go

@@ -152,7 +152,6 @@ func (cs *aciVolumeService) Create(ctx context.Context, options interface{}) (vo
 		w.Event(errorEvent(opts.Fileshare))
 		return volumes.Volume{}, err
 	}
-	//TODO tag fileshare
 	fileShare, err = fileShareClient.Create(ctx, cs.aciContext.ResourceGroup, *account.Name, opts.Fileshare, storage.FileShare{})
 	if err != nil {
 		w.Event(errorEvent(opts.Fileshare))
@@ -185,14 +184,16 @@ func (cs *aciVolumeService) Delete(ctx context.Context, options interface{}) err
 	}
 	if opts.DeleteAccount {
 		//TODO check if there are other fileshares on this account
-		//TODO flag account and only delete ours?
-		//TODO error when not found
 		storageAccountsClient, err := login.NewStorageAccountsClient(cs.aciContext.SubscriptionID)
 		if err != nil {
 			return err
 		}
 
-		_, err = storageAccountsClient.Delete(ctx, cs.aciContext.ResourceGroup, opts.Account)
+		result, err := storageAccountsClient.Delete(ctx, cs.aciContext.ResourceGroup, opts.Account)
+		if result.StatusCode == 204 {
+			return errors.Wrapf(errdefs.ErrNotFound, "storage account %s does not exist", opts.Account)
+		}
+
 		return err
 	}
 
@@ -201,7 +202,13 @@ func (cs *aciVolumeService) Delete(ctx context.Context, options interface{}) err
 		return err
 	}
 
-	_, err = fileShareClient.Delete(ctx, cs.aciContext.ResourceGroup, opts.Account, opts.Fileshare)
+	result, err := fileShareClient.Delete(ctx, cs.aciContext.ResourceGroup, opts.Account, opts.Fileshare)
+	if result.StatusCode == 204 {
+		return errors.Wrapf(errdefs.ErrNotFound, "fileshare %s does not exist", opts.Fileshare)
+	}
+	if result.StatusCode == 404 {
+		return errors.Wrapf(errdefs.ErrNotFound, "storage account %s does not exist", opts.Account)
+	}
 	return err
 }