Skip to content

Commit

Permalink
Merge pull request kubevirt#2227 from rmohr/libvirt-capabilities
Browse files Browse the repository at this point in the history
Improve scheduling of libvirt capability test VMIs
  • Loading branch information
rmohr authored May 1, 2019
2 parents f8bb43a + 5b49119 commit 293df2c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
11 changes: 2 additions & 9 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3112,19 +3112,12 @@ func RunCommandOnVmiPod(vmi *v1.VirtualMachineInstance, command []string) string
}

// GetNodeLibvirtCapabilities returns node libvirt capabilities
func GetNodeLibvirtCapabilities(nodeName string) string {
// Create a virt-launcher pod to fetch virsh capabilities
vmi := NewRandomVMIWithEphemeralDiskAndUserdata(ContainerDiskFor(ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
StartVmOnNode(vmi, nodeName)

func GetNodeLibvirtCapabilities(vmi *v1.VirtualMachineInstance) string {
return RunCommandOnVmiPod(vmi, []string{"virsh", "-r", "capabilities"})
}

// GetNodeCPUInfo returns output of lscpu on the pod that runs on the specified node
func GetNodeCPUInfo(nodeName string) string {
vmi := NewRandomVMIWithEphemeralDiskAndUserdata(ContainerDiskFor(ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
StartVmOnNode(vmi, nodeName)

func GetNodeCPUInfo(vmi *v1.VirtualMachineInstance) string {
return RunCommandOnVmiPod(vmi, []string{"lscpu"})
}

Expand Down
26 changes: 20 additions & 6 deletions tests/vmi_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
kubev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -918,12 +919,14 @@ var _ = Describe("Configurations", func() {
var cpuFeatures []string
var cpuVmi *v1.VirtualMachineInstance

BeforeEach(func() {
nodes, err := virtClient.CoreV1().Nodes().List(metav1.ListOptions{})
// Collect capabilities once for all tests
tests.BeforeAll(func() {
vmi := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n")
_, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())
Expect(nodes.Items).NotTo(BeEmpty())
node := tests.WaitForSuccessfulVMIStart(vmi)

virshCaps := tests.GetNodeLibvirtCapabilities(nodes.Items[0].Name)
virshCaps := tests.GetNodeLibvirtCapabilities(vmi)

model := libvirtCPUModelRegexp.FindStringSubmatch(virshCaps)
Expect(len(model)).To(Equal(2))
Expand All @@ -939,7 +942,7 @@ var _ = Describe("Configurations", func() {
cpuFeatures = append(cpuFeatures, cpuFeature[1])
}

cpuInfo := tests.GetNodeCPUInfo(nodes.Items[0].Name)
cpuInfo := tests.GetNodeCPUInfo(vmi)
modelName := cpuModelNameRegexp.FindStringSubmatch(cpuInfo)
Expect(len(modelName)).To(Equal(2))
cpuModelName = modelName[1]
Expand All @@ -951,13 +954,24 @@ var _ = Describe("Configurations", func() {
NodeSelectorTerms: []kubev1.NodeSelectorTerm{
{
MatchExpressions: []kubev1.NodeSelectorRequirement{
{Key: "kubernetes.io/hostname", Operator: kubev1.NodeSelectorOpIn, Values: []string{nodes.Items[0].Name}},
{Key: "kubernetes.io/hostname", Operator: kubev1.NodeSelectorOpIn, Values: []string{node}},
},
},
},
},
},
}

// Best to also delete the VMI, in the case that there is only one spot free for scheduling
err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Delete(vmi.Name, &metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
Eventually(func() bool {
_, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Get(vmi.Name, &metav1.GetOptions{})
if errors.IsNotFound(err) {
return true
}
return false
}, 30*time.Second, 1*time.Second).Should(BeTrue())
})

Context("[rfe_id:140][crit:medium][vendor:[email protected]][level:component]when CPU model defined", func() {
Expand Down

0 comments on commit 293df2c

Please sign in to comment.