Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #537 from sHaggYcaT/numa_support
Browse files Browse the repository at this point in the history
Auto tests for PR: kubevirt/kubevirt#1839
  • Loading branch information
Xenia Lisovskaia authored May 17, 2019
2 parents 092a68c + f553d04 commit 4d6422a
Show file tree
Hide file tree
Showing 23 changed files with 1,197 additions and 16 deletions.
4 changes: 3 additions & 1 deletion hack/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ source hack/common.sh
prefix=${DOCKER_PREFIX:-kubevirt}
tag=${DOCKER_TAG:-v0.13.3}
kubeconfig=${KUBECONFIG:-~/.kube/config}
oc_in_framework="oc"
virtctl_in_framework="virtctl"
[ -z "$OC_PATH" ] && OC_PATH=$(command -v oc)
[ -z "$KUBECTL_PATH" ] && KUBECTL_PATH=$(which kubectl)
[ -z "$VIRTCTL_PATH" ] && VIRTCTL_PATH=$(which virtctl)

${TESTS_OUT_DIR}/tests.test -kubeconfig=$kubeconfig -container-tag=$tag -container-prefix=$prefix -oc-path=${OC_PATH} -kubectl-path=${KUBECTL_PATH} -virtctl-path=${VIRTCTL_PATH} ${FUNC_TEST_ARGS}
OC_IN_FRAMEWORK=$oc_in_framework VIRTCTL_IN_FRAMEWORK=$virtctl_in_framework ${TESTS_OUT_DIR}/tests.test -kubeconfig=$kubeconfig -container-tag=$tag -container-prefix=$prefix -oc-path=${OC_PATH} -kubectl-path=${KUBECTL_PATH} -virtctl-path=${VIRTCTL_PATH} ${FUNC_TEST_ARGS}
2 changes: 2 additions & 0 deletions playbooks/provider/lago/LagoInitFile.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ host-settings: &nodes-settings
groups: [nodes]
{% endif %}
memory: 4096
vcpu: 8
disks:
- template_name: {{ lago_vm_image }}
type: template
Expand Down Expand Up @@ -49,6 +50,7 @@ domains:
groups: [masters, nodes, etcd, nfs]
{% endif %}
memory: 4096
vcpu: 8
nics:
- ip: 192.168.200.2
net: lago-management-network
Expand Down
2 changes: 2 additions & 0 deletions roles/kubevirt_web_ui/tasks/provision.web-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
retries: 30
delay: 10
when: kubevirt_web_ui_version_effective != ""
ignore_errors: yes

# The Web UI is deprovisioned either when
# - KWebUI CR is missing
Expand All @@ -70,4 +71,5 @@
retries: 30
delay: 10
when: kubevirt_web_ui_version_effective == ""
ignore_errors: yes

