Skip to content

Commit

Permalink
Merge pull request #317 from openebs/vgops_ci_wrapper
Browse files Browse the repository at this point in the history
test(ci): adding wrapper for vg and pv operations
  • Loading branch information
abhilashshetty04 authored Jun 25, 2024
2 parents bddedee + 24b56ef commit d119d7f
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 68 deletions.
201 changes: 201 additions & 0 deletions tests/lvm_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
Copyright 2021 The OpenEBS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tests

import (
"fmt"
"strconv"
"strings"

"github.com/onsi/gomega"
)

// 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) string {
fmt.Printf("Creating device\n")

back_file_args := []string{
"mktemp", "-t",
"openebs_lvm_localpv_disk_XXXXX",
"--dry-run",
}
file, _, _ := execAtLocal("sudo", nil, back_file_args...)

file_str := strings.TrimSpace(string(file[:]))
size_str := strconv.Itoa(size) + "G"
device_args := []string{
"truncate", "-s",
size_str, file_str,
}
_, _, err := execAtLocal("sudo", nil, device_args...)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "create device failed")

args_loop := []string{
"losetup", "-f",
file_str, "--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) {
fmt.Printf("remove pv\n")
args_pv := []string{
"pvremove",
device,
"-y",
}
_, _, 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")

args_file := []string{
"rm",
"-f",
dev_str,
}
_, _, 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")
}

// enable the monitoring on thinpool created for test, on local node which
// is part of single node cluster.
func enableThinpoolMonitoring() {
lv := VOLGROUP + "/" + pvcObj.Spec.VolumeName

args := []string{
"lvdisplay", "--columns",
"--options", "pool_lv",
"--noheadings",
lv,
}
stdout, _, err := execAtLocal("sudo", nil, args...)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "display LV")
gomega.Expect(strings.TrimSpace(string(stdout))).To(gomega.Not(gomega.Equal("")), "get thinpool LV")

thinpool := VOLGROUP + "/" + strings.TrimSpace(string(stdout))

args = []string{
"lvchange",
"--monitor", "y",
thinpool,
}

_, _, err = execAtLocal("sudo", nil, args...)
gomega.Expect(err).To(gomega.BeNil(), "run lvchange command")
}

// verify that the thinpool has extended in capacity to an expected size.
func VerifyThinpoolExtend() {
expect_size, _ := strconv.ParseInt(expanded_capacity, 10, 64)
lv := VOLGROUP + "/" + pvcObj.Spec.VolumeName

args := []string{
"lvdisplay", "--columns",
"--options", "pool_lv",
"--noheadings",
lv,
}

//stdout will contain the pool name
stdout, _, err := execAtLocal("sudo", nil, args...)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "display LV")
gomega.Expect(strings.TrimSpace(string(stdout))).To(gomega.Not(gomega.Equal("")), "get thinpool LV")

thinpool := VOLGROUP + "/" + strings.TrimSpace(string(stdout))

args = []string{
"lvdisplay", "--columns",
"--options", "lv_size",
"--units", "b",
"--noheadings",
thinpool,
}

// stdout will contain the size
stdout, _, err = execAtLocal("sudo", nil, args...)
gomega.Expect(err).To(gomega.BeNil(), "display thinpool LV")

// Remove unit suffix from the size.
size_str := strings.TrimSuffix(strings.TrimSpace(string(stdout)), "B")
// This expectation is a factor of the lvm.conf settings we do from ci-test.sh
// and the original volume size.
size_int64, _ := strconv.ParseInt(size_str, 10, 64)
gomega.Expect(size_int64).To(gomega.Equal(expect_size))
}
14 changes: 14 additions & 0 deletions tests/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,26 @@ 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)
createVg("newvgcode3", device)
device_1 := createPV(5)
extendVg("newvgcode3", device_1)
removeVg("newvgcode3")
removePV(device)
removePV(device_1)
}

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 leak protection test", leakProtectionTest)
By("Running shared volume for two app pods on same node test", sharedVolumeTest)
By("Running Lvm Ops", lvmOps)
}

func capacityTest() {
Expand Down
68 changes: 0 additions & 68 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package tests
import (
"context"
"fmt"
"strconv"
"strings"
"time"

"github.com/onsi/ginkgo"
Expand Down Expand Up @@ -748,69 +746,3 @@ func createNodeDaemonSet(ds *appsv1.DaemonSet) {
gomega.BeNil(),
"creating node plugin daemonset %v", nodeDaemonSet)
}

// enable the monitoring on thinpool created for test, on local node which
// is part of single node cluster.
func enableThinpoolMonitoring() {
lv := VOLGROUP + "/" + pvcObj.Spec.VolumeName

args := []string{
"lvdisplay", "--columns",
"--options", "pool_lv",
"--noheadings",
lv,
}
stdout, _, err := execAtLocal("sudo", nil, args...)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "display LV")
gomega.Expect(strings.TrimSpace(string(stdout))).To(gomega.Not(gomega.Equal("")), "get thinpool LV")

thinpool := VOLGROUP + "/" + strings.TrimSpace(string(stdout))

args = []string{
"lvchange",
"--monitor", "y",
thinpool,
}

_, _, err = execAtLocal("sudo", nil, args...)
gomega.Expect(err).To(gomega.BeNil(), "run lvchange command")
}

// verify that the thinpool has extended in capacity to an expected size.
func VerifyThinpoolExtend() {
expect_size, _ := strconv.ParseInt(expanded_capacity, 10, 64)
lv := VOLGROUP + "/" + pvcObj.Spec.VolumeName

args := []string{
"lvdisplay", "--columns",
"--options", "pool_lv",
"--noheadings",
lv,
}

//stdout will contain the pool name
stdout, _, err := execAtLocal("sudo", nil, args...)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "display LV")
gomega.Expect(strings.TrimSpace(string(stdout))).To(gomega.Not(gomega.Equal("")), "get thinpool LV")

thinpool := VOLGROUP + "/" + strings.TrimSpace(string(stdout))

args = []string{
"lvdisplay", "--columns",
"--options", "lv_size",
"--units", "b",
"--noheadings",
thinpool,
}

// stdout will contain the size
stdout, _, err = execAtLocal("sudo", nil, args...)
gomega.Expect(err).To(gomega.BeNil(), "display thinpool LV")

// Remove unit suffix from the size.
size_str := strings.TrimSuffix(strings.TrimSpace(string(stdout)), "B")
// This expectation is a factor of the lvm.conf settings we do from ci-test.sh
// and the original volume size.
size_int64, _ := strconv.ParseInt(size_str, 10, 64)
gomega.Expect(size_int64).To(gomega.Equal(expect_size))
}

0 comments on commit d119d7f

Please sign in to comment.