fix issue 6575

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
pull/6593/head
Lyndon-Li 2023-08-02 15:54:09 +08:00
parent 0d67b73962
commit 598023710a
3 changed files with 40 additions and 1 deletions

View File

@ -0,0 +1 @@
Fix issue 6575, flush the repo after delete the snapshot, otherwise, the changes(deleting repo snapshot) cannot be committed to the repo.

View File

@ -66,7 +66,7 @@ const (
repoOpDescMaintain = "repo maintenance"
repoOpDescForget = "forget"
repoConnectDesc = "unfied repo"
repoConnectDesc = "unified repo"
)
// NewUnifiedRepoProvider creates the service provider for Unified Repo
@ -301,6 +301,11 @@ func (urp *unifiedRepoProvider) Forget(ctx context.Context, snapshotID string, p
return errors.Wrap(err, "error to delete manifest")
}
err = bkRepo.Flush(ctx)
if err != nil {
return errors.Wrap(err, "error to flush repo")
}
log.Debug("Forget snapshot complete")
return nil

View File

@ -734,6 +734,7 @@ func TestForget(t *testing.T) {
backupRepo *reposervicenmocks.BackupRepo
retFuncOpen []interface{}
retFuncDelete interface{}
retFuncFlush interface{}
credStoreReturn string
credStoreError error
expectedErr string
@ -794,6 +795,37 @@ func TestForget(t *testing.T) {
},
expectedErr: "error to delete manifest: fake-error-3",
},
{
name: "flush fail",
getter: new(credmock.SecretStore),
credStoreReturn: "fake-password",
funcTable: localFuncTable{
getStorageVariables: func(*velerov1api.BackupStorageLocation, string, string) (map[string]string, error) {
return map[string]string{}, nil
},
getStorageCredentials: func(*velerov1api.BackupStorageLocation, velerocredentials.FileStore) (map[string]string, error) {
return map[string]string{}, nil
},
},
repoService: new(reposervicenmocks.BackupRepoService),
backupRepo: new(reposervicenmocks.BackupRepo),
retFuncOpen: []interface{}{
func(context.Context, udmrepo.RepoOptions) udmrepo.BackupRepo {
return backupRepo
},
func(context.Context, udmrepo.RepoOptions) error {
return nil
},
},
retFuncDelete: func(context.Context, udmrepo.ID) error {
return nil
},
retFuncFlush: func(context.Context) error {
return errors.New("fake-error-4")
},
expectedErr: "error to flush repo: fake-error-4",
},
}
for _, tc := range testCases {
@ -822,6 +854,7 @@ func TestForget(t *testing.T) {
if tc.backupRepo != nil {
backupRepo.On("DeleteManifest", mock.Anything, mock.Anything).Return(tc.retFuncDelete)
backupRepo.On("Flush", mock.Anything).Return(tc.retFuncFlush)
backupRepo.On("Close", mock.Anything).Return(nil)
}