Skip to content

Commit 4f26b1a

Browse files
committed
✅ Add formatOptions test
Signed-off-by: Muhammed Hussein Karimi <[email protected]>
1 parent 1ebb1ab commit 4f26b1a

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

tests/provision_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ func fsVolCreationTest() {
8686
}
8787
}
8888

89+
func formatOptionsTest() {
90+
formatOptions := "-b 4096 -N 5000000"
91+
By("####### Creating the storage class with formatOptions : " + formatOptions + " #######")
92+
createFormatOptionsStorageClass(formatOptions)
93+
By("Creating and verifying PVC bound status")
94+
createAndVerifyPVC(true)
95+
By("Creating and deploying app pod", createDeployVerifyFormatOptions)
96+
By("Verifying LVMVolume object to be Ready")
97+
VerifyLVMVolume(true, "")
98+
By("Verifing LVM Volume format options")
99+
VerifyLVMVolumeFormatOptions(formatOptions)
100+
By("Deleting verifier pvc/pod")
101+
deleteAppAndPvc([]string{"format-options-verifier"}, pvcName)
102+
By("Verifying that PV is deleted after deletion")
103+
verifyPVForPVC(false, pvcName)
104+
By("Deleting storage class", deleteStorageClass)
105+
}
106+
89107
func blockVolCreationTest() {
90108
By("Creating default storage class", createStorageClass)
91109
By("Creating and verifying PVC bound status")
@@ -321,6 +339,7 @@ func volumeCreationTest() {
321339
device := setupVg(40, "lvmvg")
322340
defer cleanupVg(device, "lvmvg")
323341
By("###Running filesystem volume creation test###", fsVolCreationTest)
342+
By("###Running filesystem with formatOptions creation test###", formatOptionsTest)
324343
By("###Running block volume creation test###", blockVolCreationTest)
325344
By("###Running thin volume creation test###", thinVolCreationTest)
326345
By("###Running leak protection test###", leakProtectionTest)

tests/utils.go

+107
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"path/filepath"
7+
"strings"
78

89
"github.com/onsi/ginkgo"
910
"github.com/onsi/gomega"
@@ -233,6 +234,29 @@ func createThinStorageClass() {
233234
gomega.Expect(err).To(gomega.BeNil(), "while creating a thinProvision storageclass {%s}", scName)
234235
}
235236

237+
func createFormatOptionsStorageClass(formatOptions string) {
238+
var (
239+
err error
240+
)
241+
242+
parameters := map[string]string{
243+
"volgroup": VOLGROUP,
244+
"formatOptions": formatOptions,
245+
}
246+
247+
ginkgo.By("building a default storage class")
248+
scObj, err = sc.NewBuilder().
249+
WithGenerateName(scName).
250+
WithVolumeExpansion(true).
251+
WithParametersNew(parameters).
252+
WithProvisioner(LocalProvisioner).Build()
253+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(),
254+
"while building formatOptions storageclass obj with prefix {%s}", scName)
255+
256+
scObj, err = SCClient.Create(scObj)
257+
gomega.Expect(err).To(gomega.BeNil(), "while creating a storageclass with formatOptions {%s}", scName)
258+
}
259+
236260
// VerifyLVMVolume verify the properties of a lvm-volume
237261
// expected_vg is supposed to be passed only when vgpatten was used for scheduling.
238262
// If its volgroup in sc then we can just match volgroup with lvmvolume's vg field.
@@ -271,6 +295,18 @@ func VerifyLVMVolume(expect_ready bool, expected_vg string) {
271295
}
272296
}
273297

