mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-22 14:20:19 +00:00
e2e: add validation for thick-provisioning
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
8870575a48
commit
2363d2a789
77
e2e/rbd.go
77
e2e/rbd.go
@ -1297,6 +1297,83 @@ var _ = Describe("RBD", func() {
|
||||
validateRBDImageCount(f, 0)
|
||||
})
|
||||
|
||||
By("create a thick-provisioned PVC", func() {
|
||||
err := deleteResource(rbdExamplePath + "storageclass.yaml")
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to delete storageclass with error %v", err)
|
||||
}
|
||||
err = createRBDStorageClass(f.ClientSet, f, nil, map[string]string{
|
||||
"thickProvision": "true"}, deletePolicy)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to create storageclass with error %v", err)
|
||||
}
|
||||
|
||||
pvc, err := loadPVC(rawPvcPath)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to load PVC with error %v", err)
|
||||
}
|
||||
pvc.Namespace = f.UniqueName
|
||||
|
||||
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to create PVC with error %v", err)
|
||||
}
|
||||
validateRBDImageCount(f, 1)
|
||||
|
||||
// nothing has been written, but the image should be allocated
|
||||
du, err := getRbdDu(f, pvc)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to get allocations of RBD image: %v", err)
|
||||
} else if du.UsedSize == 0 || du.UsedSize != du.ProvisionedSize {
|
||||
e2elog.Failf("backing RBD image is not thick-provisioned (%d/%d)", du.UsedSize, du.ProvisionedSize)
|
||||
}
|
||||
|
||||
// expanding the PVC should thick-allocate the expansion
|
||||
// nolint:mnd // we want 2x the size so that extending is done
|
||||
newSize := du.ProvisionedSize * 2
|
||||
err = expandPVCSize(f.ClientSet, pvc, fmt.Sprintf("%d", newSize), deployTimeout)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to expand PVC: %v", err)
|
||||
}
|
||||
|
||||
// after expansion, the updated 'du' should be larger
|
||||
du, err = getRbdDu(f, pvc)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to get allocations of RBD image: %v", err)
|
||||
} else if du.UsedSize != newSize {
|
||||
e2elog.Failf("backing RBD image is not extended thick-provisioned (%d/%d)", du.UsedSize, newSize)
|
||||
}
|
||||
|
||||
// thick provisioning allows for sparsifying
|
||||
err = sparsifyBackingRBDImage(f, pvc)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to sparsify RBD image: %v", err)
|
||||
}
|
||||
|
||||
// after sparsifying the image should not have any allocations
|
||||
du, err = getRbdDu(f, pvc)
|
||||
if err != nil {
|
||||
e2elog.Failf("backing RBD image is not thick-provisioned: %v", err)
|
||||
} else if du.UsedSize != 0 {
|
||||
e2elog.Failf("backing RBD image was not sparsified")
|
||||
}
|
||||
|
||||
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to delete PVC with error: %v", err)
|
||||
}
|
||||
validateRBDImageCount(f, 0)
|
||||
|
||||
err = deleteResource(rbdExamplePath + "storageclass.yaml")
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to delete storageclass with error %v", err)
|
||||
}
|
||||
err = createRBDStorageClass(f.ClientSet, f, nil, nil, deletePolicy)
|
||||
if err != nil {
|
||||
e2elog.Failf("failed to create storageclass with error %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
By("create a PVC and Bind it to an app for mapped rbd image with options", func() {
|
||||
err := deleteResource(rbdExamplePath + "storageclass.yaml")
|
||||
if err != nil {
|
||||
|
@ -313,6 +313,63 @@ func deleteBackingRBDImage(f *framework.Framework, pvc *v1.PersistentVolumeClaim
|
||||
return err
|
||||
}
|
||||
|
||||
// rbdDuImage contains the disk-usage statistics of an RBD image.
|
||||
type rbdDuImage struct {
|
||||
Name string `json:"name"`
|
||||
ProvisionedSize uint64 `json:"provisioned_size"`
|
||||
UsedSize uint64 `json:"used_size"`
|
||||
}
|
||||
|
||||
// rbdDuImageList contains the list of images returned by 'rbd du'.
|
||||
type rbdDuImageList struct {
|
||||
Images []*rbdDuImage `json:"images"`
|
||||
}
|
||||
|
||||
// getRbdDu runs 'rbd du' on the RBD image and returns a rbdDuImage struct with
|
||||
// the result.
|
||||
func getRbdDu(f *framework.Framework, pvc *v1.PersistentVolumeClaim) (*rbdDuImage, error) {
|
||||
rdil := rbdDuImageList{}
|
||||
|
||||
imageData, err := getImageInfoFromPVC(pvc.Namespace, pvc.Name, f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := fmt.Sprintf("rbd du --format=json %s %s", rbdOptions(defaultRBDPool), imageData.imageName)
|
||||
stdout, _, err := execCommandInToolBoxPod(f, cmd, rookNamespace)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(stdout), &rdil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, image := range rdil.Images {
|
||||
if image.Name == imageData.imageName {
|
||||
return image, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("image %s not found", imageData.imageName)
|
||||
}
|
||||
|
||||
// sparsifyBackingRBDImage runs `rbd sparsify` on the RBD image. Once done, all
|
||||
// data blocks that contain zeros are discarded/trimmed/unmapped and do not
|
||||
// take up any space anymore. This can be used to verify that an empty, but
|
||||
// allocated (with zerofill) extents have been released.
|
||||
func sparsifyBackingRBDImage(f *framework.Framework, pvc *v1.PersistentVolumeClaim) error {
|
||||
imageData, err := getImageInfoFromPVC(pvc.Namespace, pvc.Name, f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd := fmt.Sprintf("rbd sparsify %s %s", rbdOptions(defaultRBDPool), imageData.imageName)
|
||||
_, _, err = execCommandInToolBoxPod(f, cmd, rookNamespace)
|
||||
return err
|
||||
}
|
||||
|
||||
func deletePool(name string, cephfs bool, f *framework.Framework) error {
|
||||
var cmds = []string{}
|
||||
if cephfs {
|
||||
|
Loading…
Reference in New Issue
Block a user