18 changes: 12 additions & 6 deletions tests/framework/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package framework
import (
"errors"
"io/ioutil"
"os"
"strings"
"time"

Expand All @@ -25,6 +26,11 @@ const (
LongTimeout = time.Duration(4) * time.Minute
)

var (
ocName = os.Getenv("OC_IN_FRAMEWORK")
virtctlName = os.Getenv("VIRTCTL_IN_FRAMEWORK")
)

// VirtualMachine can be a vm, vmi, vmirs, vmiPreset.
type VirtualMachine struct {
Name string
Expand All @@ -39,22 +45,22 @@ type VirtualMachine struct {

func (vm VirtualMachine) Create() (string, string, error) {
args := []string{"create", "-f", vm.Manifest}
return ktests.RunCommandWithNS(vm.Namespace, ktests.KubeVirtOcPath, args...)
return ktests.RunCommandWithNS(vm.Namespace, ocName, args...)
}

func (vm VirtualMachine) Start() (string, string, error) {
args := []string{"start", vm.Name}
return ktests.RunCommandWithNS(vm.Namespace, ktests.KubeVirtVirtctlPath, args...)
return ktests.RunCommandWithNS(vm.Namespace, virtctlName, args...)
}

func (vm VirtualMachine) Stop() (string, string, error) {
args := []string{"stop", vm.Name}
return ktests.RunCommandWithNS(vm.Namespace, ktests.KubeVirtVirtctlPath, args...)
return ktests.RunCommandWithNS(vm.Namespace, virtctlName, args...)
}

func (vm VirtualMachine) Delete() (string, string, error) {
args := []string{"delete", vm.Type, vm.Name}
return ktests.RunCommandWithNS(vm.Namespace, ktests.KubeVirtVirtctlPath, args...)
return ktests.RunCommandWithNS(vm.Namespace, ocName, args...)
}

func (vm VirtualMachine) IsRunning() (bool, error) {
Expand All @@ -73,7 +79,7 @@ func (vm VirtualMachine) IsRunning() (bool, error) {

func (vm VirtualMachine) GetVMInfo(spec string) (string, string, error) {
args := []string{"get", vm.Type, vm.Name, "--template", spec}
return ktests.RunCommandWithNS(vm.Namespace, ktests.KubeVirtOcPath, args...)
return ktests.RunCommandWithNS(vm.Namespace, ocName, args...)
}

func (vm VirtualMachine) GetVMUID() (string, error) {
Expand All @@ -100,7 +106,7 @@ func (vm VirtualMachine) ProcessTemplate() (string, error) {

args = append(args, vm.TemplateParams...)

output, cmderr, err := ktests.RunCommandWithNS(NamespaceTestTemplate, ktests.KubeVirtOcPath, args...)
output, cmderr, err := ktests.RunCommandWithNS(NamespaceTestTemplate, ocName, args...)
if err != nil {
return "", err
}
Expand Down
36 changes: 36 additions & 0 deletions tests/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"kubevirt.io/kubevirt/pkg/kubecli"
ktests "kubevirt.io/kubevirt/tests"
"math"
)

func ProcessTemplateWithParameters(srcFilePath, dstFilePath string, params ...string) string {
Expand Down Expand Up @@ -148,3 +149,38 @@ func RemoveDataVolume(dvName string, namespace string) {
err = virtCli.CdiClient().CdiV1alpha1().DataVolumes(namespace).Delete(dvName, nil)
Expect(err).ToNot(HaveOccurred())
}

func GetAvailableResources(virtClient kubecli.KubevirtClient, cpuNeeded int64, memNeeded int64) (int, int) {
nodeList := ktests.GetAllSchedulableNodes(virtClient)
cpu_limit_total, mem_limit_total := 0, 0

for _, node := range nodeList.Items {
cpu := node.Status.Allocatable["cpu"]
mem := node.Status.Allocatable["memory"]
available_cpu, CpuOK := (&cpu).AsInt64()
available_mem, MemOK := (&mem).AsInt64()
if CpuOK && MemOK {
cpu_limit := int(available_cpu / cpuNeeded)
mem_limit := int(available_mem / memNeeded)
cpu_limit_total += cpu_limit
mem_limit_total += mem_limit
//availableVMs += int(math.Min(float64(cpu_limit), float64(mem_limit)))
}
}

return cpu_limit_total, mem_limit_total
}

// Checking if the cluster can run at least one VM
func IsEnoughResources(virtClient kubecli.KubevirtClient, cpuNeeded int, memNeeded int64) (bool, int) {
cpu_limit, mem_limit := GetAvailableResources(virtClient, int64(cpuNeeded), int64(memNeeded))
availableVMs := int(math.Min(float64(cpu_limit), float64(mem_limit)))
if availableVMs == 0 {
return false, availableVMs

} else {
return true, availableVMs

}

}
13 changes: 11 additions & 2 deletions tests/framework/vnc_console.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func OpenConsole(virtCli kubecli.KubevirtClient, vmiName string, vmiNamespace st
}, timeout, opts...)
}

func LoggedInFedoraExpecter(vmiName string, vmiNamespace string, timeout int64) (expect.Expecter, error) {
func LoggedInFedoraExpecter(vmiName string, vmiNamespace string, timeout int64, vmNameInPromt bool) (expect.Expecter, error) {
virtClient, err := kubecli.GetKubevirtClient()
ktests.PanicOnError(err)
vmi, err := virtClient.VirtualMachineInstance(vmiNamespace).Get(vmiName, &metav1.GetOptions{})
Expand All @@ -63,10 +63,19 @@ func LoggedInFedoraExpecter(vmiName string, vmiNamespace string, timeout int64)
if err != nil {
return nil, err
}

loginPromt := ""

if vmNameInPromt {
loginPromt = vmiName + " " + "login:"
} else {
loginPromt = "login:"
}

b := append([]expect.Batcher{
&expect.BSnd{S: "\n"},
&expect.BSnd{S: "\n"},
&expect.BExp{R: "login:"},
&expect.BExp{R: loginPromt},
&expect.BSnd{S: "fedora\n"},
&expect.BExp{R: "Password:"},
&expect.BSnd{S: "fedora\n"},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
apiVersion: v1
kind: Template
metadata:
annotations:
description: OCP KubeVirt Fedora 27 VM template
iconClass: icon-fedora
tags: kubevirt,ocp,template,linux,virtualmachine
labels:
kubevirt.io/os: fedora27
miq.github.io/kubevirt-is-vm-template: "true"
name: vm-template-fedora
objects:
- apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
creationTimestamp: null
labels:
kubevirt.io/os: fedora27
name: ${NAME}
spec:
running: false
template:
metadata:
creationTimestamp: null
labels:
kubevirt.io/os: fedora27
spec:
domain:
devices:
disks:
- disk:
bus: virtio
name: registryvolume
- disk:
bus: virtio
name: cloudinitvolume
machine:
type: ""
resources:
requests:
memory: ${MEMORY}
terminationGracePeriodSeconds: 0
volumes:
- containerDisk:
image: kubevirt/fedora-cloud-registry-disk-demo
name: registryvolume
- cloudInitNoCloud:
userData: |-
#cloud-config
password: fedora
chpasswd: { expire: False }
name: cloudinitvolume
status: {}
parameters:
- description: Name for the new VM
name: NAME
- description: Amount of memory
name: MEMORY
value: 256Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
apiVersion: v1
kind: Template
metadata:
annotations:
description: OCP KubeVirt Fedora 27 VM template
iconClass: icon-fedora
tags: kubevirt,ocp,template,linux,virtualmachine
labels:
kubevirt.io/os: fedora27
miq.github.io/kubevirt-is-vm-template: "true"
name: vm-template-fedora
objects:
- apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
creationTimestamp: null
labels:
kubevirt.io/os: fedora27
name: ${NAME}
spec:
running: false
template:
metadata:
creationTimestamp: null
labels:
kubevirt.io/os: fedora27
spec:
domain:
cpu:
cores: ${{CPU_CORES}}
threads: ${{CPU_THREADS}}
devices:
disks:
- disk:
bus: virtio
name: registryvolume
- disk:
bus: virtio
name: cloudinitvolume
machine:
type: ""
resources:
requests:
memory: ${MEMORY}
terminationGracePeriodSeconds: 0
volumes:
- containerDisk:
image: kubevirt/fedora-cloud-registry-disk-demo
name: registryvolume
- cloudInitNoCloud:
userData: |-
#cloud-config
password: fedora
chpasswd: { expire: False }
name: cloudinitvolume
status: {}
parameters:
- description: Name for the new VM
name: NAME
- description: Amount of memory
name: MEMORY
value: 256Mi
- description: Amount of cores
name: CPU_CORES
value: "2"
- description: Amount of threads
name: CPU_THREADS
value: "2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
apiVersion: v1
kind: Template
metadata:
annotations:
description: OCP KubeVirt Fedora 27 VM template
iconClass: icon-fedora
tags: kubevirt,ocp,template,linux,virtualmachine
labels:
kubevirt.io/os: fedora27
miq.github.io/kubevirt-is-vm-template: "true"
name: vm-template-fedora
objects:
- apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
creationTimestamp: null
labels:
kubevirt.io/os: fedora27
name: ${NAME}
spec:
running: false
template:
metadata:
creationTimestamp: null
labels:
kubevirt.io/os: fedora27
spec:
domain:
cpu:
cores: ${{CPU_CORES}}
devices:
disks:
- disk:
bus: virtio
name: registryvolume
- disk:
bus: virtio
name: cloudinitvolume
machine:
type: ""
resources:
requests:
memory: ${MEMORY}
terminationGracePeriodSeconds: 0
volumes:
- containerDisk:
image: kubevirt/fedora-cloud-registry-disk-demo
name: registryvolume
- cloudInitNoCloud:
userData: |-
#cloud-config
password: fedora
chpasswd: { expire: False }
name: cloudinitvolume
status: {}
parameters:
- description: Name for the new VM
name: NAME
- description: Amount of memory
name: MEMORY
value: 256Mi
- description: Amount of cores
name: CPU_CORES
value: "2"
Loading

0 comments on commit 4d6422a

Please sign in to comment.