Skip to content

Commit

Permalink
test: remove execute functions from utils
Browse files Browse the repository at this point in the history
Remove execute functions: ExecuteCommandOnPod,
ExecuteCommandOnPodV2, ExecCommandOnPod from
utils and use them from exec package.

Signed-off-by: Ben Oukhanov <[email protected]>
  • Loading branch information
codingben committed Oct 6, 2022
1 parent 7ba2a5f commit d887885
Show file tree
Hide file tree
Showing 33 changed files with 131 additions and 160 deletions.
3 changes: 2 additions & 1 deletion tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ go_library(
"//staging/src/kubevirt.io/client-go/log:go_default_library",
"//tests/console:go_default_library",
"//tests/containerdisk:go_default_library",
"//tests/exec:go_default_library",
"//tests/flags:go_default_library",
"//tests/framework/checks:go_default_library",
"//tests/framework/cleanup:go_default_library",
Expand Down Expand Up @@ -59,7 +60,6 @@ go_library(
"//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/tools/portforward:go_default_library",
"//vendor/k8s.io/client-go/tools/remotecommand:go_default_library",
"//vendor/k8s.io/client-go/transport/spdy:go_default_library",
"//vendor/k8s.io/utils/net:go_default_library",
"//vendor/k8s.io/utils/pointer:go_default_library",
Expand Down Expand Up @@ -209,6 +209,7 @@ go_test(
"//tests/clientcmd:go_default_library",
"//tests/console:go_default_library",
"//tests/containerdisk:go_default_library",
"//tests/exec:go_default_library",
"//tests/flags:go_default_library",
"//tests/framework/checks:go_default_library",
"//tests/framework/cleanup:go_default_library",
Expand Down
21 changes: 11 additions & 10 deletions tests/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
. "github.com/onsi/gomega"
"github.com/pborman/uuid"

"kubevirt.io/kubevirt/tests/exec"
"kubevirt.io/kubevirt/tests/util"

v1 "kubevirt.io/api/core/v1"
Expand Down Expand Up @@ -62,7 +63,7 @@ var _ = Describe("[rfe_id:899][crit:medium][vendor:[email protected]][level:comp
}
if len(path) > 0 {
cmdCheck := []string{"stat", "--printf='%s'", path}
out, err := tests.ExecuteCommandOnPod(virtClient, pod, "compute", cmdCheck)
out, err := exec.ExecuteCommandOnPod(virtClient, pod, "compute", cmdCheck)
Expect(err).NotTo(HaveOccurred())
size, err := strconv.Atoi(strings.Trim(out, "'"))
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -114,7 +115,7 @@ var _ = Describe("[rfe_id:899][crit:medium][vendor:[email protected]][level:comp

By("Checking if ConfigMap has been attached to the pod")
vmiPod := tests.GetRunningPodByVirtualMachineInstance(vmi, util.NamespaceTestDefault)
podOutput, err := tests.ExecuteCommandOnPod(
podOutput, err := exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
vmiPod.Spec.Containers[0].Name,
Expand Down Expand Up @@ -208,7 +209,7 @@ var _ = Describe("[rfe_id:899][crit:medium][vendor:[email protected]][level:comp

By("Checking if Secret has been attached to the pod")
vmiPod := tests.GetRunningPodByVirtualMachineInstance(vmi, util.NamespaceTestDefault)
podOutput, err := tests.ExecuteCommandOnPod(
podOutput, err := exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
vmiPod.Spec.Containers[0].Name,
Expand Down Expand Up @@ -281,7 +282,7 @@ var _ = Describe("[rfe_id:899][crit:medium][vendor:[email protected]][level:comp

By("Checking if ServiceAccount has been attached to the pod")
vmiPod := tests.GetRunningPodByVirtualMachineInstance(vmi, util.NamespaceTestDefault)
namespace, err := tests.ExecuteCommandOnPod(
namespace, err := exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
vmiPod.Spec.Containers[0].Name,
Expand All @@ -293,7 +294,7 @@ var _ = Describe("[rfe_id:899][crit:medium][vendor:[email protected]][level:comp
Expect(err).ToNot(HaveOccurred())
Expect(namespace).To(Equal(util.NamespaceTestDefault))

token, err := tests.ExecuteCommandOnPod(
token, err := exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
vmiPod.Spec.Containers[0].Name,
Expand Down Expand Up @@ -383,7 +384,7 @@ var _ = Describe("[rfe_id:899][crit:medium][vendor:[email protected]][level:comp

By("Checking if ConfigMap has been attached to the pod")
vmiPod := tests.GetRunningPodByVirtualMachineInstance(vmi, util.NamespaceTestDefault)
podOutputCfgMap, err := tests.ExecuteCommandOnPod(
podOutputCfgMap, err := exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
vmiPod.Spec.Containers[0].Name,
Expand All @@ -410,7 +411,7 @@ var _ = Describe("[rfe_id:899][crit:medium][vendor:[email protected]][level:comp
}, 200)).To(Succeed())

By("Checking if Secret has also been attached to the same pod")
podOutputSecret, err := tests.ExecuteCommandOnPod(
podOutputSecret, err := exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
vmiPod.Spec.Containers[0].Name,
Expand Down Expand Up @@ -490,7 +491,7 @@ var _ = Describe("[rfe_id:899][crit:medium][vendor:[email protected]][level:comp

By("Checking if Secret has been attached to the pod")
vmiPod := tests.GetRunningPodByVirtualMachineInstance(vmi, util.NamespaceTestDefault)
podOutput1, err := tests.ExecuteCommandOnPod(
podOutput1, err := exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
vmiPod.Spec.Containers[0].Name,
Expand All @@ -501,7 +502,7 @@ var _ = Describe("[rfe_id:899][crit:medium][vendor:[email protected]][level:comp
Expect(err).ToNot(HaveOccurred())
Expect(podOutput1).To(Equal(expectedPrivateKey), "Expected pod output of private key to match genereated one.")

podOutput2, err := tests.ExecuteCommandOnPod(
podOutput2, err := exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
vmiPod.Spec.Containers[0].Name,
Expand Down Expand Up @@ -551,7 +552,7 @@ var _ = Describe("[rfe_id:899][crit:medium][vendor:[email protected]][level:comp

By("Checking if DownwardAPI has been attached to the pod")
vmiPod := tests.GetRunningPodByVirtualMachineInstance(vmi, util.NamespaceTestDefault)
podOutput, err := tests.ExecuteCommandOnPod(
podOutput, err := exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
vmiPod.Spec.Containers[0].Name,
Expand Down
5 changes: 3 additions & 2 deletions tests/container_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"kubevirt.io/kubevirt/tests/exec"
"kubevirt.io/kubevirt/tests/util"

v1 "kubevirt.io/api/core/v1"
Expand Down Expand Up @@ -244,7 +245,7 @@ var _ = Describe("[rfe_id:588][crit:medium][vendor:[email protected]][level:comp

writableImagePath := fmt.Sprintf("/var/run/kubevirt-ephemeral-disks/disk-data/%v/disk.qcow2", vmi.Spec.Domain.Devices.Disks[0].Name)

writableImageOctalMode, err := tests.ExecuteCommandOnPod(
writableImageOctalMode, err := exec.ExecuteCommandOnPod(
virtClient,
pod,
"compute",
Expand All @@ -255,7 +256,7 @@ var _ = Describe("[rfe_id:588][crit:medium][vendor:[email protected]][level:comp
By("Checking the writable Image Octal mode")
Expect(strings.Trim(writableImageOctalMode, "\n")).To(Equal("640"), "Octal Mode of writable Image should be 640")

readonlyImageOctalMode, err := tests.ExecuteCommandOnPod(
readonlyImageOctalMode, err := exec.ExecuteCommandOnPod(
virtClient,
pod,
"compute",
Expand Down
11 changes: 6 additions & 5 deletions tests/infra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (

kvtls "kubevirt.io/kubevirt/pkg/util/tls"

"kubevirt.io/kubevirt/tests/exec"
"kubevirt.io/kubevirt/tests/framework/checks"

expect "github.com/google/goexpect"
Expand Down Expand Up @@ -640,7 +641,7 @@ var _ = Describe("[Serial][sig-compute]Infrastructure", func() {
// We need a token from a service account that can view all namespaces in the cluster
By("extracting virt-operator sa token")
cmd := []string{"cat", "/var/run/secrets/kubernetes.io/serviceaccount/token"}
token, stderr, err := tests.ExecuteCommandOnPodV2(virtClient, &op, "virt-operator", cmd)
token, stderr, err := exec.ExecuteCommandOnPodV2(virtClient, &op, "virt-operator", cmd)
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf(remoteCmdErrPattern, strings.Join(cmd, " "), token, stderr, err))
Expect(token).ToNot(BeEmpty(), "virt-operator sa token returned empty")

Expand All @@ -659,7 +660,7 @@ var _ = Describe("[Serial][sig-compute]Infrastructure", func() {
vmi.Name,
)}

stdout, stderr, err := tests.ExecuteCommandOnPodV2(virtClient, &op, "virt-operator", cmd)
stdout, stderr, err := exec.ExecuteCommandOnPodV2(virtClient, &op, "virt-operator", cmd)
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf(remoteCmdErrPattern, strings.Join(cmd, " "), stdout, stderr, err))

// the Prometheus go-client does not export queryResult, and
Expand Down Expand Up @@ -803,7 +804,7 @@ var _ = Describe("[Serial][sig-compute]Infrastructure", func() {
}

cmd := fmt.Sprintf("curl -L -k https://%s:8443/metrics", tests.FormatIPForURL(ep.IP))
stdout, stderr, err := tests.ExecuteCommandOnPodV2(virtClient, pod, "virt-handler", strings.Fields(cmd))
stdout, stderr, err := exec.ExecuteCommandOnPodV2(virtClient, pod, "virt-handler", strings.Fields(cmd))
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf(remoteCmdErrPattern, cmd, stdout, stderr, err))

scrapedData := strings.Split(stdout, "\n")
Expand Down Expand Up @@ -838,7 +839,7 @@ var _ = Describe("[Serial][sig-compute]Infrastructure", func() {
}

cmd := fmt.Sprintf("curl -L -k https://%s:8443/metrics", tests.FormatIPForURL(ep.IP))
stdout, stderr, err := tests.ExecuteCommandOnPodV2(virtClient, pod, "virt-handler", strings.Fields(cmd))
stdout, stderr, err := exec.ExecuteCommandOnPodV2(virtClient, pod, "virt-handler", strings.Fields(cmd))
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf(remoteCmdErrPattern, cmd, stdout, stderr, err))

scrapedData := strings.Split(stdout, "\n")
Expand Down Expand Up @@ -890,7 +891,7 @@ var _ = Describe("[Serial][sig-compute]Infrastructure", func() {
Expect(err).ToNot(HaveOccurred())
for _, ep := range endpoint.Subsets[0].Addresses {
cmd := fmt.Sprintf("curl -L -k https://%s:8443/metrics", tests.FormatIPForURL(ep.IP))
stdout, stderr, err := tests.ExecuteCommandOnPodV2(virtClient, pod, "virt-handler", strings.Fields(cmd))
stdout, stderr, err := exec.ExecuteCommandOnPodV2(virtClient, pod, "virt-handler", strings.Fields(cmd))
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf(remoteCmdErrPattern, cmd, stdout, stderr, err))
Expect(stdout).To(ContainSubstring("go_goroutines"))
}
Expand Down
3 changes: 2 additions & 1 deletion tests/io_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/kubecli"

"kubevirt.io/kubevirt/tests/exec"
"kubevirt.io/kubevirt/tests/flags"
. "kubevirt.io/kubevirt/tests/framework/matcher"
"kubevirt.io/kubevirt/tests/testsuite"
Expand Down Expand Up @@ -69,7 +70,7 @@ func ExecuteCommandInVirtHandlerPod(nodeName string, args []string) (stdout stri
return stdout, err
}

stdout, stderr, err := ExecuteCommandOnPodV2(virtClient, pod, "virt-handler", args)
stdout, stderr, err := exec.ExecuteCommandOnPodV2(virtClient, pod, "virt-handler", args)
if err != nil {
return stdout, fmt.Errorf("Failed excuting command=%v, error=%v, stdout=%s, stderr=%s", args, err, stdout, stderr)
}
Expand Down
13 changes: 7 additions & 6 deletions tests/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

"kubevirt.io/api/migrations/v1alpha1"

"kubevirt.io/kubevirt/tests/exec"
"kubevirt.io/kubevirt/tests/framework/cleanup"

"kubevirt.io/kubevirt/pkg/virt-handler/cgroup"
Expand Down Expand Up @@ -571,7 +572,7 @@ var _ = Describe("[rfe_id:393][crit:high][vendor:[email protected]][level:system
}

getLibvirtdPid := func(pod *k8sv1.Pod) string {
stdout, stderr, err := tests.ExecuteCommandOnPodV2(virtClient, pod, "compute",
stdout, stderr, err := exec.ExecuteCommandOnPodV2(virtClient, pod, "compute",
[]string{
"pidof",
"libvirtd",
Expand Down Expand Up @@ -1104,7 +1105,7 @@ var _ = Describe("[rfe_id:393][crit:high][vendor:[email protected]][level:system

// kill libvirtd
By(fmt.Sprintf("Killing libvirtd with pid %s", pid))
stdout, stderr, err := tests.ExecuteCommandOnPodV2(virtClient, &pods.Items[0], "compute",
stdout, stderr, err := exec.ExecuteCommandOnPodV2(virtClient, &pods.Items[0], "compute",
[]string{
"kill",
"-9",
Expand Down Expand Up @@ -4102,7 +4103,7 @@ var _ = Describe("[rfe_id:393][crit:high][vendor:[email protected]][level:system
pod, err := tests.GetRunningPodByLabel(string(vmi.GetUID()), v1.CreatedByLabel, vmi.Namespace, vmi.Status.NodeName)
Expect(err).ToNot(HaveOccurred())

stdout, stderr, err := tests.ExecuteCommandOnPodV2(virtClient,
stdout, stderr, err := exec.ExecuteCommandOnPodV2(virtClient,
pod,
"compute",
[]string{"virsh", "vcpupin", fmt.Sprintf("%s_%s", vmi.GetNamespace(), vmi.GetName())})
Expand All @@ -4127,7 +4128,7 @@ var _ = Describe("[rfe_id:393][crit:high][vendor:[email protected]][level:system
cpusetPath = "/sys/fs/cgroup/cpuset/cpuset.cpus"
}

stdout, stderr, err := tests.ExecuteCommandOnPodV2(virtClient,
stdout, stderr, err := exec.ExecuteCommandOnPodV2(virtClient,
pod,
"compute",
[]string{"cat", cpusetPath})
Expand Down Expand Up @@ -4553,7 +4554,7 @@ func wakeNodeLabellerUp(virtClient kubecli.KubevirtClient) {
func libvirtDomainIsPersistent(virtClient kubecli.KubevirtClient, vmi *v1.VirtualMachineInstance) (bool, error) {
vmiPod := tests.GetRunningPodByVirtualMachineInstance(vmi, util.NamespaceTestDefault)

stdout, stderr, err := tests.ExecuteCommandOnPodV2(
stdout, stderr, err := exec.ExecuteCommandOnPodV2(
virtClient,
vmiPod,
tests.GetComputeContainerOfPod(vmiPod).Name,
Expand All @@ -4573,7 +4574,7 @@ func getVMIsCgroupVersion(vmi *v1.VirtualMachineInstance, virtClient kubecli.Kub
}

func getPodsCgroupVersion(pod *k8sv1.Pod, virtClient kubecli.KubevirtClient) cgroup.CgroupVersion {
stdout, stderr, err := tests.ExecuteCommandOnPodV2(virtClient,
stdout, stderr, err := exec.ExecuteCommandOnPodV2(virtClient,
pod,
"compute",
[]string{"stat", "/sys/fs/cgroup/", "-f", "-c", "%T"})
Expand Down
1 change: 1 addition & 0 deletions tests/network/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ go_library(
"//tests/clientcmd:go_default_library",
"//tests/console:go_default_library",
"//tests/containerdisk:go_default_library",
"//tests/exec:go_default_library",
"//tests/flags:go_default_library",
"//tests/framework/checks:go_default_library",
"//tests/framework/matcher:go_default_library",
Expand Down
3 changes: 2 additions & 1 deletion tests/network/expose.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"kubevirt.io/kubevirt/tests/console"
"kubevirt.io/kubevirt/tests/exec"

"kubevirt.io/kubevirt/tests/framework/checks"
"kubevirt.io/kubevirt/tests/libnet/cluster"
Expand Down Expand Up @@ -788,7 +789,7 @@ func getNodeHostname(nodeAddresses []k8sv1.NodeAddress) *string {

func resolveNodeIp(virtclient kubecli.KubevirtClient, pod *k8sv1.Pod, hostname string, ipFamily k8sv1.IPFamily) (string, error) {
ahostsCmd := string("ahosts" + ipFamily[2:])
output, err := tests.ExecuteCommandOnPod(
output, err := exec.ExecuteCommandOnPod(
virtclient,
pod,
"compute",
Expand Down
7 changes: 4 additions & 3 deletions tests/network/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (

"kubevirt.io/kubevirt/tests"
"kubevirt.io/kubevirt/tests/console"
"kubevirt.io/kubevirt/tests/exec"
"kubevirt.io/kubevirt/tests/framework/checks"
"kubevirt.io/kubevirt/tests/libnet"
"kubevirt.io/kubevirt/tests/libnode"
Expand Down Expand Up @@ -620,7 +621,7 @@ func getNodesWithAllocatedResource(virtClient kubecli.KubevirtClient, resourceNa
}

func validatePodKubevirtResourceNameByVMI(virtClient kubecli.KubevirtClient, vmi *v1.VirtualMachineInstance, networkName, sriovResourceName string) error {
out, err := tests.ExecuteCommandOnPod(
out, err := exec.ExecuteCommandOnPod(
virtClient,
tests.GetRunningPodByVirtualMachineInstance(vmi, vmi.Namespace),
"compute",
Expand Down Expand Up @@ -757,7 +758,7 @@ func checkDefaultInterfaceInPod(vmi *v1.VirtualMachineInstance) error {
}

By("checking default interface is present")
_, err = tests.ExecuteCommandOnPod(
_, err = exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
"compute",
Expand All @@ -768,7 +769,7 @@ func checkDefaultInterfaceInPod(vmi *v1.VirtualMachineInstance) error {
}

By("checking default interface is attached to VMI")
_, err = tests.ExecuteCommandOnPod(
_, err = exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
"compute",
Expand Down
7 changes: 4 additions & 3 deletions tests/network/vmi_multus.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v13 "k8s.io/apimachinery/pkg/apis/meta/v1"

"kubevirt.io/kubevirt/tests/exec"
"kubevirt.io/kubevirt/tests/framework/checks"

"kubevirt.io/kubevirt/tests/util"
Expand Down Expand Up @@ -361,7 +362,7 @@ var _ = SIGDescribe("[Serial]Multus", func() {

By("Verifying the desired custom MAC is not configured inside the pod namespace.")
vmiPod := tests.GetRunningPodByVirtualMachineInstance(vmiOne, util.NamespaceTestDefault)
out, err := tests.ExecuteCommandOnPod(
out, err := exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
"compute",
Expand Down Expand Up @@ -463,7 +464,7 @@ var _ = SIGDescribe("[Serial]Multus", func() {

By("Verifying the desired custom MAC is not configured inside the pod namespace.")
vmiPod := tests.GetRunningPodByVirtualMachineInstance(vmiOne, vmiOne.Namespace)
out, err := tests.ExecuteCommandOnPod(
out, err := exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
"compute",
Expand Down Expand Up @@ -515,7 +516,7 @@ var _ = SIGDescribe("[Serial]Multus", func() {
It("should have the correct MTU on the secondary interface with no dhcp server", func() {
getPodInterfaceMtu := func(vmi *v1.VirtualMachineInstance) string {
vmiPod := tests.GetRunningPodByVirtualMachineInstance(vmi, vmi.Namespace)
output, err := tests.ExecuteCommandOnPod(
output, err := exec.ExecuteCommandOnPod(
virtClient,
vmiPod,
"compute",
Expand Down
Loading

0 comments on commit d887885

Please sign in to comment.