From adfae19f4254e85b4ea4d04dc6255cc6323fc93f Mon Sep 17 00:00:00 2001 From: Abhilash Shetty Date: Thu, 20 Jun 2024 19:00:19 +0000 Subject: [PATCH] test(vci: adding wrapper for vg and pv operations Signed-off-by: Abhilash Shetty --- tests/provision_test.go | 14 +++++++ tests/utils.go | 93 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 1 deletion(-) diff --git a/tests/provision_test.go b/tests/provision_test.go index af54c8f7..17541716 100644 --- a/tests/provision_test.go +++ b/tests/provision_test.go @@ -152,10 +152,24 @@ func leakProtectionTest() { By("Deleting storage class", deleteStorageClass) } +// This acts as a test just to call the new wrapper functions that written, +// Once we write tests calling them this will not be required. +// This doesnt test any Openebs component. +func lvmOps() { + device := createPV(6, "dev1") + createVg("newvgcode1", device) + device_1 := createPV(6, "dev2") + extendVg("newvgcode1", device_1) + removeVg("newvgcode1") + removePV(device, "dev1") + removePV(device_1, "dev2") +} + func volumeCreationTest() { 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) + By("Running Lvm Ops", lvmOps) } diff --git a/tests/utils.go b/tests/utils.go index 8f65cc9f..6d3d4e8e 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -187,7 +187,6 @@ func VerifyLVMVolume() { gomega.Expect(vol.Finalizers[0]).To(gomega.Equal(lvm.LVMFinalizer), "while checking finializer to be set {%s}", pvcObj.Spec.VolumeName) } - func deleteStorageClass() { err := SCClient.Delete(scObj.Name, &metav1.DeleteOptions{}) gomega.Expect(err).To(gomega.BeNil(), @@ -742,6 +741,98 @@ func enableThinpoolMonitoring() { gomega.Expect(err).To(gomega.BeNil(), "run lvchange command") } +// This creates loopdevice using file_id(for unquiness) and size, +// Uses the new loop device to create PV. returns loopdevice name to the caller. +func createPV(size int, file_id string) string { + fmt.Printf("Creating device\n") + filename := fmt.Sprintf("/tmp/openebs_ci_disk_%s.img", file_id) + + size_str := strconv.Itoa(size) + "G" + args_file := []string{ + "truncate", "-s", + size_str, filename, + } + _, _, err := execAtLocal("sudo", nil, args_file...) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "create device failed") + args_loop := []string{ + "losetup", "-f", + filename, "--show", + } + + stdout_loop, _, err := execAtLocal("sudo", nil, args_loop...) + gomega.Expect(err).To(gomega.BeNil(), "loop device create failed") + stdout_loop_str := strings.TrimSpace(string(stdout_loop[:])) + args_pv := []string{ + "pvcreate", + stdout_loop_str, + } + _, _, err_pv := execAtLocal("sudo", nil, args_pv...) + gomega.Expect(err_pv).To(gomega.BeNil(), "pv create failed") + return stdout_loop_str +} + +// Does pvremove on specified device. Deletes loop device and the file backing loop device. +func removePV(device string, file_id string) { + fmt.Printf("remove pv\n") + args_pv := []string{ + "pvremove", + device, + "-ff", + "-y", + } + _, _, err_pv := execAtLocal("sudo", nil, args_pv...) + gomega.Expect(err_pv).To(gomega.BeNil(), "pv remove failed") + + args_loop := []string{ + "losetup", "-d", + device, + } + _, _, err_loop := execAtLocal("sudo", nil, args_loop...) + gomega.Expect(err_loop).To(gomega.BeNil(), "loop device remove failed") + filename := fmt.Sprintf("/tmp/openebs_ci_disk_%s.img", file_id) + args_file := []string{ + "rm", + filename, + } + _, _, err_file := execAtLocal("sudo", nil, args_file...) + gomega.Expect(err_file).To(gomega.BeNil(), "file remove failed") +} + +// Creates vg on the specified device, Device passed should be a pv. +func createVg(name string, device string) { + fmt.Printf("Creating vg\n") + args_vg := []string{ + "vgcreate", name, + device, + } + _, _, err_vg := execAtLocal("sudo", nil, args_vg...) + gomega.Expect(err_vg).To(gomega.BeNil(), "vg create failed") +} + +// Takes vg name and pv device, extends vg using the supplied pv. +func extendVg(name string, device string) { + fmt.Printf("extending vg\n") + args_vg := []string{ + "vgextend", name, + device, + } + _, _, err_vg := execAtLocal("sudo", nil, args_vg...) + gomega.Expect(err_vg).To(gomega.BeNil(), "vg extend failed") +} + +// 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") + args_vg := []string{ + "vgremove", + name, + "-f", + } + _, _, err_vg := execAtLocal("sudo", nil, args_vg...) + gomega.Expect(err_vg).To(gomega.BeNil(), "vg remove failed") +} + // verify that the thinpool has extended in capacity to an expected size. func VerifyThinpoolExtend() { expect_size, _ := strconv.ParseInt(expanded_capacity, 10, 64)