Skip to content

Commit

Permalink
Merge pull request kubevirt#747 from rmohr/prefix
Browse files Browse the repository at this point in the history
Make functional test configuration more flexible
  • Loading branch information
rmohr authored Feb 21, 2018
2 parents 8257f41 + c1b5d57 commit b0af705
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 134 deletions.
4 changes: 2 additions & 2 deletions hack/dockerized
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ _rsync() {
rm ${KUBEVIRT_DIR}/.glide*.hash -f

# Copy kubevirt into the persistent docker volume
_rsync --delete --exclude 'cluster/vagrant*' --exclude "_out" --exclude ".vagrant" ${KUBEVIRT_DIR}/ "rsync://[email protected]:${RSYNCD_PORT}/build"
_rsync --delete --exclude 'cluster/**/.kubectl' --exclude 'cluster/**/.oc' --exclude 'cluster/**/.kubeconfig' --exclude "_out" --exclude ".vagrant" ${KUBEVIRT_DIR}/ "rsync://[email protected]:${RSYNCD_PORT}/build"

# Run the command
test -t 1 && USE_TTY="-it"
docker run --rm -v "${BUILDER}:/root:rw,z" ${USE_TTY} -w "/root/go/src/kubevirt.io/kubevirt" ${BUILDER} "$@"

# Copy the whole kubevirt data out to get generated sources and formatting changes
_rsync --exclude '.glide*' --exclude "_out" --exclude "vendor" --exclude ".vagrant" --exclude ".git" "rsync://[email protected]:${RSYNCD_PORT}/build" ${KUBEVIRT_DIR}/
_rsync --exclude '.glide*' --exclude 'cluster/**/.kubectl' --exclude 'cluster/**/.oc' --exclude 'cluster/**/.kubeconfig' --exclude "_out" --exclude "vendor" --exclude ".vagrant" --exclude ".git" "rsync://[email protected]:${RSYNCD_PORT}/build" ${KUBEVIRT_DIR}/
if [ "$SYNC_VENDOR" = "true" ]; then
_rsync --delete "rsync://[email protected]:${RSYNCD_PORT}/vendor" ${VENDOR_DIR}
fi
Expand Down
2 changes: 1 addition & 1 deletion hack/functests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ set -e
source hack/common.sh
source hack/config.sh

${TESTS_OUT_DIR}/tests.test -kubeconfig=${kubeconfig} -test.timeout 40m ${FUNC_TEST_ARGS}
${TESTS_OUT_DIR}/tests.test -kubeconfig=${kubeconfig} -tag=${docker_tag} -prefix=${docker_prefix} -test.timeout 40m ${FUNC_TEST_ARGS}
6 changes: 3 additions & 3 deletions tests/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var _ = Describe("Console", func() {
Context("with a cirros image", func() {
It("should return that we are running cirros", func() {
RunVMAndExpectConsoleOutput(
"kubevirt/cirros-registry-disk-demo:devel",
tests.RegistryDiskFor(tests.RegistryDiskCirros),
"checking http://169.254.169.254/2009-04-04/instance-id",
)
}, 140)
Expand All @@ -75,14 +75,14 @@ var _ = Describe("Console", func() {
Context("with a fedora image", func() {
It("should return that we are running fedora", func() {
RunVMAndExpectConsoleOutput(
"kubevirt/fedora-cloud-registry-disk-demo:devel",
tests.RegistryDiskFor(tests.RegistryDiskFedora),
"Welcome to",
)
}, 140)
})

It("should be able to reconnect to console multiple times", func() {
vm := tests.NewRandomVMWithEphemeralDisk("kubevirt/alpine-registry-disk-demo:devel")
vm := tests.NewRandomVMWithEphemeralDisk(tests.RegistryDiskFor(tests.RegistryDiskAlpine))

By("Creating a new VM")
Expect(virtClient.RestClient().Post().Resource("virtualmachines").Namespace(tests.NamespaceTestDefault).Body(vm).Do().Error()).To(Succeed())
Expand Down
6 changes: 3 additions & 3 deletions tests/registry_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var _ = Describe("RegistryDisk", func() {
Describe("Starting and stopping the same VM", func() {
Context("with ephemeral registry disk", func() {
It("should success multiple times", func(done Done) {
vm := tests.NewRandomVMWithEphemeralDisk("kubevirt/cirros-registry-disk-demo:devel")
vm := tests.NewRandomVMWithEphemeralDisk(tests.RegistryDiskFor(tests.RegistryDiskCirros))
num := 2
for i := 0; i < num; i++ {
By("Starting the VM")
Expand All @@ -112,7 +112,7 @@ var _ = Describe("RegistryDisk", func() {
Describe("Starting a VM", func() {
Context("with ephemeral registry disk", func() {
It("should not modify the spec on status update", func() {
vm := tests.NewRandomVMWithEphemeralDisk("kubevirt/cirros-registry-disk-demo:devel")
vm := tests.NewRandomVMWithEphemeralDisk(tests.RegistryDiskFor(tests.RegistryDiskCirros))
v1.SetObjectDefaults_VirtualMachine(vm)

By("Starting the VM")
Expand All @@ -134,7 +134,7 @@ var _ = Describe("RegistryDisk", func() {
vms := make([]*v1.VirtualMachine, 0, num)
objs := make([]runtime.Object, 0, num)
for i := 0; i < num; i++ {
vm := tests.NewRandomVMWithEphemeralDisk("kubevirt/cirros-registry-disk-demo:devel")
vm := tests.NewRandomVMWithEphemeralDisk(tests.RegistryDiskFor(tests.RegistryDiskCirros))
// FIXME if we give too much ram, the vms really boot and eat all our memory (cache?)
vm.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("1M")
obj := LaunchVM(vm)
Expand Down
2 changes: 1 addition & 1 deletion tests/replicaset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var _ = Describe("VirtualMachineReplicaSet", func() {

newReplicaSet := func() *v1.VirtualMachineReplicaSet {
By("Create a new VM replica set")
template := tests.NewRandomVMWithEphemeralDisk("kubevirt/cirros-registry-disk-demo:devel")
template := tests.NewRandomVMWithEphemeralDisk(tests.RegistryDiskFor(tests.RegistryDiskCirros))
newRS := tests.NewRandomReplicaSetFromVM(template, int32(0))
newRS, err = virtClient.ReplicaSet(tests.NamespaceTestDefault).Create(newRS)
Expect(err).ToNot(HaveOccurred())
Expand Down
89 changes: 32 additions & 57 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,21 @@ import (

"github.com/google/goexpect"

"flag"

"kubevirt.io/kubevirt/pkg/api/v1"
"kubevirt.io/kubevirt/pkg/kubecli"
"kubevirt.io/kubevirt/pkg/log"
)

var KubeVirtVersionTag string = "latest"
var KubeVirtRepoPrefix string = "kubevirt"

func init() {
flag.StringVar(&KubeVirtVersionTag, "tag", "latest", "Set the image tag or digest to use")
flag.StringVar(&KubeVirtRepoPrefix, "prefix", "kubevirt", "Set the repository prefix for all images")
}

type EventType string

const (
Expand Down Expand Up @@ -87,22 +97,11 @@ const (
DiskAlpineISCSI = "disk-alpine-iscsi"
)

const (
labelISCSIPod = "iscsi-demo-target"
labelISCSIWithAuthPod = "iscsi-auth-demo-target"
labelNFSPod = "nfs-server-demo"
)

const (
iscsiIqn = "iqn.2017-01.io.kubevirt:sn.42"
iscsiSecretName = "iscsi-demo-secret"
)

const (
nfsPathAlpine = "/nfsshare/alpine"
nfsPathCirros = "/nfsshare/cirros"
)

type ProcessFunc func(event *k8sv1.Event) (done bool)

type ObjectEventWatcher struct {
Expand Down Expand Up @@ -383,49 +382,6 @@ func newPvISCSI(os string, targetIp string, lun int32, withAuth bool) *k8sv1.Per
return pv
}

func createPvNFS(os string, path string) {
virtCli, err := kubecli.GetKubevirtClient()
PanicOnError(err)

nfsServer := getPodIpByLabel(labelNFSPod)

_, err = virtCli.CoreV1().PersistentVolumes().Create(newPvNFS(os, nfsServer, path))
if !errors.IsAlreadyExists(err) {
PanicOnError(err)
}
}

func newPvNFS(os string, nfsServer string, path string) *k8sv1.PersistentVolume {
quantity, err := resource.ParseQuantity("1Gi")
PanicOnError(err)

name := fmt.Sprintf("%s-disk-for-tests", os)
label := os

pv := &k8sv1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: map[string]string{
"kubevirt.io/test": label,
},
},
Spec: k8sv1.PersistentVolumeSpec{
AccessModes: []k8sv1.PersistentVolumeAccessMode{k8sv1.ReadWriteOnce},
Capacity: k8sv1.ResourceList{
"storage": quantity,
},
PersistentVolumeReclaimPolicy: k8sv1.PersistentVolumeReclaimRetain,
PersistentVolumeSource: k8sv1.PersistentVolumeSource{
NFS: &k8sv1.NFSVolumeSource{
Server: nfsServer,
Path: path,
},
},
},
}
return pv
}

func deletePVC(os string, withAuth bool) {
virtCli, err := kubecli.GetKubevirtClient()
PanicOnError(err)
Expand Down Expand Up @@ -700,7 +656,7 @@ func NewRandomVMWithPVC(claimName string) *v1.VirtualMachine {
}

func NewRandomVMWithWatchdog() *v1.VirtualMachine {
vm := NewRandomVMWithEphemeralDisk("kubevirt/alpine-registry-disk-demo:devel")
vm := NewRandomVMWithEphemeralDisk(RegistryDiskFor(RegistryDiskAlpine))

vm.Spec.Domain.Devices.Watchdog = &v1.Watchdog{
Name: "mywatchdog",
Expand Down Expand Up @@ -788,7 +744,7 @@ func NewBool(x bool) *bool {
return &x
}

func RenderJob(name string, dockerTag string, cmd []string, args []string) *k8sv1.Pod {
func RenderJob(name string, cmd []string, args []string) *k8sv1.Pod {
job := k8sv1.Pod{
ObjectMeta: metav1.ObjectMeta{
GenerateName: name,
Expand All @@ -801,7 +757,7 @@ func RenderJob(name string, dockerTag string, cmd []string, args []string) *k8sv
Containers: []k8sv1.Container{
{
Name: name,
Image: "kubevirt/vm-killer:" + dockerTag,
Image: fmt.Sprintf("%s/vm-killer:%s", KubeVirtRepoPrefix, KubeVirtVersionTag),
Command: cmd,
Args: args,
SecurityContext: &k8sv1.SecurityContext{
Expand Down Expand Up @@ -843,3 +799,22 @@ func NewConsoleExpecter(virtCli kubecli.KubevirtClient, vm *v1.VirtualMachine, c
Check: func() bool { return true },
}, timeout, opts...)
}

type RegistryDisk string

const (
RegistryDiskCirros RegistryDisk = "cirros"
RegistryDiskAlpine RegistryDisk = "alpine"
RegistryDiskFedora RegistryDisk = "fedora-cloud"
)

// RegistryDiskFor takes the name of an image and returns the full
// registry diks image path.
// Supported values are: cirros, fedora, alpine
func RegistryDiskFor(name RegistryDisk) string {
switch name {
case RegistryDiskCirros, RegistryDiskAlpine, RegistryDiskFedora:
return fmt.Sprintf("%s/%s-registry-disk-demo:%s", KubeVirtRepoPrefix, name, KubeVirtVersionTag)
}
panic(fmt.Sprintf("Unsupported registry disk %s", name))
}
4 changes: 2 additions & 2 deletions tests/vm_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var _ = Describe("Configurations", func() {
var vm *v1.VirtualMachine

BeforeEach(func() {
vm = tests.NewRandomVMWithEphemeralDisk("kubevirt/alpine-registry-disk-demo:devel")
vm = tests.NewRandomVMWithEphemeralDisk(tests.RegistryDiskFor(tests.RegistryDiskAlpine))
})
It("should report 3 cpu cores under guest OS", func() {
vm.Spec.Domain.CPU = &v1.CPU{
Expand Down Expand Up @@ -88,7 +88,7 @@ var _ = Describe("Configurations", func() {
BeforeEach(func() {
// ordering:
// use a small disk for the other ones
containerImage := "kubevirt/cirros-registry-disk-demo:devel"
containerImage := tests.RegistryDiskFor(tests.RegistryDiskCirros)
// virtio - added by NewRandomVMWithEphemeralDisk
vm = tests.NewRandomVMWithEphemeralDiskAndUserdata(containerImage, "echo hi!\n")
// sata
Expand Down
9 changes: 2 additions & 7 deletions tests/vm_networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package tests_test

import (
"flag"
"os"
"time"

. "github.com/onsi/ginkgo"
Expand All @@ -44,10 +43,6 @@ import (
)

var _ = Describe("Networking", func() {
dockerTag := os.Getenv("docker_tag")
if dockerTag == "" {
dockerTag = "latest"
}

flag.Parse()

Expand All @@ -64,7 +59,7 @@ var _ = Describe("Networking", func() {
var wg sync.WaitGroup

createAndLogin := func() (vm *v1.VirtualMachine) {
vm = tests.NewRandomVMWithEphemeralDiskAndUserdata("kubevirt/cirros-registry-disk-demo:devel", "#!/bin/bash\necho 'hello'\n")
vm = tests.NewRandomVMWithEphemeralDiskAndUserdata(tests.RegistryDiskFor(tests.RegistryDiskCirros), "#!/bin/bash\necho 'hello'\n")

// Start VM
vm, err = virtClient.VM(tests.NamespaceTestDefault).Create(vm)
Expand Down Expand Up @@ -153,7 +148,7 @@ var _ = Describe("Networking", func() {

// Run netcat and give it one second to ghet "Hello World!" back from the VM
check := []string{fmt.Sprintf("while read x; do test \"$x\" = \"Hello World!\"; exit $?; done < <(nc %s 1500 -i 1 -w 1)", ip)}
job := tests.RenderJob("netcat", dockerTag, []string{"/bin/bash", "-c"}, check)
job := tests.RenderJob("netcat", []string{"/bin/bash", "-c"}, check)
job.Spec.Affinity = &v12.Affinity{
NodeAffinity: &v12.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &v12.NodeSelector{
Expand Down
4 changes: 2 additions & 2 deletions tests/vm_userdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var _ = Describe("CloudInit UserData", func() {
magicStr := "printed from cloud-init userdata"
userData := fmt.Sprintf("#!/bin/sh\n\necho '%s'\n", magicStr)

vm := tests.NewRandomVMWithEphemeralDiskAndUserdata("kubevirt/cirros-registry-disk-demo:devel", userData)
vm := tests.NewRandomVMWithEphemeralDiskAndUserdata(tests.RegistryDiskFor(tests.RegistryDiskCirros), userData)
obj := LaunchVM(vm)
VerifyUserDataVM(vm, obj, magicStr)
close(done)
Expand All @@ -88,7 +88,7 @@ var _ = Describe("CloudInit UserData", func() {
It("should take user-data from k8s secret", func(done Done) {
magicStr := "printed from cloud-init userdata"
userData := fmt.Sprintf("#!/bin/sh\n\necho '%s'\n", magicStr)
vm := tests.NewRandomVMWithEphemeralDiskAndUserdata("kubevirt/cirros-registry-disk-demo:devel", userData)
vm := tests.NewRandomVMWithEphemeralDiskAndUserdata(tests.RegistryDiskFor(tests.RegistryDiskCirros), userData)

for _, volume := range vm.Spec.Volumes {
if volume.CloudInitNoCloud == nil {
Expand Down
Loading

0 comments on commit b0af705

Please sign in to comment.