Skip to content

Commit

Permalink
test(ci): adding wrapper for vg and pv operations
Browse files Browse the repository at this point in the history
Signed-off-by: Abhilash Shetty <[email protected]>
  • Loading branch information
abhilashshetty04 committed Jun 24, 2024
1 parent 4a57750 commit 73b136d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,24 @@ func leakProtectionTest() {
By("Deleting storage class", deleteStorageClass)
}

// This acts as a test just to call the new wrapper functions,
// 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)
}
92 changes: 92 additions & 0 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,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)
Expand Down

0 comments on commit 73b136d

Please sign in to comment.