Skip to content

Commit

Permalink
test(ci): adding vgops wrapper
Browse files Browse the repository at this point in the history
Signed-off-by: Abhilash Shetty <[email protected]>
  • Loading branch information
abhilashshetty04 committed Jun 25, 2024
1 parent 73b136d commit 5dd59bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
14 changes: 7 additions & 7 deletions tests/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
24 changes: 18 additions & 6 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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",
Expand All @@ -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")
Expand Down

0 comments on commit 5dd59bd

Please sign in to comment.