Skip to content

Commit

Permalink
Merge pull request kubevirt#3916 from phoracek/e2e_networking
Browse files Browse the repository at this point in the history
Keep network e2e tests in a dedicated module
  • Loading branch information
kubevirt-bot authored Aug 17, 2020
2 parents c794ac0 + 15070b5 commit 442a4c8
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 24 deletions.
11 changes: 11 additions & 0 deletions OWNERS_ALIASES
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@ aliases:
ci-approvers:
- dhiller
- danielBelenky
network-reviewers:
- AlonaKaplan
- EdDev
- RamLavi
- alonSadan
- maiqueb
- ormergi
- oshoval
- phoracek
- qinqon
- rhrazdil
1 change: 1 addition & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ go_test(
"//staging/src/kubevirt.io/client-go/subresources:go_default_library",
"//tests/containerdisk:go_default_library",
"//tests/flags:go_default_library",
"//tests/network:go_default_library",
"//tests/reporter:go_default_library",
"//tools/vms-generator/utils:go_default_library",
"//vendor/github.com/evanphx/json-patch:go_default_library",
Expand Down
21 changes: 21 additions & 0 deletions tests/network/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"framework.go",
"primary_pod_network.go",
],
importpath = "kubevirt.io/kubevirt/tests/network",
visibility = ["//visibility:public"],
deps = [
"//staging/src/kubevirt.io/client-go/api/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/kubecli:go_default_library",
"//tests:go_default_library",
"//tests/containerdisk:go_default_library",
"//vendor/github.com/onsi/ginkgo:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
],
)
2 changes: 2 additions & 0 deletions tests/network/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
reviewers:
- network-reviewers
32 changes: 32 additions & 0 deletions tests/network/framework.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* This file is part of the KubeVirt project
*
* 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.
*
* Copyright 2020 Red Hat, Inc.
*
*/

package network

import (
. "github.com/onsi/ginkgo"
)

func SIGDescribe(text string, body func()) bool {
return Describe("[sig-network] "+text, body)
}

func FSIGDescribe(text string, body func()) bool {
return FDescribe("[sig-network] "+text, body)
}
146 changes: 146 additions & 0 deletions tests/network/primary_pod_network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* This file is part of the KubeVirt project
*
* 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.
*
* Copyright 2020 Red Hat, Inc.
*
*/

package network

import (
"time"

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

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1 "kubevirt.io/client-go/api/v1"
"kubevirt.io/client-go/kubecli"

"kubevirt.io/kubevirt/tests"
cd "kubevirt.io/kubevirt/tests/containerdisk"
)

var _ = SIGDescribe("Primary Pod Network", func() {
var virtClient kubecli.KubevirtClient

BeforeEach(func() {
var err error
virtClient, err = kubecli.GetKubevirtClient()
Expect(err).NotTo(HaveOccurred(), "Should successfully initialize an API client")
})

Describe("Status", func() {
AssertReportedIP := func(vmi *v1.VirtualMachineInstance) {
By("Getting pod of the VMI")
vmiPod := tests.GetRunningPodByVirtualMachineInstance(vmi, tests.NamespaceTestDefault)

By("Making sure IP reported on the VMI matches the one on the pod")
Expect(vmi.Status.Interfaces[0].IP).To(Equal(vmiPod.Status.PodIP))
Expect(vmi.Status.Interfaces[0].IPs).NotTo(BeEmpty())
Expect(vmi.Status.Interfaces[0].IPs[0]).To(Equal(vmiPod.Status.PodIP))
}

Context("VMI connected to the pod network using the default (implicit) binding", func() {
var vmi *v1.VirtualMachineInstance

BeforeEach(func() {
vmi = setupVMI(virtClient, vmiWithDefaultBinding())
})

AfterEach(func() {
cleanupVMI(virtClient, vmi)
})

It("should report PodIP as its own on interface status", func() { AssertReportedIP(vmi) })
})

Context("VMI connected to the pod network using bridge binding", func() {
var vmi *v1.VirtualMachineInstance

BeforeEach(func() {
vmi = setupVMI(virtClient, vmiWithBridgeBinding())
})

AfterEach(func() {
cleanupVMI(virtClient, vmi)
})

It("should report PodIP as its own on interface status", func() { AssertReportedIP(vmi) })
})

Context("VMI connected to the pod network using masquerade binding", func() {
var vmi *v1.VirtualMachineInstance

BeforeEach(func() {
vmi = setupVMI(virtClient, vmiWithMasqueradeBinding())
})

AfterEach(func() {
cleanupVMI(virtClient, vmi)
})

It("should report PodIP as its own on interface status", func() { AssertReportedIP(vmi) })
})
})
})

