Skip to content

Commit

Permalink
Merge pull request kubevirt#2250 from stu-gott/testing-matchexpression
Browse files Browse the repository at this point in the history
[Testing] Add missing functional test covering matchExpressions of Presets
  • Loading branch information
davidvossel authored May 29, 2019
2 parents 3345b3e + 3bc2e22 commit 6065bdb
Showing 1 changed file with 82 additions and 7 deletions.
89 changes: 82 additions & 7 deletions tests/vmipreset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ var _ = Describe("[rfe_id:609][crit:medium][vendor:[email protected]][level:comp
err := virtClient.RestClient().Post().Resource("virtualmachineinstancepresets").Namespace(tests.NamespaceTestDefault).Body(memoryPreset).Do().Error()
Expect(err).ToNot(HaveOccurred())

// Give virt-api's cache time to sync before proceeding
time.Sleep(3 * time.Second)

newPreset, err := getPreset(virtClient, memoryPrefix)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -185,6 +188,9 @@ var _ = Describe("[rfe_id:609][crit:medium][vendor:[email protected]][level:comp
err := virtClient.RestClient().Post().Resource("virtualmachineinstancepresets").Namespace(tests.NamespaceTestDefault).Body(cpuPreset).Do().Error()
Expect(err).ToNot(HaveOccurred())

// Give virt-api's cache time to sync before proceeding
time.Sleep(3 * time.Second)

newPreset, err := getPreset(virtClient, cpuPrefix)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -210,6 +216,9 @@ var _ = Describe("[rfe_id:609][crit:medium][vendor:[email protected]][level:comp
err := virtClient.RestClient().Post().Resource("virtualmachineinstancepresets").Namespace(tests.NamespaceTestDefault).Body(memoryPreset).Do().Error()
Expect(err).ToNot(HaveOccurred())

// Give virt-api's cache time to sync before proceeding
time.Sleep(3 * time.Second)

newPreset, err := getPreset(virtClient, memoryPrefix)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -237,6 +246,9 @@ var _ = Describe("[rfe_id:609][crit:medium][vendor:[email protected]][level:comp
err = virtClient.RestClient().Post().Resource("virtualmachineinstancepresets").Namespace(tests.NamespaceTestDefault).Body(memoryPreset).Do().Error()
Expect(err).ToNot(HaveOccurred())

// Give virt-api's cache time to sync before proceeding
time.Sleep(3 * time.Second)

newPreset, err := getPreset(virtClient, memoryPrefix)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -253,6 +265,9 @@ var _ = Describe("[rfe_id:609][crit:medium][vendor:[email protected]][level:comp
err := virtClient.RestClient().Post().Resource("virtualmachineinstancepresets").Namespace(tests.NamespaceTestDefault).Body(cpuPreset).Do().Error()
Expect(err).ToNot(HaveOccurred())

// Give virt-api's cache time to sync before proceeding
time.Sleep(3 * time.Second)

newPreset, err := getPreset(virtClient, cpuPrefix)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -301,13 +316,12 @@ var _ = Describe("[rfe_id:609][crit:medium][vendor:[email protected]][level:comp
It("[test_id:1605]should denied to start the VMI", func() {
err := virtClient.RestClient().Post().Resource("virtualmachineinstancepresets").Namespace(tests.NamespaceTestDefault).Body(conflictPreset).Do().Error()
Expect(err).ToNot(HaveOccurred())
getPreset(virtClient, conflictPrefix)
Expect(err).ToNot(HaveOccurred())

err = virtClient.RestClient().Post().Resource("virtualmachineinstancepresets").Namespace(tests.NamespaceTestDefault).Body(memoryPreset).Do().Error()
Expect(err).ToNot(HaveOccurred())
getPreset(virtClient, memoryPrefix)
Expect(err).ToNot(HaveOccurred())

// Give virt-api's cache time to sync before proceeding
time.Sleep(3 * time.Second)

vmi.Labels = map[string]string{flavorKey: memoryFlavor, conflictKey: conflictFlavor}
By("creating the VirtualMachineInstance")
Expand Down Expand Up @@ -345,9 +359,8 @@ var _ = Describe("[rfe_id:609][crit:medium][vendor:[email protected]][level:comp
err := virtClient.RestClient().Post().Resource("virtualmachineinstancepresets").Namespace(tests.NamespaceTestDefault).Body(overridePreset).Do().Error()
Expect(err).ToNot(HaveOccurred())

By("Waiting for preset to be created")
getPreset(virtClient, overridePrefix)
Expect(err).ToNot(HaveOccurred())
// Give virt-api's cache time to sync before proceeding
time.Sleep(3 * time.Second)

By("Creating VMI with 128M")
vmi = tests.NewRandomVMIWithEphemeralDisk(tests.ContainerDiskFor(tests.ContainerDiskAlpine))
Expand Down Expand Up @@ -414,6 +427,68 @@ var _ = Describe("[rfe_id:609][crit:medium][vendor:[email protected]][level:comp
})
})

Context("Match Expressions", func() {
var preset *v1.VirtualMachineInstancePreset
labelKey := "kubevirt.io/os"

var vmiWin7 *v1.VirtualMachineInstance
var vmiWin10 *v1.VirtualMachineInstance
win7Label := "win7"
win10Label := "win10"

BeforeEach(func() {
selector := k8smetav1.LabelSelector{
MatchExpressions: []k8smetav1.LabelSelectorRequirement{
{
Key: labelKey,
Operator: k8smetav1.LabelSelectorOpIn,
Values: []string{win10Label, win7Label},
},
},
}

preset = &v1.VirtualMachineInstancePreset{
ObjectMeta: k8smetav1.ObjectMeta{GenerateName: memoryPrefix},
Spec: v1.VirtualMachineInstancePresetSpec{
Selector: selector,
Domain: &v1.DomainSpec{
Resources: v1.ResourceRequirements{Requests: k8sv1.ResourceList{
"memory": memory}},
},
},
}

// The actual type of machine is unimportant here. This test is about the label
vmiWin7 = tests.NewRandomVMIWithEphemeralDisk(tests.ContainerDiskFor(tests.ContainerDiskAlpine))
// this helper function explicitly sets a memory req, but we don't want one for this test
vmiWin7.Spec.Domain.Resources = v1.ResourceRequirements{}
vmiWin7.Labels = map[string]string{labelKey: win7Label}
vmiWin10 = tests.NewRandomVMIWithEphemeralDisk(tests.ContainerDiskFor(tests.ContainerDiskAlpine))
vmiWin10.Spec.Domain.Resources = v1.ResourceRequirements{}
vmiWin10.Labels = map[string]string{labelKey: win10Label}
})

It("[test_id:726] Should match multiple VMs via MatchExpression", func() {
By("Creating preset with MatchExpression")
_, err := virtClient.VirtualMachineInstancePreset(tests.NamespaceTestDefault).Create(preset)
Expect(err).ToNot(HaveOccurred())

// Give virt-api's cache time to sync before proceeding
time.Sleep(3 * time.Second)

By("Creating first VirtualMachineInstance")
newVmi7, err := virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmiWin7)
Expect(err).ToNot(HaveOccurred())

By("Creating second VirtualMachineInstance")
newVmi10, err := virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmiWin10)
Expect(err).ToNot(HaveOccurred())

By("Checking that preset matched bot VMs")
Expect(newVmi7.Spec.Domain.Resources.Requests["memory"]).To(Equal(memory))
Expect(newVmi10.Spec.Domain.Resources.Requests["memory"]).To(Equal(memory))
})
})
})

func getPreset(virtClient kubecli.KubevirtClient, prefix string) (*v1.VirtualMachineInstancePreset, error) {
Expand Down

0 comments on commit 6065bdb

Please sign in to comment.