Skip to content

Commit

Permalink
test(ci): adding volgroup based tests
Browse files Browse the repository at this point in the history
Signed-off-by: Abhilash Shetty <[email protected]>
  • Loading branch information
abhilashshetty04 committed Jun 26, 2024
1 parent d119d7f commit cc52876
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 66 deletions.
16 changes: 0 additions & 16 deletions ci/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ cleanup_loopdev() {
done
}

cleanup_lvmvg() {
if [ -f /tmp/openebs_ci_disk.img ]
then
sudo vgremove lvmvg -y || true
rm /tmp/openebs_ci_disk.img
fi
cleanup_loopdev
}

cleanup_foreign_lvmvg() {
if [ -f /tmp/openebs_ci_foreign_disk.img ]
then
Expand All @@ -65,7 +56,6 @@ cleanup() {

echo "Cleaning up test resources"

cleanup_lvmvg
cleanup_foreign_lvmvg

kubectl delete pvc -n openebs lvmpv-pvc
Expand All @@ -79,12 +69,6 @@ cleanup() {
[ -n "${CLEANUP_ONLY}" ] && cleanup 2>/dev/null && exit 0
[ -n "${RESET}" ] && cleanup 2>/dev/null

# setup the lvm volume group to create the volume
cleanup_lvmvg
truncate -s 100G /tmp/openebs_ci_disk.img
disk="$(sudo losetup -f /tmp/openebs_ci_disk.img --show)"
sudo pvcreate "${disk}"
sudo vgcreate lvmvg "${disk}"

# setup a foreign lvm to test
cleanup_foreign_lvmvg
Expand Down
14 changes: 8 additions & 6 deletions tests/lvm_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ limitations under the License.
package tests

import (
"fmt"
"strconv"
"strings"

"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)

// This creates loopdevice using the size passed as arg,
// Uses the new loop device to create PV. returns loopdevice name to the caller.
func createPV(size int) string {
fmt.Printf("Creating device\n")
ginkgo.By("Creating device")

back_file_args := []string{
"mktemp", "-t",
Expand Down Expand Up @@ -64,7 +64,7 @@ func createPV(size int) string {

// Does pvremove on specified device. Deletes loop device and the file backing loop device.
func removePV(device string) {
fmt.Printf("remove pv\n")
ginkgo.By("remove pv")
args_pv := []string{
"pvremove",
device,
Expand Down Expand Up @@ -101,7 +101,7 @@ func removePV(device string) {

// Creates vg on the specified device, Device passed should be a pv.
func createVg(name string, device string) {
fmt.Printf("Creating vg\n")
ginkgo.By("Creating vg")
args_vg := []string{
"vgcreate", name,
device,
Expand All @@ -112,7 +112,7 @@ func createVg(name string, device string) {

// Takes vg name and pv device, extends vg using the supplied pv.
func extendVg(name string, device string) {
fmt.Printf("extending vg\n")
ginkgo.By("extending vg")
args_vg := []string{
"vgextend", name,
device,
Expand All @@ -124,7 +124,7 @@ func extendVg(name string, device string) {
// Does vhremove on specified vg with force flag,
// lv will be forcedeleted if vg is not empty.
func removeVg(name string) {
fmt.Printf("Removing vg\n")
ginkgo.By("Removing vg")
args_vg := []string{
"vgremove",
name,
Expand All @@ -137,6 +137,7 @@ func removeVg(name string) {
// enable the monitoring on thinpool created for test, on local node which
// is part of single node cluster.
func enableThinpoolMonitoring() {
ginkgo.By("Enable thinpool monitoring")
lv := VOLGROUP + "/" + pvcObj.Spec.VolumeName

args := []string{
Expand All @@ -163,6 +164,7 @@ func enableThinpoolMonitoring() {

// verify that the thinpool has extended in capacity to an expected size.
func VerifyThinpoolExtend() {
ginkgo.By("Verify thinpool extend")
expect_size, _ := strconv.ParseInt(expanded_capacity, 10, 64)
lv := VOLGROUP + "/" + pvcObj.Spec.VolumeName

Expand Down
90 changes: 76 additions & 14 deletions tests/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ func deleteAppAndPvc(appnames []string, pvcname string) {
}

func fsVolCreationTest() {
device := createPV(20)
createVg("lvmvg", device)
fstypes := []string{"ext4", "xfs", "btrfs"}
for _, fstype := range fstypes {
By("####### Creating the storage class : " + fstype + " #######")
createFstypeStorageClass(fstype)
By("creating and verifying PVC bound status", createAndVerifyPVC)
By("creating and verifying PVC bound status")
createAndVerifyPVC(true)
By("Creating and deploying app pod", createDeployVerifyApp)
By("verifying LVMVolume object", VerifyLVMVolume)
By("verifying LVMVolume object")
VerifyLVMVolume(false)

resizeAndVerifyPVC(true, "8Gi")
// do not resize after creating the snapshot(not supported)
Expand All @@ -70,13 +74,19 @@ func fsVolCreationTest() {
verifyPVForPVC(false, pvcName)
By("Deleting storage class", deleteStorageClass)
}
removeVg("lvmvg")
removePV(device)
}

func blockVolCreationTest() {
device := createPV(20)
createVg("lvmvg", device)
By("Creating default storage class", createStorageClass)
By("creating and verifying PVC bound status", createAndVerifyBlockPVC)
By("creating and verifying PVC bound status")
createAndVerifyBlockPVC(true)
By("Creating and deploying app pod", createDeployVerifyBlockApp)
By("verifying LVMVolume object", VerifyLVMVolume)
By("verifying LVMVolume object")
VerifyLVMVolume(false)
By("Online resizing the block volume")
resizeAndVerifyPVC(true, "8Gi")
By("create snapshot")
Expand All @@ -91,28 +101,55 @@ func blockVolCreationTest() {
By("Verifying that PV is deleted after snapshot deletion")
verifyPVForPVC(false, pvcName)
By("Deleting storage class", deleteStorageClass)
removeVg("lvmvg")
removePV(device)
}

func vgNotPresentTest() {
device := createPV(20)
createVg("lvmvg", device)
By("Creating custom storage class with non existing vg parameter", createStorageClassWithNonExistingVg)
By("creating and verifying PVC Not Bound status")
createAndVerifyPVC(false)
By("verifying LVMVolume object with no provision set")
VerifyLVMVolume(true)
By("Deleting pvc")
deleteAndVerifyPVC(pvcName)
By("Deleting storage class", deleteStorageClass)
removeVg("lvmvg")
removePV(device)
}

func sharedVolumeTest() {
device := createPV(20)
createVg("lvmvg", device)
By("Creating shared LV storage class", createSharedVolStorageClass)
By("creating and verifying PVC bound status", createAndVerifyPVC)
By("creating and verifying PVC bound status")
createAndVerifyPVC(true)
//we use two fio app pods for this test.
appNames = append(appNames, "fio-ci-1")
By("Creating and deploying app pod", createDeployVerifyApp)
By("verifying LVMVolume object", VerifyLVMVolume)
By("verifying LVMVolume object")
VerifyLVMVolume(false)
By("Online resizing the shared volume")
resizeAndVerifyPVC(true, "8Gi")
deleteAppAndPvc(appNames, pvcName)
By("Deleting storage class", deleteStorageClass)
// Reset the app list back to original
appNames = appNames[:len(appNames)-1]
removeVg("lvmvg")
removePV(device)
}

func thinVolCreationTest() {
device := createPV(20)
createVg("lvmvg", device)
By("Creating thinProvision storage class", createThinStorageClass)
By("creating and verifying PVC bound status", createAndVerifyPVC)
By("creating and verifying PVC bound status")
createAndVerifyPVC(true)
By("Creating and deploying app pod", createDeployVerifyApp)
By("verifying LVMVolume object", VerifyLVMVolume)
By("verifying LVMVolume object")
VerifyLVMVolume(false)
By("Online resizing the block volume")
resizeAndVerifyPVC(true, "8Gi")
By("create snapshot")
Expand All @@ -127,41 +164,61 @@ func thinVolCreationTest() {
By("Verifying that PV is deleted after snapshot deletion")
verifyPVForPVC(false, pvcName)
By("Deleting thinProvision storage class", deleteStorageClass)
removeVg("lvmvg")
removePV(device)
}

func thinVolCapacityTest() {
device := createPV(20)
createVg("lvmvg", device)
By("Creating thinProvision storage class", createThinStorageClass)
By("creating and verifying PVC bound status", createAndVerifyPVC)
By("creating and verifying PVC bound status")
createAndVerifyPVC(true)
By("enabling monitoring on thinpool", enableThinpoolMonitoring)
By("Creating and deploying app pod", createDeployVerifyApp)
By("verifying thinpool auto-extended", VerifyThinpoolExtend)
By("verifying LVMVolume object", VerifyLVMVolume)
By("verifying LVMVolume object")
VerifyLVMVolume(false)
deleteAppAndPvc(appNames, pvcName)
By("Deleting thinProvision storage class", deleteStorageClass)
removeVg("lvmvg")
removePV(device)
}

func sizedSnapFSTest() {
device := createPV(20)
createVg("lvmvg", device)
createFstypeStorageClass("ext4")
By("creating and verifying PVC bound status", createAndVerifyPVC)
By("creating and verifying PVC bound status")
createAndVerifyPVC(true)
By("Creating and deploying app pod", createDeployVerifyApp)
By("verifying LVMVolume object", VerifyLVMVolume)
By("verifying LVMVolume object")
VerifyLVMVolume(false)
createSnapshot(pvcName, snapName, sizedsnapYAML)
verifySnapshotCreated(snapName)
deleteAppAndPvc(appNames, pvcName)
deleteSnapshot(pvcName, snapName, sizedsnapYAML)
By("Deleting storage class", deleteStorageClass)
removeVg("lvmvg")
removePV(device)
}

func sizedSnapBlockTest() {
device := createPV(20)
createVg("lvmvg", device)
By("Creating default storage class", createStorageClass)
By("creating and verifying PVC bound status", createAndVerifyPVC)
By("creating and verifying PVC bound status")
createAndVerifyPVC(true)
By("Creating and deploying app pod", createDeployVerifyApp)
By("verifying LVMVolume object", VerifyLVMVolume)
By("verifying LVMVolume object")
VerifyLVMVolume(false)
createSnapshot(pvcName, snapName, sizedsnapYAML)
verifySnapshotCreated(snapName)
deleteAppAndPvc(appNames, pvcName)
deleteSnapshot(pvcName, snapName, sizedsnapYAML)
By("Deleting storage class", deleteStorageClass)
removeVg("lvmvg")
removePV(device)
}

func sizedSnapshotTest() {
Expand All @@ -170,6 +227,8 @@ func sizedSnapshotTest() {
}

func leakProtectionTest() {
device := createPV(20)
createVg("lvmvg", device)
By("Creating default storage class", createStorageClass)
ds := deleteNodeDaemonSet() // ensure that provisioning remains in pending state.

Expand All @@ -188,6 +247,8 @@ func leakProtectionTest() {
gomega.Expect(IsPVCDeletedEventually(pvcName)).To(gomega.Equal(true),
"failed to garbage collect leaked pvc")
By("Deleting storage class", deleteStorageClass)
removeVg("lvmvg")
removePV(device)
}

// This acts as a test just to call the new wrapper functions,
Expand All @@ -210,6 +271,7 @@ func volumeCreationTest() {
By("Running leak protection test", leakProtectionTest)
By("Running shared volume for two app pods on same node test", sharedVolumeTest)
By("Running Lvm Ops", lvmOps)
By("Running vg not present test", vgNotPresentTest)
}

func capacityTest() {
Expand Down
2 changes: 2 additions & 0 deletions tests/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import (
const (
// volume group name where volume provisioning will happen
VOLGROUP = "lvmvg"
// This is supposed to be the volgroup parameter. This will not be available for provisioning in the lvmnode.
NONEXIST_VOLGROUP = "lvmvgn"
)

var (
Expand Down
Loading

0 comments on commit cc52876

Please sign in to comment.