func setupVMI(virtClient kubecli.KubevirtClient, vmi *v1.VirtualMachineInstance) *v1.VirtualMachineInstance {
By("Creating the VMI")
var err error
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).NotTo(HaveOccurred(), "VMI should be successfully created")

By("Waiting until the VMI gets ready")
vmi = tests.WaitUntilVMIReady(vmi, tests.LoggedInAlpineExpecter)

return vmi
}

func cleanupVMI(virtClient kubecli.KubevirtClient, vmi *v1.VirtualMachineInstance) {
if vmi != nil {
By("Deleting the VMI")
Expect(virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Delete(vmi.GetName(), &metav1.DeleteOptions{})).To(Succeed())

By("Waiting for the VMI to be gone")
Eventually(func() error {
_, err := virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Get(vmi.GetName(), &metav1.GetOptions{})
return err
}, 2*time.Minute, time.Second).Should(SatisfyAll(HaveOccurred(), WithTransform(errors.IsNotFound, BeTrue())), "The VMI should be gone within the given timeout")
}
}

func vmiWithDefaultBinding() *v1.VirtualMachineInstance {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi.Spec.Domain.Devices.Interfaces = nil
vmi.Spec.Networks = nil
return vmi
}

func vmiWithBridgeBinding() *v1.VirtualMachineInstance {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi.Spec.Domain.Devices.Interfaces = []v1.Interface{*v1.DefaultBridgeNetworkInterface()}
vmi.Spec.Networks = []v1.Network{*v1.DefaultPodNetwork()}
return vmi
}

func vmiWithMasqueradeBinding() *v1.VirtualMachineInstance {
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi.Spec.Domain.Devices.Interfaces = []v1.Interface{*v1.DefaultMasqueradeNetworkInterface()}
vmi.Spec.Networks = []v1.Network{*v1.DefaultPodNetwork()}
return vmi
}
2 changes: 2 additions & 0 deletions tests/tests_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (

"kubevirt.io/kubevirt/tests"
ginkgo_reporters "kubevirt.io/qe-tools/pkg/ginkgo-reporters"

_ "kubevirt.io/kubevirt/tests/network"
)

func TestTests(t *testing.T) {
Expand Down
24 changes: 0 additions & 24 deletions tests/vmi_networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,30 +816,6 @@ sockfd = None`})
Expect(err.Error()).To(ContainSubstring("Bridge interface is not enabled in kubevirt-config"))
})
})

Context("VirtualMachineInstance connected to the pod network", func() {
var vmi *v1.VirtualMachineInstance

BeforeEach(func() {
tests.BeforeTestCleanup()

vmi = tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
tests.AddExplicitPodNetworkInterface(vmi)

By("Starting tested VMI")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).NotTo(HaveOccurred(), "VMI should be successfully created")
vmi = tests.WaitUntilVMIReady(vmi, tests.LoggedInAlpineExpecter)
})

It("should report IP address matching the launcher PodIP in its status", func() {
vmiPod := tests.GetRunningPodByVirtualMachineInstance(vmi, tests.NamespaceTestDefault)

Expect(vmi.Status.Interfaces[0].IP).To(Equal(vmiPod.Status.PodIP), "The address reported in VMI's IP should match the PodIP")
Expect(vmi.Status.Interfaces[0].IPs).NotTo(BeEmpty(), "VMI should report a list of its IP addresses")
Expect(vmi.Status.Interfaces[0].IPs[0]).To(Equal(vmiPod.Status.PodIP), "The first address reported in VMI's IPs should match the PodIP")
})
})
})

func waitUntilVMIReady(vmi *v1.VirtualMachineInstance, expecterFactory tests.VMIExpecterFactory) *v1.VirtualMachineInstance {
Expand Down

0 comments on commit 442a4c8

Please sign in to comment.