Skip to content

Commit

Permalink
[WIP] Add Windows VM tests
Browse files Browse the repository at this point in the history
To test Windows VM we need to create additional pod that
will have winrm-cli tool.

Tests:
- Start Windows VM
- Stop Windows VM
- Verify that Windows VM has correct UUID
- Verify that Windows VM has pod IP

Signed-off-by: Lukianov Artyom <alukiano@redhat.com>
  • Loading branch information
Lukianov Artyom committed Mar 13, 2018
1 parent e555d56 commit 30ad695
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 23 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"
docker_images="cmd/virt-controller cmd/virt-launcher cmd/virt-handler 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"
docker_images="cmd/virt-controller cmd/virt-launcher cmd/virt-handler 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 images/winrmcli"
docker_prefix=kubevirt
docker_tag=${DOCKER_TAG:-latest}
master_ip=192.168.200.2
Expand Down
24 changes: 24 additions & 0 deletions images/winrmcli/Dockerfile
@@ -0,0 +1,24 @@
#
# 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 golang:1.6

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

RUN go get github.com/masterzen/winrm-cli
85 changes: 74 additions & 11 deletions tests/utils.go
Expand Up @@ -20,29 +20,30 @@
package tests

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

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

k8sv1 "k8s.io/api/core/v1"

"k8s.io/apimachinery/pkg/api/meta"
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"
"k8s.io/client-go/tools/remotecommand"

"flag"

"kubevirt.io/kubevirt/pkg/api/v1"
"kubevirt.io/kubevirt/pkg/kubecli"
Expand Down Expand Up @@ -91,17 +92,26 @@ 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"
)

const VmResource = "virtualmachines"

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

type ObjectEventWatcher struct {
Expand Down Expand Up @@ -262,6 +272,8 @@ func AfterTestSuitCleanup() {
createNamespaces()
cleanNamespaces()

deletePVC(osWindows, false)

deletePVC(osAlpineISCSI, false)
deletePV(osAlpineISCSI, false)

Expand All @@ -282,21 +294,23 @@ func BeforeTestSuitSetup() {
createIscsiSecrets()

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

createPVC(osWindows, false, defaultWindowsDiskSize)
}

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

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

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

name := fmt.Sprintf("disk-%s", os)
Expand Down Expand Up @@ -886,3 +900,52 @@ func LoggedInCirrosExpecter(vm *v1.VirtualMachine) (expect.Expecter, error) {
log.DefaultLogger().Object(vm).Infof("%v", res)
return expecter, err
}

func ExecuteCommandOnPod(virtCli kubecli.KubevirtClient, pod *k8sv1.Pod, containerName string, command string) (string, error) {
var (
execOut bytes.Buffer
execErr bytes.Buffer
)

execRequest := virtCli.CoreV1().RESTClient().Post().
Resource("pods").
Name(pod.Name).
Namespace(pod.Namespace).
SubResource("exec").
Param("container", containerName).
Param("command", command).
Param("stdout", "true").
Param("stderr", "true")

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

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

err = exec.Stream(remotecommand.StreamOptions{
Stdout: &execOut,
Stderr: &execErr,
})
if err != nil {
return "", err
}
if execErr.Len() > 0 {
return "", fmt.Errorf("stderr: %v", execErr.String())
}
return execOut.String(), nil
}

func BeforeAll(fn func()) {
first := true
BeforeEach(func() {
if first {
fn()
first = false
}
})
}
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 @@ -177,13 +177,3 @@ var _ = Describe("Networking", func() {
})

})

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

0 comments on commit 30ad695

Please sign in to comment.