Skip to content

Commit

Permalink
test(api): refactor e2e label and annotation test case (#515)
Browse files Browse the repository at this point in the history
- adapt existing label and annotation test case to updated API
- fix typo and improve test cases contexts

Signed-off-by: Roman Sysoev <[email protected]>
  • Loading branch information
hardcoretime authored Nov 28, 2024
1 parent 7ea5bae commit 41908ae
Show file tree
Hide file tree
Showing 24 changed files with 516 additions and 290 deletions.
1 change: 0 additions & 1 deletion tests/e2e/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ tasks:
- |
ginkgo \
--skip-file vm_test.go \
--skip-file vm_label_annotation_test.go \
--skip-file ipam_test.go \
--skip-file disks_test.go \
-v
Expand Down
22 changes: 11 additions & 11 deletions tests/e2e/complex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() {
hasNoConsumerLabel = map[string]string{"hasNoConsumer": "complex-test"}
)

Context("When virtualization resources are applied:", func() {
Context("When virtualization resources are applied", func() {
It("result should be succeeded", func() {
res := kubectl.Apply(kc.ApplyOptions{
Filename: []string{conf.TestData.ComplexTest},
Expand All @@ -75,7 +75,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context("When virtual images are applied:", func() {
Context("When virtual images are applied", func() {
It("checks VIs phases", func() {
By(fmt.Sprintf("VIs should be in %s phases", PhaseReady))
WaitPhaseByLabel(kc.ResourceVI, PhaseReady, kc.WaitOptions{
Expand All @@ -86,7 +86,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context("When cluster virtual images are applied:", func() {
Context("When cluster virtual images are applied", func() {
It("checks CVIs phases", func() {
By(fmt.Sprintf("CVIs should be in %s phases", PhaseReady))
WaitPhaseByLabel(kc.ResourceCVI, PhaseReady, kc.WaitOptions{
Expand All @@ -97,7 +97,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context("When virtual machine classes are applied:", func() {
Context("When virtual machine classes are applied", func() {
It("checks VMClasses phases", func() {
By(fmt.Sprintf("VMClasses should be in %s phases", PhaseReady))
WaitPhaseByLabel(kc.ResourceVMClass, PhaseReady, kc.WaitOptions{
Expand All @@ -108,7 +108,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context("When virtual machines IP addresses are applied:", func() {
Context("When virtual machines IP addresses are applied", func() {
It("patches custom VMIP with unassigned address", func() {
vmipName := fmt.Sprintf("%s-%s", namePrefix, "vm-custom-ip")
Eventually(func() error {
Expand All @@ -126,7 +126,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context("When virtual disks are applied:", func() {
Context("When virtual disks are applied", func() {
It("checks VDs phases with consumers", func() {
By(fmt.Sprintf("VDs should be in %s phases", PhaseReady))
WaitPhaseByLabel(kc.ResourceVD, PhaseReady, kc.WaitOptions{
Expand All @@ -147,7 +147,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context("When virtual machines are applied:", func() {
Context("When virtual machines are applied", func() {
It("checks VMs phases", func() {
By(fmt.Sprintf("VMs should be in %s phases", PhaseRunning))
WaitPhaseByLabel(kc.ResourceVM, PhaseRunning, kc.WaitOptions{
Expand All @@ -158,7 +158,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context("When virtual machine block device attachments are applied:", func() {
Context("When virtual machine block device attachments are applied", func() {
It("checks VMBDAs phases", func() {
By(fmt.Sprintf("VMBDAs should be in %s phases", PhaseAttached))
WaitPhaseByLabel(kc.ResourceVMBDA, PhaseAttached, kc.WaitOptions{
Expand Down Expand Up @@ -186,7 +186,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() {
})

Describe("Migrations", func() {
Context(fmt.Sprintf("When VMs are in %s phases:", PhaseRunning), func() {
Context(fmt.Sprintf("When VMs are in %s phases", PhaseRunning), func() {
It("starts migrations", func() {
res := kubectl.List(kc.ResourceVM, kc.GetOptions{
Labels: testCaseLabel,
Expand All @@ -200,7 +200,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context("When VMs migrations are applied:", func() {
Context("When VMs migrations are applied", func() {
It("checks VMs and KubevirtVMIMs phases", func() {
By(fmt.Sprintf("KubevirtVMIMs should be in %s phases", PhaseSucceeded))
WaitPhaseByLabel(kc.ResourceKubevirtVMIM, PhaseSucceeded, kc.WaitOptions{
Expand Down Expand Up @@ -229,7 +229,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context("When test is complited:", func() {
Context("When test is completed", func() {
It("deletes test case resources", func() {
DeleteTestCaseResources(ResourcesToDelete{
KustomizationDir: conf.TestData.ComplexTest,
Expand Down
19 changes: 10 additions & 9 deletions tests/e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,16 @@ type Config struct {
}

type TestData struct {
ComplexTest string `yaml:"complexTest"`
Connectivity string `yaml:"connectivity"`
DiskResizing string `yaml:"diskResizing"`
SizingPolicy string `yaml:"sizingPolicy"`
VmConfiguration string `yaml:"vmConfiguration"`
VmMigration string `yaml:"vmMigration"`
VmDiskAttachment string `yaml:"vmDiskAttachment"`
Sshkey string `yaml:"sshKey"`
SshUser string `yaml:"sshUser"`
ComplexTest string `yaml:"complexTest"`
Connectivity string `yaml:"connectivity"`
DiskResizing string `yaml:"diskResizing"`
SizingPolicy string `yaml:"sizingPolicy"`
VmConfiguration string `yaml:"vmConfiguration"`
VmLabelAnnotation string `yaml:"vmLabelAnnotation"`
VmMigration string `yaml:"vmMigration"`
VmDiskAttachment string `yaml:"vmDiskAttachment"`
Sshkey string `yaml:"sshKey"`
SshUser string `yaml:"sshUser"`
}

type StorageClass struct {
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ testData:
diskResizing: "/tmp/testdata/disk-resizing"
sizingPolicy: "/tmp/testdata/sizing-policy"
vmConfiguration: "/tmp/testdata/vm-configuration"
vmLabelAnnotation: "/tmp/testdata/vm-label-annotation"
vmMigration: "/tmp/testdata/vm-migration"
vmDiskAttachment: "/tmp/testdata/vm-disk-attachment"
sshKey: "/tmp/testdata/sshkeys/id_ed"
Expand Down
16 changes: 8 additions & 8 deletions tests/e2e/sizing_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var _ = Describe("Sizing policy", ginkgoutil.CommonE2ETestDecorators(), func() {
newVmClassFilePath = fmt.Sprintf("%s/vmc-copy.yaml", conf.TestData.SizingPolicy)
})

Context("When resources are applied:", func() {
Context("When resources are applied", func() {
It("result should be succeeded", func() {
res := kubectl.Apply(kc.ApplyOptions{
Filename: []string{conf.TestData.SizingPolicy},
Expand All @@ -97,7 +97,7 @@ var _ = Describe("Sizing policy", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context("When virtual images are applied:", func() {
Context("When virtual images are applied", func() {
It("checks VIs phases", func() {
By(fmt.Sprintf("VIs should be in %s phases", PhaseReady))
WaitPhaseByLabel(kc.ResourceVI, PhaseReady, kc.WaitOptions{
Expand All @@ -108,7 +108,7 @@ var _ = Describe("Sizing policy", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context("When virtual disks are applied:", func() {
Context("When virtual disks are applied", func() {
It(fmt.Sprintf("checks VDs phases with %s and %s label", notExistingVmClassChanging, notExistingVmClassCreating), func() {
By(fmt.Sprintf("VDs should be in %s phases", phaseByVolumeBindingMode))
WaitPhaseByLabel(kc.ResourceVD, phaseByVolumeBindingMode, kc.WaitOptions{
Expand All @@ -133,7 +133,7 @@ var _ = Describe("Sizing policy", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context("When virtual machines are applied:", func() {
Context("When virtual machines are applied", func() {
It(fmt.Sprintf("checks VMs phases with %s and %s label", notExistingVmClassChanging, notExistingVmClassCreating), func() {
By(fmt.Sprintf("VMs should be in %s phases", PhasePending))
WaitPhaseByLabel(kc.ResourceVM, PhasePending, kc.WaitOptions{
Expand All @@ -159,7 +159,7 @@ var _ = Describe("Sizing policy", ginkgoutil.CommonE2ETestDecorators(), func() {
})

Describe("Not existing virtual machine class", func() {
Context(fmt.Sprintf("When virtual machine with label %s in phase %s:", notExistingVmClassChanging, PhasePending), func() {
Context(fmt.Sprintf("When virtual machine with label %s in phase %s", notExistingVmClassChanging, PhasePending), func() {
It("checks condition status before changing 'virtulaMachineCLass` field with existing class", func() {
By(fmt.Sprintf("VirtualMachineClassReady status should be '%s' before changing", ReadyStatusFalse))
CompareVirtualMachineClassReadyStatus(vmNotValidSizingPolicyChanging, ReadyStatusFalse)
Expand All @@ -183,7 +183,7 @@ var _ = Describe("Sizing policy", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context(fmt.Sprintf("When virtual machine with label %s in phase %s:", notExistingVmClassCreating, PhasePending), func() {
Context(fmt.Sprintf("When virtual machine with label %s in phase %s", notExistingVmClassCreating, PhasePending), func() {
It("checks condition status before creating `VirtualMachineClass`", func() {
By(fmt.Sprintf("VirtualMachineClassReady status should be '%s' before creating", ReadyStatusFalse))
CompareVirtualMachineClassReadyStatus(vmNotValidSizingPolicyCreating, ReadyStatusFalse)
Expand Down Expand Up @@ -223,7 +223,7 @@ var _ = Describe("Sizing policy", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context(fmt.Sprintf("When virtual machines in phase %s:", PhaseRunning), func() {
Context(fmt.Sprintf("When virtual machines in phase %s", PhaseRunning), func() {
It("checks sizing policy match", func() {
res := kubectl.List(kc.ResourceVM, kc.GetOptions{
Labels: testCaseLabel,
Expand All @@ -247,7 +247,7 @@ var _ = Describe("Sizing policy", ginkgoutil.CommonE2ETestDecorators(), func() {
})
})

Context("When test is complited:", func() {
Context("When test is completed", func() {
It("deletes test case resources", func() {
DeleteTestCaseResources(ResourcesToDelete{
KustomizationDir: conf.TestData.SizingPolicy,
Expand Down
12 changes: 12 additions & 0 deletions tests/e2e/testdata/vm-label-annotation/base/cfg/cloudinit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#cloud-config
users:
- name: cloud
# passwd: cloud
passwd: $6$rounds=4096$vln/.aPHBOI7BMYR$bBMkqQvuGs5Gyd/1H5DP4m9HjQSy.kgrxpaGEHwkX7KEFV8BS.HZWPitAtZ2Vd8ZqIZRqmlykRCagTgPejt1i.
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
chpasswd: { expire: False }
lock_passwd: false
ssh_authorized_keys:
# testcases
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFxcXHmwaGnJ8scJaEN5RzklBPZpVSic4GdaAsKjQoeA [email protected]
14 changes: 14 additions & 0 deletions tests/e2e/testdata/vm-label-annotation/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./vm.yaml
- ./vd-root.yaml
configurations:
- transformer.yaml
generatorOptions:
disableNameSuffixHash: true
secretGenerator:
- files:
- userData=cfg/cloudinit.yaml
name: cloud-init
type: provisioning.virtualization.deckhouse.io/cloud-init
54 changes: 54 additions & 0 deletions tests/e2e/testdata/vm-label-annotation/base/transformer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# https://github.com/kubernetes-sigs/kustomize/blob/master/examples/transformerconfigs/README.md#transformer-configurations

namespace:
- kind: ClusterVirtualImage
path: spec/dataSource/objectRef/namespace
nameReference:
- kind: VirtualImage
version: v1alpha2 # optional
fieldSpecs:
- path: spec/dataSource/objectRef/name
kind: ClusterVirtualImage
- path: spec/dataSource/objectRef/name
kind: VirtualImage
- path: spec/dataSource/objectRef/name
kind: VirtualDisk
- path: spec/blockDeviceRefs/name
kind: VirtualMachine
- kind: ClusterVirtualImage
version: v1alpha2 # optional
fieldSpecs:
- path: spec/dataSource/objectRef/name
kind: ClusterVirtualImage
- path: spec/dataSource/objectRef/name
kind: VirtualImage
- path: spec/dataSource/objectRef/name
kind: VirtualDisk
- path: spec/blockDeviceRefs/name
kind: VirtualMachine
- kind: VirtualDisk
version: v1alpha2 # optional
fieldSpecs:
- path: spec/blockDeviceRefs/name
kind: VirtualMachine
- path: spec/blockDeviceRef/name
kind: VirtualMachineBlockDeviceAttachment
- kind: Secret
fieldSpecs:
- path: spec/provisioning/userDataRef/name
kind: VirtualMachine
- kind: VirtualMachineIPAddress
version: v1alpha2
fieldSpecs:
- path: spec/virtualMachineIPAddressName
kind: VirtualMachine
- kind: VirtualMachine
version: v1alpha2
fieldSpecs:
- path: spec/virtualMachineName
kind: VirtualMachineBlockDeviceAttachment
- kind: VirtualMachineClass
version: v1alpha2
fieldSpecs:
- path: spec/virtualMachineClassName
kind: VirtualMachine
12 changes: 12 additions & 0 deletions tests/e2e/testdata/vm-label-annotation/base/vd-root.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualDisk
metadata:
name: vd-root
spec:
persistentVolumeClaim:
size: 512Mi
dataSource:
type: ObjectRef
objectRef:
kind: VirtualImage
name: vi-alpine-http
21 changes: 21 additions & 0 deletions tests/e2e/testdata/vm-label-annotation/base/vm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: virtualization.deckhouse.io/v1alpha2
kind: VirtualMachine
metadata:
name: vm
spec:
virtualMachineClassName: generic
cpu:
cores: 1
coreFraction: 5%
memory:
size: 256Mi
disruptions:
restartApprovalMode: Manual
provisioning:
type: UserDataRef
userDataRef:
kind: Secret
name: cloud-init
blockDeviceRefs:
- kind: VirtualDisk
name: vd-root
15 changes: 15 additions & 0 deletions tests/e2e/testdata/vm-label-annotation/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: testcases
namePrefix: pr-number-or-commit-hash-
resources:
- ns.yaml
- vi
- overlays/vm-label-annotation
configurations:
- transformer.yaml
labels:
- includeSelectors: true
pairs:
id: pr-number-or-commit-hash
testcase: vm-label-annotation
4 changes: 4 additions & 0 deletions tests/e2e/testdata/vm-label-annotation/ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: default
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
nameSuffix: -label-annotation
resources:
- ../../base
patches:
- patch: |-
- op: replace
path: /spec/runPolicy
value: AlwaysOn
target:
kind: VirtualMachine
name: vm
- patch: |-
- op: replace
path: /spec/disruptions/restartApprovalMode
value: Automatic
target:
kind: VirtualMachine
name: vm
Loading

0 comments on commit 41908ae

Please sign in to comment.