-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ci): adding wrapper for vg and pv operations
Signed-off-by: Abhilash Shetty <[email protected]>
- Loading branch information
1 parent
bddedee
commit 24b56ef
Showing
3 changed files
with
215 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters