Skip to content

Commit

Permalink
Merge pull request #809 from cynepco3hahue/windows_tests
Browse files Browse the repository at this point in the history
Add Windows VM tests
  • Loading branch information
rmohr committed Apr 8, 2018
2 parents 061db6d + 428b051 commit e83802d
Show file tree
Hide file tree
Showing 5 changed files with 353 additions and 30 deletions.
2 changes: 1 addition & 1 deletion hack/config-default.sh
@@ -1,5 +1,5 @@
binaries="cmd/virt-controller cmd/virt-launcher cmd/virt-handler cmd/virtctl cmd/fake-qemu-process cmd/virt-api cmd/subresource-access-test"
docker_images="cmd/virt-controller cmd/virt-launcher cmd/virt-handler cmd/virt-api images/iscsi-demo-target-tgtd images/vm-killer cmd/registry-disk-v1alpha images/cirros-registry-disk-demo images/fedora-cloud-registry-disk-demo images/alpine-registry-disk-demo cmd/subresource-access-test"
docker_images="cmd/virt-controller cmd/virt-launcher cmd/virt-handler cmd/virt-api images/iscsi-demo-target-tgtd images/vm-killer cmd/registry-disk-v1alpha images/cirros-registry-disk-demo images/fedora-cloud-registry-disk-demo images/alpine-registry-disk-demo cmd/subresource-access-test images/winrmcli"
docker_prefix=kubevirt
docker_tag=${DOCKER_TAG:-latest}
master_ip=192.168.200.2
Expand Down
33 changes: 33 additions & 0 deletions images/winrmcli/Dockerfile
@@ -0,0 +1,33 @@
#
# 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 2018 Red Hat, Inc.
#

FROM fedora:27

MAINTAINER "The KubeVirt Project" <kubevirt-dev@googlegroups.com>
ENV container docker

RUN dnf -y install make git gcc && dnf -y clean all

ENV GIMME_GO_VERSION=1.9.2
RUN mkdir -p /gimme && curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | HOME=/gimme bash >> /etc/profile.d/gimme.sh

ENV GOPATH="/go" GOBIN="/usr/bin"
RUN \
mkdir -p /go && \
source /etc/profile.d/gimme.sh && \
go get github.com/masterzen/winrm-cli
116 changes: 98 additions & 18 deletions tests/utils.go
Expand Up @@ -20,32 +20,31 @@
package tests

import (
"bytes"
"encoding/base64"
"flag"
"fmt"
"io"
"reflect"
"time"

"github.com/google/goexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/cobra"

k8sv1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/rand"

"k8s.io/apimachinery/pkg/api/errors"

"k8s.io/apimachinery/pkg/api/resource"

"io"

"github.com/google/goexpect"

"flag"

"github.com/spf13/cobra"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/remotecommand"

"kubevirt.io/kubevirt/pkg/api/v1"
"kubevirt.io/kubevirt/pkg/kubecli"
Expand Down Expand Up @@ -76,9 +75,9 @@ const SubresourceTestLabel = "subresource-access-test-pod"

const (
// tests.NamespaceTestDefault is the default namespace, to test non-infrastructure related KubeVirt objects.
NamespaceTestDefault string = "kubevirt-test-default"
NamespaceTestDefault = "kubevirt-test-default"
// NamespaceTestAlternative is used to test controller-namespace independency.
NamespaceTestAlternative string = "kubevirt-test-alternative"
NamespaceTestAlternative = "kubevirt-test-alternative"
)

var testNamespaces = []string{NamespaceTestDefault, NamespaceTestAlternative}
Expand All @@ -99,17 +98,24 @@ const (

const (
osAlpineISCSI = "alpine-iscsi"
osWindows = "windows"
)

const (
DiskAlpineISCSI = "disk-alpine-iscsi"
DiskWindows = "disk-windows"
)

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

const (
defaultDiskSize = "1Gi"
defaultWindowsDiskSize = "30Gi"
)

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

type ObjectEventWatcher struct {
Expand Down Expand Up @@ -271,6 +277,8 @@ func AfterTestSuitCleanup() {
cleanNamespaces()
cleanupSubresourceServiceAccount()

deletePVC(osWindows)

deletePVC(osAlpineISCSI)
deletePV(osAlpineISCSI)

Expand All @@ -292,21 +300,23 @@ func BeforeTestSuitSetup() {
createIscsiSecrets()

createPvISCSI(osAlpineISCSI, 2)
createPVC(osAlpineISCSI)
createPVC(osAlpineISCSI, defaultDiskSize)

createPVC(osWindows, defaultWindowsDiskSize)
}

func createPVC(os string) {
func createPVC(os string, size string) {
virtCli, err := kubecli.GetKubevirtClient()
PanicOnError(err)

_, err = virtCli.CoreV1().PersistentVolumeClaims(NamespaceTestDefault).Create(newPVC(os))
_, err = virtCli.CoreV1().PersistentVolumeClaims(NamespaceTestDefault).Create(newPVC(os, size))
if !errors.IsAlreadyExists(err) {
PanicOnError(err)
}
}

func newPVC(os string) *k8sv1.PersistentVolumeClaim {
quantity, err := resource.ParseQuantity("1Gi")
func newPVC(os string, size string) *k8sv1.PersistentVolumeClaim {
quantity, err := resource.ParseQuantity(size)
PanicOnError(err)

name := fmt.Sprintf("disk-%s", os)
Expand Down Expand Up @@ -970,3 +980,73 @@ func NewRepeatableVirtctlCommand(args ...string) func() error {
return cmd.Execute()
}
}

func ExecuteCommandOnPod(virtCli kubecli.KubevirtClient, pod *k8sv1.Pod, containerName string, command []string) (string, error) {
var (
stdout bytes.Buffer
stderr bytes.Buffer
)

req := virtCli.CoreV1().RESTClient().Post().
Resource("pods").
Name(pod.Name).
Namespace(pod.Namespace).
SubResource("exec").
Param("container", containerName)

req.VersionedParams(&k8sv1.PodExecOptions{
Container: containerName,
Command: command,
Stdin: false,
Stdout: true,
Stderr: true,
TTY: false,
}, scheme.ParameterCodec)

config, err := kubecli.GetKubevirtClientConfig()
if err != nil {
return "", err
}

exec, err := remotecommand.NewSPDYExecutor(config, "POST", req.URL())
if err != nil {
return "", err
}

err = exec.Stream(remotecommand.StreamOptions{
Stdout: &stdout,
Stderr: &stderr,
Tty: false,
})

if err != nil {
return "", err
}

if stderr.Len() > 0 {
return "", fmt.Errorf("stderr: %v", stderr.String())
}

return stdout.String(), nil
}

func BeforeAll(fn func()) {
first := true
BeforeEach(func() {
if first {
fn()
first = false
}
})
}

func SkipIfNoWindowsImage(virtClient kubecli.KubevirtClient) {
windowsPv, err := virtClient.CoreV1().PersistentVolumes().Get(DiskWindows, metav1.GetOptions{})
if err != nil || (windowsPv.Status.Phase != k8sv1.VolumeAvailable && windowsPv.Status.Phase != k8sv1.VolumeReleased) {
Skip(fmt.Sprintf("Skip Windows tests that requires PVC %s", DiskWindows))
} else if windowsPv.Status.Phase == k8sv1.VolumeReleased {
windowsPv.Spec.ClaimRef = nil
_, err = virtClient.CoreV1().PersistentVolumes().Update(windowsPv)
Expect(err).ToNot(HaveOccurred())
}
}
12 changes: 1 addition & 11 deletions tests/vm_networking_test.go
Expand Up @@ -54,7 +54,7 @@ var _ = Describe("Networking", func() {
var outboundVM *v1.VirtualMachine

// TODO this is not optimal, since the one test which will initiate this, will look slow
BeforeAll(func() {
tests.BeforeAll(func() {
tests.BeforeTestCleanup()

var wg sync.WaitGroup
Expand Down Expand Up @@ -186,13 +186,3 @@ var _ = Describe("Networking", func() {
})

})

func BeforeAll(fn func()) {
first := true
BeforeEach(func() {
if first {
fn()
first = false
}
})
}

0 comments on commit e83802d

Please sign in to comment.