forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubevirt#2250 from stu-gott/testing-matchexpression
[Testing] Add missing functional test covering matchExpressions of Presets
- Loading branch information
Showing
1 changed file
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()) | ||
|
||
|
@@ -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()) | ||
|
||
|
@@ -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()) | ||
|
||
|
@@ -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()) | ||
|
||
|
@@ -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()) | ||
|
||
|
@@ -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") | ||
|
@@ -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)) | ||
|
@@ -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) { | ||
|