mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-17 20:00:23 +00:00
e2e: add test cases for subvolume metadata validation
create a PVC and check PVC/PV metadata on cephFS subvolume Fixes: #2875 Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
parent
466bdf97b2
commit
25ce21f496
@ -397,6 +397,64 @@ var _ = Describe(cephfsType, func() {
|
||||
}
|
||||
})
|
||||
|
||||
By("create a PVC and check PVC/PV metadata on CephFS subvolume", func() {
|
||||
err := createCephfsStorageClass(f.ClientSet, f, true, nil)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to create CephFS storageclass: %v", err)
|
||||
}
|
||||
pvc, err := loadPVC(pvcPath)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to load PVC: %v", err)
|
||||
}
|
||||
pvc.Namespace = f.UniqueName
|
||||
|
||||
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to create PVC: %v", err)
|
||||
}
|
||||
|
||||
validateSubvolumeCount(f, 1, fileSystemName, subvolumegroup)
|
||||
validateOmapCount(f, 1, cephfsType, metadataPool, volumesType)
|
||||
|
||||
pvcObj, err := getPersistentVolumeClaim(c, pvc.Namespace, pvc.Name)
|
||||
if err != nil {
|
||||
e2elog.Logf("error getting pvc %q in namespace %q: %v", pvc.Name, pvc.Namespace, err)
|
||||
}
|
||||
if pvcObj.Spec.VolumeName == "" {
|
||||
e2elog.Logf("pv name is empty %q in namespace %q: %v", pvc.Name, pvc.Namespace, err)
|
||||
}
|
||||
subvol, err := listCephFSSubVolumes(f, fileSystemName, subvolumegroup)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to list CephFS subvolumes: %v", err)
|
||||
}
|
||||
if len(subvol) == 0 {
|
||||
e2elog.Failf("cephFS subvolumes list is empty %s", fileSystemName)
|
||||
}
|
||||
metadata, err := listCephFSSubvolumeMetadata(f, fileSystemName, subvol[0].Name, subvolumegroup)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to list subvolume metadata: %v", err)
|
||||
}
|
||||
|
||||
if metadata.PVCNameKey != pvc.Name {
|
||||
e2elog.Failf("expected pvcName %q got %q", pvc.Name, metadata.PVCNameKey)
|
||||
} else if metadata.PVCNamespaceKey != pvc.Namespace {
|
||||
e2elog.Failf("expected pvcNamespace %q got %q", pvc.Namespace, metadata.PVCNamespaceKey)
|
||||
} else if metadata.PVNameKey != pvcObj.Spec.VolumeName {
|
||||
e2elog.Failf("expected pvName %q got %q", pvcObj.Spec.VolumeName, metadata.PVNameKey)
|
||||
}
|
||||
|
||||
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to delete PVC: %v", err)
|
||||
}
|
||||
validateSubvolumeCount(f, 0, fileSystemName, subvolumegroup)
|
||||
validateOmapCount(f, 0, cephfsType, metadataPool, volumesType)
|
||||
err = deleteResource(cephFSExamplePath + "storageclass.yaml")
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to delete CephFS storageclass: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
By("create PVC in storageClass with volumeNamePrefix", func() {
|
||||
volumeNamePrefix := "foo-bar-"
|
||||
err := createCephfsStorageClass(
|
||||
|
@ -212,6 +212,38 @@ func listCephFSSubVolumes(f *framework.Framework, filesystem, groupname string)
|
||||
return subVols, nil
|
||||
}
|
||||
|
||||
type cephfsSubvolumeMetadata struct {
|
||||
PVCNameKey string `json:"csi.storage.k8s.io/pvc/name"`
|
||||
PVCNamespaceKey string `json:"csi.storage.k8s.io/pvc/namespace"`
|
||||
PVNameKey string `json:"csi.storage.k8s.io/pv/name"`
|
||||
}
|
||||
|
||||
func listCephFSSubvolumeMetadata(
|
||||
f *framework.Framework,
|
||||
filesystem,
|
||||
subvolume,
|
||||
groupname string,
|
||||
) (cephfsSubvolumeMetadata, error) {
|
||||
var metadata cephfsSubvolumeMetadata
|
||||
stdout, stdErr, err := execCommandInToolBoxPod(
|
||||
f,
|
||||
fmt.Sprintf("ceph fs subvolume metadata ls %s %s --group_name=%s --format=json", filesystem, subvolume, groupname),
|
||||
rookNamespace)
|
||||
if err != nil {
|
||||
return metadata, err
|
||||
}
|
||||
if stdErr != "" {
|
||||
return metadata, fmt.Errorf("error listing subvolume metadata %v", stdErr)
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(stdout), &metadata)
|
||||
if err != nil {
|
||||
return metadata, err
|
||||
}
|
||||
|
||||
return metadata, nil
|
||||
}
|
||||
|
||||
// getSubvolumepath validates whether subvolumegroup is present.
|
||||
func getSubvolumePath(f *framework.Framework, filesystem, subvolgrp, subvolume string) (string, error) {
|
||||
cmd := fmt.Sprintf("ceph fs subvolume getpath %s %s --group_name=%s", filesystem, subvolume, subvolgrp)
|
||||
|
Loading…
Reference in New Issue
Block a user