298+
func VerifyLVMVolumeFormatOptions(formatOptions string) {
299+
ginkgo.By("fetching lvm volume")
300+
vol_name := pvcObj.Spec.VolumeName
301+
vol, err := LVMClient.WithNamespace(OpenEBSNamespace).
302+
Get(vol_name, metav1.GetOptions{})
303+
gomega.Expect(err).To(gomega.BeNil(), "while fetching the lvm volume {%s}", pvcObj.Spec.VolumeName)
304+
gomega.Expect(vol).To(gomega.Not(gomega.BeNil()), "LVMVolume Obj is Nil")
305+
gomega.Expect(vol.ObjectMeta.Name).To(gomega.Not(gomega.Equal(vol_name)), "LVMVolume mismatch")
306+
gomega.Expect(vol.Spec.FormatOptions).To(gomega.Equal(strings.Split(formatOptions, " ")),
307+
"While checking if lvmvolume: %s has correct formatOptions", pvcObj.Spec.VolumeName)
308+
}
309+
274310
func deleteStorageClass() {
275311
err := SCClient.Delete(scObj.Name, &metav1.DeleteOptions{})
276312
gomega.Expect(err).To(gomega.BeNil(),
@@ -560,6 +596,77 @@ func createAndDeployBlockAppPod() {
560596
}
561597
}
562598

599+
func createDeployVerifyFormatOptions() {
600+
ginkgo.By("creating and deploying verifier pod")
601+
createAndDeployVerifyFormatOptions()
602+
ginkgo.By("verifying verifier pod is running", verifyAppPodRunning)
603+
}
604+
605+
func createAndDeployVerifyFormatOptions() {
606+
var err error
607+
appname := "format-options-verifier"
608+
labels := map[string]string{
609+
"role": "test",
610+
"app": appname,
611+
}
612+
ginkgo.By("building app " + appname + " using above lvm volume")
613+
deployObj, err = deploy.NewBuilder().
614+
WithName(appname).
615+
WithNamespace(OpenEBSNamespace).
616+
WithLabelsNew(labels).
617+
WithSelectorMatchLabelsNew(labels).
618+
WithPodTemplateSpecBuilder(
619+
pts.NewBuilder().
620+
WithLabelsNew(labels).
621+
WithContainerBuilders(
622+
container.NewBuilder().
623+
WithImage("debian:stable-slim").
624+
WithName("verifier").
625+
WithImagePullPolicy(corev1.PullIfNotPresent).
626+
WithEnvsNew(
627+
[]corev1.EnvVar{
628+
{
629+
Name: "EXPECTED_INODES",
630+
Value: "5001264",
631+
},
632+
},
633+
).
634+
WithCommandNew(
635+
[]string{
636+
"bash",
637+
"-c",
638+
`export DEVICE=$(df --output=source '/mnt/datadir' | tail -n 1); export ACTUAL_INODES=$(tune2fs -l "$DEVICE" | grep "Inode count" | awk '{print $3}'); [ "$ACTUAL_INODES" -eq "$EXPECTED_INODES" ] && echo "Inode count is correct: $ACTUAL_INODES" && exit 0 || echo "Inode count mismatch: expected $EXPECTED_INODES, but got $ACTUAL_INODES" && exit 1`,
639+
},
640+
).
641+
WithVolumeMountsNew(
642+
[]corev1.VolumeMount{
643+
{
644+
Name: "datavol1",
645+
// If this path changes, modify the above fio command line accordingly.
646+
MountPath: "/mnt/datadir",
647+
},
648+
},
649+
),
650+
).
651+
WithVolumeBuilders(
652+
k8svolume.NewBuilder().
653+
WithName("datavol1").
654+
WithPVCSource(pvcObj.Name),
655+
),
656+
).
657+
Build()
658+
659+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "while building app deployement {%s}", appname)
660+
661+
deployObj, err = DeployClient.WithNamespace(OpenEBSNamespace).Create(deployObj)
662+
gomega.Expect(err).ShouldNot(
663+
gomega.HaveOccurred(),
664+
"while creating pod {%s} in namespace {%s}",
665+
appname,
666+
OpenEBSNamespace,
667+
)
668+
}
669+
563670
func createDeployVerifyBlockApp() {
564671
ginkgo.By("creating and deploying app pod", createAndDeployBlockAppPod)
565672
ginkgo.By("verifying app pod is running", verifyAppPodRunning)

0 commit comments

Comments
 (0)