Skip to content

Commit

Permalink
Merge pull request kubevirt#11589 from EdDev/tests-slirp-convert-to-b…
Browse files Browse the repository at this point in the history
…inding-plugin

tests, net: Convert slirp tests to use the binding plugin directly
  • Loading branch information
kubevirt-bot authored Mar 27, 2024
2 parents 63def35 + 33876de commit d6fa126
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/network/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
"bindingplugin.go",
"bindingplugin_macvtap.go",
"bindingplugin_passt.go",
"bindingplugin_slirp.go",
"dual_stack_cluster.go",
"expose.go",
"framework.go",
Expand All @@ -27,7 +28,6 @@ go_library(
"vmi_multus.go",
"vmi_networking.go",
"vmi_passt.go",
"vmi_slirp_interface.go",
"vmi_subdomain.go",
],
importpath = "kubevirt.io/kubevirt/tests/network",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"context"
"strings"

virtconfig "kubevirt.io/kubevirt/pkg/virt-config"
"kubevirt.io/kubevirt/tests/libkvconfig"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand All @@ -46,18 +49,34 @@ import (
"kubevirt.io/kubevirt/tests/testsuite"
)

var _ = SIGDescribe("Slirp", decorators.Networking, func() {
var _ = SIGDescribe("Slirp", decorators.Networking, decorators.NetCustomBindingPlugins, Serial, func() {

BeforeEach(libnet.SkipWhenClusterNotSupportIpv4)

BeforeEach(func() {
tests.EnableFeatureGate(virtconfig.NetworkBindingPlugingsGate)
})

const slirpBindingName = "slirp"

BeforeEach(func() {
const slirpSidecarImage = "registry:5000/kubevirt/network-slirp-binding:devel"

Expect(libkvconfig.WithNetBindingPlugin(slirpBindingName, v1.InterfaceBindingPlugin{
SidecarImage: slirpSidecarImage,
})).To(Succeed())
})

It("VMI with SLIRP interface, custom mac and port is configured correctly", func() {
vmi := libvmifact.NewCirros(
libvmi.WithNetwork(v1.DefaultPodNetwork()),
libvmi.WithInterface(
libvmi.InterfaceDeviceWithSlirpBinding(v1.DefaultPodNetwork().Name, v1.Port{Name: "http", Port: 80}),
),
libvmi.WithInterface(v1.Interface{
Name: v1.DefaultPodNetwork().Name,
Binding: &v1.PluginBinding{Name: slirpBindingName},
MacAddress: "de:ad:00:00:be:af",
Ports: []v1.Port{{Name: "http", Port: 80}},
}),
)
vmi.Spec.Domain.Devices.Interfaces[0].MacAddress = "de:ad:00:00:be:af"
var err error
vmi, err = kubevirt.Client().VirtualMachineInstance(testsuite.GetTestNamespace(nil)).Create(context.Background(), vmi, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
Expand All @@ -72,13 +91,8 @@ var _ = SIGDescribe("Slirp", decorators.Networking, func() {
vmiPod, err := libpod.GetPodByVirtualMachineInstance(vmi, vmi.Namespace)
Expect(err).NotTo(HaveOccurred())

var container k8sv1.Container
for _, containerSpec := range vmiPod.Spec.Containers {
if containerSpec.Name == "compute" {
container = containerSpec
break
}
}
container := lookupComputeContainer(vmiPod.Spec.Containers)
Expect(container).NotTo(BeNil(), "could not find the compute container")
Expect(container.Name).ToNot(Equal(""))
Expect(container.Ports).ToNot(BeNil())
Expect(container.Ports[0].Name).To(Equal("http"))
Expand Down Expand Up @@ -115,3 +129,12 @@ var _ = SIGDescribe("Slirp", decorators.Networking, func() {
Expect(err).To(HaveOccurred())
})
})

func lookupComputeContainer(containers []k8sv1.Container) *k8sv1.Container {
for idx := range containers {
if containers[idx].Name == "compute" {
return &containers[idx]
}
}
return nil
}

0 comments on commit d6fa126

Please sign in to comment.