Skip to content

Commit

Permalink
Merge pull request kubevirt#2199 from rmohr/prow-preparations
Browse files Browse the repository at this point in the history
Prepare automation test script for prow
  • Loading branch information
rmohr authored Apr 30, 2019
2 parents f6494e9 + 4b95c2f commit f8bb43a
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 95 deletions.
16 changes: 3 additions & 13 deletions automation/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
set -ex

export WORKSPACE="${WORKSPACE:-$PWD}"
readonly ARTIFACTS_PATH="$WORKSPACE/exported-artifacts"
readonly ARTIFACTS_PATH="${ARTIFACTS-$WORKSPACE/exported-artifacts}"
readonly TEMPLATES_SERVER="https://templates.ovirt.org/kubevirt/"

if [[ $TARGET =~ windows.* ]]; then
Expand Down Expand Up @@ -140,17 +140,7 @@ fi

kubectl() { cluster/kubectl.sh "$@"; }


# If run on CI use random kubevirt system-namespaces
if [ -n "${JOB_NAME}" ]; then
export NAMESPACE="kubevirt-system-$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)"
cat >hack/config-local.sh <<EOF
namespace=${NAMESPACE}
EOF
else
export NAMESPACE="${NAMESPACE:-kubevirt}"
fi

export NAMESPACE="${NAMESPACE:-kubevirt}"

# Make sure that the VM is properly shut down on exit
trap '{ make cluster-down; }' EXIT SIGINT SIGTERM SIGSTOP
Expand Down Expand Up @@ -245,7 +235,7 @@ kubectl version

mkdir -p "$ARTIFACTS_PATH"

ginko_params="--ginkgo.noColor --junit-output=$ARTIFACTS_PATH/tests.junit.xml"
ginko_params="--ginkgo.noColor --junit-output=$ARTIFACTS_PATH/junit.functest.xml"

# Prepare PV for Windows testing
if [[ $TARGET =~ windows.* ]]; then
Expand Down
8 changes: 4 additions & 4 deletions pkg/virt-launcher/virtwrap/cli/generated_mock_libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ func (_mr *_MockVirDomainRecorder) ShutdownFlags(arg0 interface{}) *gomock.Call
return _mr.mock.ctrl.RecordCall(_mr.mock, "ShutdownFlags", arg0)
}

func (_m *MockVirDomain) Undefine() error {
ret := _m.ctrl.Call(_m, "Undefine")
func (_m *MockVirDomain) UndefineFlags(flags libvirt_go.DomainUndefineFlagsValues) error {
ret := _m.ctrl.Call(_m, "UndefineFlags", flags)
ret0, _ := ret[0].(error)
return ret0
}

func (_mr *_MockVirDomainRecorder) Undefine() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Undefine")
func (_mr *_MockVirDomainRecorder) UndefineFlags(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "UndefineFlags", arg0)
}

