Skip to content

Commit

Permalink
Merge pull request #308 from openebs/thinpool_config
Browse files Browse the repository at this point in the history
test: thinpool auto-extend test
  • Loading branch information
dsharma-dc authored Jun 14, 2024
2 parents f417c07 + ccc803c commit 4a57750
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 12 deletions.
8 changes: 6 additions & 2 deletions ci/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ cleanup() {

# setup the lvm volume group to create the volume
cleanup_lvmvg
truncate -s 1024G /tmp/openebs_ci_disk.img
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
truncate -s 1024G /tmp/openebs_ci_foreign_disk.img
truncate -s 100G /tmp/openebs_ci_foreign_disk.img
foreign_disk="$(sudo losetup -f /tmp/openebs_ci_foreign_disk.img --show)"
sudo pvcreate "${foreign_disk}"
sudo vgcreate foreign_lvmvg "${foreign_disk}" --config="${FOREIGN_LVM_CONFIG}"
Expand All @@ -97,6 +97,10 @@ sudo vgcreate foreign_lvmvg "${foreign_disk}" --config="${FOREIGN_LVM_CONFIG}"
sudo modprobe dm-snapshot
sudo modprobe dm_thin_pool

# Set the configuration for thin pool autoextend in lvm.conf
sudo sed -i '/^[^#]*thin_pool_autoextend_threshold/ s/= .*/= 50/' /etc/lvm/lvm.conf
sudo sed -i '/^[^#]*thin_pool_autoextend_percent/ s/= .*/= 20/' /etc/lvm/lvm.conf

# Prepare env for running BDD tests
# Minikube is already running
kubectl apply -f "${LVM_OPERATOR}"
Expand Down
17 changes: 16 additions & 1 deletion tests/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ func thinVolCreationTest() {
By("Deleting thinProvision storage class", deleteStorageClass)
}

func thinVolCapacityTest() {
By("Creating thinProvision storage class", createThinStorageClass)
By("creating and verifying PVC bound status", createAndVerifyPVC)
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("Deleting application deployment")
deleteAppDeployment(appName)
By("Deleting pvc")
deleteAndVerifyPVC(pvcName)
By("Deleting thinProvision storage class", deleteStorageClass)
}

func leakProtectionTest() {
By("Creating default storage class", createStorageClass)
ds := deleteNodeDaemonSet() // ensure that provisioning remains in pending state.
Expand All @@ -116,8 +130,9 @@ func leakProtectionTest() {
}

func volumeCreationTest() {
By("Running volume creation test", fsVolCreationTest)
By("Running filesystem volume creation test", fsVolCreationTest)
By("Running block volume creation test", blockVolCreationTest)
By("Running thin volume creation test", thinVolCreationTest)
By("Running thin volume capacity test", thinVolCapacityTest)
By("Running leak protection test", leakProtectionTest)
}
19 changes: 10 additions & 9 deletions tests/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ var (
nodeDaemonSet = "openebs-lvm-node"
controllerDeployment = "openebs-lvm-controller"

nsObj *corev1.Namespace
scObj *storagev1.StorageClass
deployObj *appsv1.Deployment
pvcObj *corev1.PersistentVolumeClaim
appPod *corev1.PodList
accessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
capacity = "5368709120" // 5Gi
KubeConfigPath string
OpenEBSNamespace string
nsObj *corev1.Namespace
scObj *storagev1.StorageClass
deployObj *appsv1.Deployment
pvcObj *corev1.PersistentVolumeClaim
appPod *corev1.PodList
accessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
capacity = "5368709120" // 5Gi
expanded_capacity = "6442450944" // 6Gi
KubeConfigPath string
OpenEBSNamespace string
)

func init() {
Expand Down
68 changes: 68 additions & 0 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package tests
import (
"context"
"fmt"
"strconv"
"strings"
"time"

"github.com/onsi/ginkgo"
Expand Down Expand Up @@ -706,3 +708,69 @@ func createNodeDaemonSet(ds *appsv1.DaemonSet) {
gomega.BeNil(),
"creating node plugin daemonset %v", nodeDaemonSet)
}

// enable the monitoring on thinpool created for test, on local node which
// is part of single node cluster.
func enableThinpoolMonitoring() {
lv := VOLGROUP + "/" + pvcObj.Spec.VolumeName

args := []string{
"lvdisplay", "--columns",
"--options", "pool_lv",
"--noheadings",
lv,
}
stdout, _, err := execAtLocal("sudo", nil, args...)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "display LV")
gomega.Expect(strings.TrimSpace(string(stdout))).To(gomega.Not(gomega.Equal("")), "get thinpool LV")

thinpool := VOLGROUP + "/" + strings.TrimSpace(string(stdout))

args = []string{
"lvchange",
"--monitor", "y",
thinpool,
}

_, _, err = execAtLocal("sudo", nil, args...)
gomega.Expect(err).To(gomega.BeNil(), "run lvchange command")
}

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

args := []string{
"lvdisplay", "--columns",
"--options", "pool_lv",
"--noheadings",
lv,
}

//stdout will contain the pool name
stdout, _, err := execAtLocal("sudo", nil, args...)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "display LV")
gomega.Expect(strings.TrimSpace(string(stdout))).To(gomega.Not(gomega.Equal("")), "get thinpool LV")

thinpool := VOLGROUP + "/" + strings.TrimSpace(string(stdout))

args = []string{
"lvdisplay", "--columns",
"--options", "lv_size",
"--units", "b",
"--noheadings",
thinpool,
}

// stdout will contain the size
stdout, _, err = execAtLocal("sudo", nil, args...)
gomega.Expect(err).To(gomega.BeNil(), "display thinpool LV")

// Remove unit suffix from the size.
size_str := strings.TrimSuffix(strings.TrimSpace(string(stdout)), "B")
// This expectation is a factor of the lvm.conf settings we do from ci-test.sh
// and the original volume size.
size_int64, _ := strconv.ParseInt(size_str, 10, 64)
gomega.Expect(size_int64).To(gomega.Equal(expect_size))
}

0 comments on commit 4a57750

Please sign in to comment.