Skip to content

Commit

Permalink
Merge pull request kubevirt#7418 from EdDev/tests-cleanup
Browse files Browse the repository at this point in the history
tests: Various helpers cleanups
  • Loading branch information
kubevirt-bot authored Mar 27, 2022
2 parents f3c5050 + 566c44a commit 1c0f95d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 39 deletions.
1 change: 0 additions & 1 deletion tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ go_library(
"job.go",
"migration.go",
"pod_servers.go",
"test.go",
"utils.go",
"vmi_servers.go",
],
Expand Down
6 changes: 4 additions & 2 deletions tests/network/vmi_istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const (
// Istio uses certain ports for it's own purposes, this port server to verify that traffic is not routed
// into the VMI for these ports. https://istio.io/latest/docs/ops/deployment/requirements/
istioRestrictedPort = istio.EnvoyTunnelPort

istioInjectNamespaceLabel = "istio-injection"
)

const (
Expand Down Expand Up @@ -133,9 +135,9 @@ var _ = SIGDescribe("[Serial] Istio", func() {
})
JustBeforeEach(func() {
// Enable sidecar injection by setting the namespace label
Expect(libnet.AddLabelToNamespace(virtClient, util.NamespaceTestDefault, tests.IstioInjectNamespaceLabel, "enabled")).ShouldNot(HaveOccurred())
Expect(libnet.AddLabelToNamespace(virtClient, util.NamespaceTestDefault, istioInjectNamespaceLabel, "enabled")).ShouldNot(HaveOccurred())
defer func() {
Expect(libnet.RemoveLabelFromNamespace(virtClient, util.NamespaceTestDefault, tests.IstioInjectNamespaceLabel)).ShouldNot(HaveOccurred())
Expect(libnet.RemoveLabelFromNamespace(virtClient, util.NamespaceTestDefault, istioInjectNamespaceLabel)).ShouldNot(HaveOccurred())
}()

By("Creating VMI")
Expand Down
13 changes: 11 additions & 2 deletions tests/network/vmi_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package network
import (
"context"
"fmt"
"strings"

expect "github.com/google/goexpect"

Expand Down Expand Up @@ -72,7 +73,7 @@ var _ = SIGDescribe("[crit:high][arm64][vendor:[email protected]][level:componen
// Start a VirtualMachineInstance with bridged networking
nodeName := tests.WaitForSuccessfulVMIStart(bridgeVMI).Status.NodeName

tests.VerifyDummyNicForBridgeNetwork(bridgeVMI)
verifyDummyNicForBridgeNetwork(bridgeVMI)

By("restarting kubelet")
pod := renderPkillAllPod("kubelet")
Expand Down Expand Up @@ -108,7 +109,7 @@ var _ = SIGDescribe("[crit:high][arm64][vendor:[email protected]][level:componen
// Start a VirtualMachineInstance with bridged networking
By("Waiting the VirtualMachineInstance start")
bridgeVMI = tests.WaitUntilVMIReady(bridgeVMI, console.LoginToCirros)
tests.VerifyDummyNicForBridgeNetwork(bridgeVMI)
verifyDummyNicForBridgeNetwork(bridgeVMI)

vmIP := libnet.GetVmiPrimaryIpByFamily(bridgeVMI, k8sv1.IPv4Protocol)
dadCommand := fmt.Sprintf("sudo /usr/sbin/arping -D -I eth0 -c 2 %s | grep Received | cut -d ' ' -f 2\n", vmIP)
Expand All @@ -128,3 +129,11 @@ var _ = SIGDescribe("[crit:high][arm64][vendor:[email protected]][level:componen
func renderPkillAllPod(processName string) *k8sv1.Pod {
return tests.RenderPrivilegedPod("vmi-killer", []string{"pkill"}, []string{"-9", processName})
}

func verifyDummyNicForBridgeNetwork(vmi *v1.VirtualMachineInstance) {
output := tests.RunCommandOnVmiPod(vmi, []string{tests.BinBash, "-c", "/usr/sbin/ip link show|grep DOWN|grep -c eth0"})
ExpectWithOffset(1, strings.TrimSpace(output)).To(Equal("1"))

output = tests.RunCommandOnVmiPod(vmi, []string{tests.BinBash, "-c", "/usr/sbin/ip link show|grep UP|grep -c eth0-nic"})
ExpectWithOffset(1, strings.TrimSpace(output)).To(Equal("1"))
}
20 changes: 0 additions & 20 deletions tests/test.go

This file was deleted.

14 changes: 0 additions & 14 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,6 @@ const (
SecretLabel = "kubevirt.io/secret"
)

const (
IstioInjectNamespaceLabel = "istio-injection"
)

const (
tmpPath = "/var/provision/kubevirt.io/tests"
)
Expand Down Expand Up @@ -1609,16 +1605,6 @@ func DeletePV(os string) {
}
}

func VerifyDummyNicForBridgeNetwork(vmi *v1.VirtualMachineInstance) {
output := RunCommandOnVmiPod(vmi, []string{BinBash, "-c", "/usr/sbin/ip link show|grep DOWN|grep -c eth0"})
ExpectWithOffset(1, strings.TrimSpace(output)).To(Equal("1"))

output = RunCommandOnVmiPod(vmi, []string{BinBash, "-c", "/usr/sbin/ip link show|grep UP|grep -c eth0-nic"})
ExpectWithOffset(1, strings.TrimSpace(output)).To(Equal("1"))

return
}

func RunVMI(vmi *v1.VirtualMachineInstance, timeout int) *v1.VirtualMachineInstance {
By(StartingVMInstance)
virtCli, err := kubecli.GetKubevirtClient()
Expand Down

0 comments on commit 1c0f95d

Please sign in to comment.