func (_m *MockVirDomain) GetName() (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/virt-launcher/virtwrap/cli/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ type VirDomain interface {
Resume() error
DestroyFlags(flags libvirt.DomainDestroyFlags) error
ShutdownFlags(flags libvirt.DomainShutdownFlags) error
Undefine() error
UndefineFlags(flags libvirt.DomainUndefineFlagsValues) error
GetName() (string, error)
GetUUIDString() (string, error)
GetXMLDesc(flags libvirt.DomainXMLFlags) (string, error)
Expand Down
2 changes: 1 addition & 1 deletion pkg/virt-launcher/virtwrap/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ func (l *LibvirtDomainManager) DeleteVMI(vmi *v1.VirtualMachineInstance) error {
}
defer dom.Free()

err = dom.Undefine()
err = dom.UndefineFlags(libvirt.DOMAIN_UNDEFINE_NVRAM)
if err != nil {
log.Log.Object(vmi).Reason(err).Error("Undefining the domain failed.")
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/virt-launcher/virtwrap/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ var _ = Describe("Manager", func() {
// Make sure that we always free the domain after use
mockDomain.EXPECT().Free()
mockConn.EXPECT().LookupDomainByName(testDomainName).Return(mockDomain, nil)
mockDomain.EXPECT().Undefine().Return(nil)
mockDomain.EXPECT().UndefineFlags(libvirt.DOMAIN_UNDEFINE_NVRAM).Return(nil)
manager, _ := NewLibvirtDomainManager(mockConn, "fake", nil, 0)
err := manager.DeleteVMI(newVMI(testNamespace, testVmName))
Expect(err).To(BeNil())
Expand Down
4 changes: 4 additions & 0 deletions tests/expose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
k8sv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8smetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1 "kubevirt.io/kubevirt/pkg/api/v1"
Expand Down Expand Up @@ -431,6 +432,9 @@ var _ = Describe("[rfe_id:253][crit:medium][vendor:[email protected]][level:comp
By("Verifying the VMI is back up AFTER restart (in Running status with new UID).")
Eventually(func() bool {
vmi, err = virtClient.VirtualMachineInstance(vmObj.Namespace).Get(vmObj.Name, &k8smetav1.GetOptions{})
if errors.IsNotFound(err) {
return false
}
Expect(err).ToNot(HaveOccurred())
vmiUIdAfterRestart := vmi.GetObjectMeta().GetUID()
newUId := (vmiUIdAfterRestart != vmiUIdBeforeRestart)
Expand Down
5 changes: 2 additions & 3 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ type ObjectEventWatcher struct {
resourceVersion string
startType startType
dontFailOnMissingEvent bool
abort chan struct{}
}

func NewObjectEventWatcher(object runtime.Object) *ObjectEventWatcher {
Expand Down Expand Up @@ -324,16 +323,16 @@ func (w *ObjectEventWatcher) Watch(abortChan chan struct{}, processFunc ProcessF
if w.timeout != nil {
select {
case <-done:
case <-w.abort:
case <-abortChan:
case <-time.After(*w.timeout):
if !w.dontFailOnMissingEvent {
Fail(fmt.Sprintf("Waited for %v seconds on the event stream to match a specific event", w.timeout.Seconds()), 1)
}
}
} else {
select {
case <-abortChan:
case <-done:
case <-w.abort:
}
}
}
Expand Down
110 changes: 38 additions & 72 deletions tests/vmi_multus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ var _ = Describe("Multus", func() {
virtClient, err := kubecli.GetKubevirtClient()
tests.PanicOnError(err)

var detachedVMI *v1.VirtualMachineInstance
var vmiOne *v1.VirtualMachineInstance
var vmiTwo *v1.VirtualMachineInstance
var nodes *k8sv1.NodeList

defaultInterface := v1.Interface{
Expand Down Expand Up @@ -90,6 +87,19 @@ var _ = Describe("Multus", func() {
},
}

AfterEach(func() {
// Multus tests need to ensure that old VMIs are gone
Expect(virtClient.RestClient().Delete().Namespace(tests.NamespaceTestDefault).Resource("virtualmachineinstances").Do().Error()).To(Succeed())
Expect(virtClient.RestClient().Delete().Namespace(tests.NamespaceTestAlternative).Resource("virtualmachineinstances").Do().Error()).To(Succeed())
Eventually(func() int {
list1, err := virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).List(&v13.ListOptions{})
Expect(err).ToNot(HaveOccurred())
list2, err := virtClient.VirtualMachineInstance(tests.NamespaceTestAlternative).List(&v13.ListOptions{})
Expect(err).ToNot(HaveOccurred())
return len(list1.Items) + len(list2.Items)
}, 180*time.Second, 1*time.Second).Should(BeZero())
})

createVMIOnNode := func(interfaces []v1.Interface, networks []v1.Network) *v1.VirtualMachineInstance {
vmi := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskAlpine), "#!/bin/bash\n")
vmi.Spec.Domain.Devices.Interfaces = interfaces
Expand Down Expand Up @@ -155,18 +165,10 @@ var _ = Describe("Multus", func() {

Describe("[rfe_id:694][crit:medium][vendor:[email protected]][level:component]VirtualMachineInstance using different types of interfaces.", func() {
Context("VirtualMachineInstance with cni ptp plugin interface", func() {
AfterEach(func() {
virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Delete(detachedVMI.Name, &v13.DeleteOptions{})
fmt.Printf("Waiting for vmi %s in %s namespace to be removed, this can take a while ...\n", detachedVMI.Name, tests.NamespaceTestDefault)
EventuallyWithOffset(1, func() bool {
return errors.IsNotFound(virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Delete(detachedVMI.Name, nil))
}, 180*time.Second, 1*time.Second).
Should(BeTrue())
})

It("[test_id:1751]should create a virtual machine with one interface", func() {
By("checking virtual machine instance can ping 10.1.1.1 using ptp cni plugin")
detachedVMI = tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
detachedVMI := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
detachedVMI.Spec.Domain.Devices.Interfaces = []v1.Interface{{Name: "ptp", InterfaceBindingMethod: v1.InterfaceBindingMethod{Bridge: &v1.InterfaceBridge{}}}}
detachedVMI.Spec.Networks = []v1.Network{
{Name: "ptp", NetworkSource: v1.NetworkSource{
Expand All @@ -183,7 +185,7 @@ var _ = Describe("Multus", func() {

It("[test_id:1752]should create a virtual machine with one interface with network definition from different namespace", func() {
By("checking virtual machine instance can ping 10.1.1.1 using ptp cni plugin")
detachedVMI = tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
detachedVMI := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
detachedVMI.Spec.Domain.Devices.Interfaces = []v1.Interface{{Name: "ptp", InterfaceBindingMethod: v1.InterfaceBindingMethod{Bridge: &v1.InterfaceBridge{}}}}
detachedVMI.Spec.Networks = []v1.Network{
{Name: "ptp", NetworkSource: v1.NetworkSource{
Expand All @@ -200,7 +202,7 @@ var _ = Describe("Multus", func() {

It("[test_id:1753]should create a virtual machine with two interfaces", func() {
By("checking virtual machine instance can ping 10.1.1.1 using ptp cni plugin")
detachedVMI = tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
detachedVMI := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")

detachedVMI.Spec.Domain.Devices.Interfaces = []v1.Interface{
defaultInterface,
Expand Down Expand Up @@ -236,17 +238,9 @@ var _ = Describe("Multus", func() {
})

Context("VirtualMachineInstance with multus network as default network", func() {
AfterEach(func() {
virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Delete(detachedVMI.Name, &v13.DeleteOptions{})
fmt.Printf("Waiting for vmi %s in %s namespace to be removed, this can take a while ...\n", detachedVMI.Name, tests.NamespaceTestDefault)
EventuallyWithOffset(1, func() bool {
return errors.IsNotFound(virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Delete(detachedVMI.Name, nil))
}, 180*time.Second, 1*time.Second).
Should(BeTrue())
})

It("should create a virtual machine with one interface with multus default network definition", func() {
detachedVMI = tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
detachedVMI := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
detachedVMI.Spec.Domain.Devices.Interfaces = []v1.Interface{{Name: "ptp", InterfaceBindingMethod: v1.InterfaceBindingMethod{Bridge: &v1.InterfaceBridge{}}}}
detachedVMI.Spec.Networks = []v1.Network{
{Name: "ptp", NetworkSource: v1.NetworkSource{
Expand Down Expand Up @@ -281,9 +275,6 @@ var _ = Describe("Multus", func() {
})

Context("VirtualMachineInstance with cni ptp plugin interface with custom MAC address", func() {
AfterEach(func() {
deleteVMIs(virtClient, []*v1.VirtualMachineInstance{vmiOne})
})

table.DescribeTable("configure valid custom MAC address on ptp interface", func(networkName string) {
customMacAddress := "50:00:00:00:90:0d"
Expand All @@ -307,7 +298,7 @@ var _ = Describe("Multus", func() {

By("Creating a VM with custom MAC address on its ptp interface.")
interfaces[0].MacAddress = customMacAddress
vmiOne = createVMIOnNode(interfaces, networks)
vmiOne := createVMIOnNode(interfaces, networks)
tests.WaitUntilVMIReady(vmiOne, tests.LoggedInAlpineExpecter)

By("Configuring static IP address to ptp interface.")
Expand Down Expand Up @@ -341,14 +332,11 @@ var _ = Describe("Multus", func() {
BeforeEach(func() {
tests.SkipIfNoSriovDevicePlugin(virtClient)
})
AfterEach(func() {
deleteVMIs(virtClient, []*v1.VirtualMachineInstance{vmiOne})
})

It("[test_id:1754]should create a virtual machine with sriov interface", func() {
// since neither cirros nor alpine has drivers for Intel NICs, we are left with fedora
userData := "#cloud-config\npassword: fedora\nchpasswd: { expire: False }\n"
vmiOne = tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskFedora), userData)
vmiOne := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskFedora), userData)
tests.AddExplicitPodNetworkInterface(vmiOne)

iface := v1.Interface{Name: "sriov", InterfaceBindingMethod: v1.InterfaceBindingMethod{SRIOV: &v1.InterfaceSRIOV{}}}
Expand Down Expand Up @@ -404,7 +392,7 @@ var _ = Describe("Multus", func() {
It("[test_id:1755]should create a virtual machine with two sriov interfaces referring the same resource", func() {
// since neither cirros nor alpine has drivers for Intel NICs, we are left with fedora
userData := "#cloud-config\npassword: fedora\nchpasswd: { expire: False }\n"
vmiOne = tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskFedora), userData)
vmiOne := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskFedora), userData)
tests.AddExplicitPodNetworkInterface(vmiOne)

for _, name := range []string{"sriov", "sriov2"} {
Expand Down Expand Up @@ -464,17 +452,14 @@ var _ = Describe("Multus", func() {
})

Context("VirtualMachineInstance with ovs-cni plugin interface", func() {
AfterEach(func() {
deleteVMIs(virtClient, []*v1.VirtualMachineInstance{vmiOne, vmiTwo})
})

It("[test_id:1577]should create two virtual machines with one interface", func() {
By("checking virtual machine instance can ping the secondary virtual machine instance using ovs-cni plugin")
interfaces := []v1.Interface{ovsInterface}
networks := []v1.Network{ovsNetwork}

vmiOne = createVMIOnNode(interfaces, networks)
vmiTwo = createVMIOnNode(interfaces, networks)
vmiOne := createVMIOnNode(interfaces, networks)
vmiTwo := createVMIOnNode(interfaces, networks)

tests.WaitUntilVMIReady(vmiOne, tests.LoggedInAlpineExpecter)
tests.WaitUntilVMIReady(vmiTwo, tests.LoggedInAlpineExpecter)
Expand Down Expand Up @@ -502,8 +487,8 @@ var _ = Describe("Multus", func() {
ovsNetwork,
}

vmiOne = createVMIOnNode(interfaces, networks)
vmiTwo = createVMIOnNode(interfaces, networks)
vmiOne := createVMIOnNode(interfaces, networks)
vmiTwo := createVMIOnNode(interfaces, networks)

tests.WaitUntilVMIReady(vmiOne, tests.LoggedInAlpineExpecter)
tests.WaitUntilVMIReady(vmiTwo, tests.LoggedInAlpineExpecter)
Expand All @@ -527,18 +512,14 @@ var _ = Describe("Multus", func() {
ovsIfIdx := 0
customMacAddress := "50:00:00:00:90:0d"

AfterEach(func() {
deleteVMIs(virtClient, []*v1.VirtualMachineInstance{vmiOne, vmiTwo})
})

It("[test_id:676]should configure valid custom MAC address on ovs-cni interface.", func() {
By("Creating a VM with ovs-cni network interface and default MAC address.")
vmiTwo = createVMIOnNode(interfaces, networks)
vmiTwo := createVMIOnNode(interfaces, networks)
tests.WaitUntilVMIReady(vmiTwo, tests.LoggedInAlpineExpecter)

By("Creating another VM with custom MAC address on its ovs-cni interface.")
interfaces[ovsIfIdx].MacAddress = customMacAddress
vmiOne = createVMIOnNode(interfaces, networks)
vmiOne := createVMIOnNode(interfaces, networks)
tests.WaitUntilVMIReady(vmiOne, tests.LoggedInAlpineExpecter)

By("Configuring static IP address to the ovs interface.")
Expand Down Expand Up @@ -569,9 +550,6 @@ var _ = Describe("Multus", func() {
})
})
Context("Single VirtualMachineInstance with ovs-cni plugin interface", func() {
AfterEach(func() {
deleteVMIs(virtClient, []*v1.VirtualMachineInstance{vmiOne})
})

It("[test_id:1756]should report all interfaces in Status", func() {
interfaces := []v1.Interface{
Expand All @@ -583,7 +561,7 @@ var _ = Describe("Multus", func() {
ovsNetwork,
}

vmiOne = createVMIOnNode(interfaces, networks)
vmiOne := createVMIOnNode(interfaces, networks)

tests.WaitUntilVMIReady(vmiOne, tests.LoggedInAlpineExpecter)

Expand Down Expand Up @@ -645,11 +623,6 @@ var _ = Describe("Multus", func() {

Describe("[rfe_id:1758][crit:medium][vendor:[email protected]][level:component]VirtualMachineInstance definition", func() {
Context("with quemu guest agent", func() {
var agentVMI *v1.VirtualMachineInstance

AfterEach(func() {
deleteVMIs(virtClient, []*v1.VirtualMachineInstance{agentVMI})
})

It("[test_id:1757] should report guest interfaces in VMI status", func() {
interfaces := []v1.Interface{
Expand All @@ -665,16 +638,20 @@ var _ = Describe("Multus", func() {
ep2Ip := "1.0.0.11/24"
ep1IpV6 := "fe80::ce3d:82ff:fe52:24c0/64"
ep2IpV6 := "fe80::ce3d:82ff:fe52:24c1/64"
agentVMI = tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskFedora), fmt.Sprintf(`#!/bin/bash
echo "fedora" |passwd fedora --stdin
ip link add ep1 type veth peer name ep2
ip addr add %s dev ep1
userdata := fmt.Sprintf(`#!/bin/bash
echo "fedora" |passwd fedora --stdin
setenforce 0
ip link add ep1 type veth peer name ep2
ip addr add %s dev ep1
ip addr add %s dev ep2
ip addr add %s dev ep1
ip addr add %s dev ep2
yum install -y qemu-guest-agent
systemctl start qemu-guest-agent
`, ep1Ip, ep2Ip, ep1IpV6, ep2IpV6))
mkdir -p /usr/local/bin
curl %s > /usr/local/bin/qemu-ga
chmod +x /usr/local/bin/qemu-ga
systemd-run --unit=guestagent /usr/local/bin/qemu-ga
`, ep1Ip, ep2Ip, ep1IpV6, ep2IpV6, tests.GuestAgentHttpUrl)
agentVMI := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskFedora), userdata)

agentVMI.Spec.Domain.Devices.Interfaces = interfaces
agentVMI.Spec.Networks = networks
Expand Down Expand Up @@ -733,17 +710,6 @@ var _ = Describe("Multus", func() {
})
})

func deleteVMIs(virtClient kubecli.KubevirtClient, vmis []*v1.VirtualMachineInstance) {
for _, deleteVMI := range vmis {
virtClient.VirtualMachineInstance("default").Delete(deleteVMI.Name, &v13.DeleteOptions{})
fmt.Printf("Waiting for vmi %s in %s namespace to be removed, this can take a while ...\n", deleteVMI.Name, tests.NamespaceTestDefault)
EventuallyWithOffset(1, func() bool {
return errors.IsNotFound(virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Delete(deleteVMI.Name, nil))
}, 180*time.Second, 1*time.Second).
Should(BeTrue())
}
}

func configInterface(vmi *v1.VirtualMachineInstance, interfaceName, interfaceAddress, prompt string) {
cmdCheck := fmt.Sprintf("ip addr add %s dev %s\n", interfaceAddress, interfaceName)
err := tests.CheckForTextExpecter(vmi, []expect.Batcher{
Expand Down

0 comments on commit f8bb43a

Please sign in to comment.