Skip to content

Commit

Permalink
test/io_utils.go refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
odra committed Oct 7, 2021
1 parent 10294dc commit e663f2f
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions tests/io_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ import (
"kubevirt.io/kubevirt/tests/util"
)


func gen_chroot_args(args...string) []string {
base_args := []string = {
"/usr/bin/virt-chroot",
"--mount",
"/proc/1/ns/mnt",
"exec",
"--",
}

return append(base_args, args...)
}


func NodeNameWithHandler() string {
listOptions := metav1.ListOptions{LabelSelector: v1.AppLabel + "=virt-handler"}
virtClient, err := kubecli.GetKubevirtClient()
Expand Down Expand Up @@ -67,13 +81,13 @@ func ExecuteCommandInVirtHandlerPod(nodeName string, args []string) (stdout stri
return stdout, nil
}

func CreateErrorDisk(nodeName string) (address string, device string) {
By("Creating error disk")
args := []string{"/usr/bin/virt-chroot", "--mount", "/proc/1/ns/mnt", "exec", "--", "/usr/sbin/modprobe", "scsi_debug", "opts=2", "every_nth=4"}
func CreateErrorDisk(nodeName string) (address string, device string) {
By("Creating error disk")
args := gen_chroot_args("/usr/sbin/modprobe", "scsi_debug", "opts=2", "every_nth=4")
_, err := ExecuteCommandInVirtHandlerPod(nodeName, args)
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to create faulty disk")

args = []string{"/usr/bin/virt-chroot", "--mount", "/proc/1/ns/mnt", "exec", "--", "/usr/bin/lsscsi"}
args = gen_chroot_args("/usr/bin/lsscsi")
stdout, err := ExecuteCommandInVirtHandlerPod(nodeName, args)
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to find out address of faulty disk")

Expand Down Expand Up @@ -101,7 +115,7 @@ func RemoveErrorDisk(nodeName, address string) {
_, err := ExecuteCommandInVirtHandlerPod(nodeName, args)
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to disable faulty disk")

args = []string{"/usr/bin/virt-chroot", "--mount", "/proc/1/ns/mnt", "exec", "--", "/usr/sbin/modprobe", "-r", "scsi_debug"}
args = gen_chroot_args("/usr/sbin/modprobe", "-r", "scsi_debug")
_, err = ExecuteCommandInVirtHandlerPod(nodeName, args)
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to disable faulty disk")
}
Expand Down

0 comments on commit e663f2f

Please sign in to comment.