test: fix ut and add e2e test
This commit is contained in:
parent
e819966385
commit
e0c7569564
@ -242,21 +242,21 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
|
||||
|
||||
internalVolumePath := getInternalVolumePath(cs.Driver.workingMountDir, nfsVol)
|
||||
|
||||
if !strings.EqualFold(nfsVol.onDelete, archive) {
|
||||
// delete subdirectory under base-dir
|
||||
klog.V(2).Infof("Removing subdirectory at %v", internalVolumePath)
|
||||
if err = os.RemoveAll(internalVolumePath); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to delete subdirectory: %v", err.Error())
|
||||
}
|
||||
} else {
|
||||
if strings.EqualFold(nfsVol.onDelete, archive) {
|
||||
archivedNfsVol := *nfsVol
|
||||
archivedNfsVol.subDir = "archived-" + nfsVol.subDir
|
||||
archivedInternalVolumePath := getArchivedInternalVolumePath(cs.Driver.workingMountDir, nfsVol, &archivedNfsVol)
|
||||
|
||||
// archive subdirectory under base-dir
|
||||
klog.V(2).Infof("Archiving subdirectory at %v", internalVolumePath)
|
||||
klog.V(2).Infof("archiving subdirectory %s --> %s", internalVolumePath, archivedInternalVolumePath)
|
||||
if err = os.Rename(internalVolumePath, archivedInternalVolumePath); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to archive subdirectory: %v", err.Error())
|
||||
return nil, status.Errorf(codes.Internal, "archive subdirectory(%s, %s) failed with %v", internalVolumePath, archivedInternalVolumePath, err.Error())
|
||||
}
|
||||
} else {
|
||||
// delete subdirectory under base-dir
|
||||
klog.V(2).Infof("removing subdirectory at %v", internalVolumePath)
|
||||
if err = os.RemoveAll(internalVolumePath); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "delete subdirectory(%s) failed with %v", internalVolumePath, err.Error())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -50,7 +50,7 @@ const (
|
||||
newTestVolumeIDUUID = "test-server#test-base-dir#volume-name#uuid"
|
||||
newTestVolumeOnDeleteRetain = "test-server#test-base-dir#volume-name#uuid#retain"
|
||||
newTestVolumeOnDeleteDelete = "test-server#test-base-dir#volume-name#uuid#delete"
|
||||
newTestVolumeOnDeleteArchive = "test-server#test-base-dir#volume-name#uuid#archive"
|
||||
newTestVolumeOnDeleteArchive = "test-server#test-base-dir#volume-name##archive"
|
||||
)
|
||||
|
||||
func initTestController(t *testing.T) *ControllerServer {
|
||||
@ -294,7 +294,7 @@ func TestDeleteVolume(t *testing.T) {
|
||||
req: &csi.DeleteVolumeRequest{VolumeId: newTestVolumeOnDeleteArchive},
|
||||
resp: &csi.DeleteVolumeResponse{},
|
||||
expectedErr: nil,
|
||||
expectedDeleteSubDir: false,
|
||||
expectedDeleteSubDir: true,
|
||||
},
|
||||
}
|
||||
|
||||
@ -510,7 +510,7 @@ func TestNfsVolFromId(t *testing.T) {
|
||||
server: testServer,
|
||||
baseDir: testBaseDir,
|
||||
subDir: testCSIVolume,
|
||||
uuid: "uuid",
|
||||
uuid: "",
|
||||
onDelete: "archive",
|
||||
},
|
||||
expectErr: false,
|
||||
|
||||
@ -350,4 +350,27 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
|
||||
}
|
||||
test.Run(cs, ns)
|
||||
})
|
||||
|
||||
ginkgo.It("should create a volume on demand with archive subdir on delete [nfs.csi.k8s.io]", func() {
|
||||
pods := []testsuites.PodDetails{
|
||||
{
|
||||
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
|
||||
Volumes: []testsuites.VolumeDetails{
|
||||
{
|
||||
ClaimSize: "10Gi",
|
||||
VolumeMount: testsuites.VolumeMountDetails{
|
||||
NameGenerate: "test-volume-",
|
||||
MountPathGenerate: "/mnt/test-",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
|
||||
CSIDriver: testDriver,
|
||||
Pods: pods,
|
||||
StorageClassParameters: archiveStorageClassParameters,
|
||||
}
|
||||
test.Run(cs, ns)
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user