From 5dd59bdd4a255d997434ce146a93f7eeae184f61 Mon Sep 17 00:00:00 2001 From: Abhilash Shetty Date: Tue, 25 Jun 2024 07:14:55 +0000 Subject: [PATCH] test(ci): adding vgops wrapper Signed-off-by: Abhilash Shetty --- tests/provision_test.go | 14 +++++++------- tests/utils.go | 24 ++++++++++++++++++------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/tests/provision_test.go b/tests/provision_test.go index a9199c83..2cfbcd96 100644 --- a/tests/provision_test.go +++ b/tests/provision_test.go @@ -133,13 +133,13 @@ func leakProtectionTest() { // 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") + device := createPV(6) + createVg("newvgcode3", device) + device_1 := createPV(6) + extendVg("newvgcode3", device_1) + removeVg("newvgcode3") + removePV(device) + removePV(device_1) } func volumeCreationTest() { diff --git a/tests/utils.go b/tests/utils.go index 45bd6cce..728cf9fc 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -736,11 +736,12 @@ func enableThinpoolMonitoring() { gomega.Expect(err).To(gomega.BeNil(), "run lvchange command") } -// This creates loopdevice using file_id(for unquiness) and size, +// 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, file_id string) string { +func createPV(size int) string { fmt.Printf("Creating device\n") - filename := fmt.Sprintf("/tmp/openebs_ci_disk_%s.img", file_id) + t := time.Now().Format("20060102150405") + filename := fmt.Sprintf("/tmp/openebs_ci_disk_%s.img", t) size_str := strconv.Itoa(size) + "G" args_file := []string{ @@ -767,7 +768,7 @@ func createPV(size int, file_id string) string { } // Does pvremove on specified device. Deletes loop device and the file backing loop device. -func removePV(device string, file_id string) { +func removePV(device string) { fmt.Printf("remove pv\n") args_pv := []string{ "pvremove", @@ -778,16 +779,27 @@ func removePV(device string, file_id string) { _, _, err_pv := execAtLocal("sudo", nil, args_pv...) gomega.Expect(err_pv).To(gomega.BeNil(), "pv remove failed") + args_lo := []string{ + "losetup", + device, + "-O", + "BACK-FILE", + "--noheadings", + } + dev, _, _ := execAtLocal("sudo", nil, args_lo...) + dev_str := strings.TrimSpace(string(dev)) + 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, + "-f", + dev_str, } _, _, err_file := execAtLocal("sudo", nil, args_file...) gomega.Expect(err_file).To(gomega.BeNil(), "file remove failed")