diff --git a/tests/e2e/Taskfile.yaml b/tests/e2e/Taskfile.yaml index 3bd952457..766c8ca93 100644 --- a/tests/e2e/Taskfile.yaml +++ b/tests/e2e/Taskfile.yaml @@ -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 diff --git a/tests/e2e/complex_test.go b/tests/e2e/complex_test.go index 9bff3d288..8792b0783 100644 --- a/tests/e2e/complex_test.go +++ b/tests/e2e/complex_test.go @@ -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}, @@ -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{ @@ -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{ @@ -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{ @@ -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 { @@ -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{ @@ -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{ @@ -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{ @@ -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, @@ -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{ @@ -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, diff --git a/tests/e2e/config/config.go b/tests/e2e/config/config.go index 6eec9bab0..b19f33569 100644 --- a/tests/e2e/config/config.go +++ b/tests/e2e/config/config.go @@ -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 { diff --git a/tests/e2e/default_config.yaml b/tests/e2e/default_config.yaml index 914448e79..f1fac75ff 100644 --- a/tests/e2e/default_config.yaml +++ b/tests/e2e/default_config.yaml @@ -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" diff --git a/tests/e2e/sizing_policy_test.go b/tests/e2e/sizing_policy_test.go index 915fbb17d..eae1be27b 100644 --- a/tests/e2e/sizing_policy_test.go +++ b/tests/e2e/sizing_policy_test.go @@ -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}, @@ -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{ @@ -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{ @@ -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{ @@ -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) @@ -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) @@ -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, @@ -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, diff --git a/tests/e2e/testdata/vm-label-annotation/base/cfg/cloudinit.yaml b/tests/e2e/testdata/vm-label-annotation/base/cfg/cloudinit.yaml new file mode 100644 index 000000000..e9ceb0454 --- /dev/null +++ b/tests/e2e/testdata/vm-label-annotation/base/cfg/cloudinit.yaml @@ -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 your_email@example.com diff --git a/tests/e2e/testdata/vm-label-annotation/base/kustomization.yaml b/tests/e2e/testdata/vm-label-annotation/base/kustomization.yaml new file mode 100644 index 000000000..d820a3f56 --- /dev/null +++ b/tests/e2e/testdata/vm-label-annotation/base/kustomization.yaml @@ -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 diff --git a/tests/e2e/testdata/vm-label-annotation/base/transformer.yaml b/tests/e2e/testdata/vm-label-annotation/base/transformer.yaml new file mode 100644 index 000000000..c70c289af --- /dev/null +++ b/tests/e2e/testdata/vm-label-annotation/base/transformer.yaml @@ -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 diff --git a/tests/e2e/testdata/vm-label-annotation/base/vd-root.yaml b/tests/e2e/testdata/vm-label-annotation/base/vd-root.yaml new file mode 100644 index 000000000..79dfd103e --- /dev/null +++ b/tests/e2e/testdata/vm-label-annotation/base/vd-root.yaml @@ -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 diff --git a/tests/e2e/testdata/vm-label-annotation/base/vm.yaml b/tests/e2e/testdata/vm-label-annotation/base/vm.yaml new file mode 100644 index 000000000..a352cb713 --- /dev/null +++ b/tests/e2e/testdata/vm-label-annotation/base/vm.yaml @@ -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 diff --git a/tests/e2e/testdata/vm-label-annotation/kustomization.yaml b/tests/e2e/testdata/vm-label-annotation/kustomization.yaml new file mode 100644 index 000000000..28ddbfe9e --- /dev/null +++ b/tests/e2e/testdata/vm-label-annotation/kustomization.yaml @@ -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 diff --git a/tests/e2e/testdata/vm-label-annotation/ns.yaml b/tests/e2e/testdata/vm-label-annotation/ns.yaml new file mode 100644 index 000000000..5efde875b --- /dev/null +++ b/tests/e2e/testdata/vm-label-annotation/ns.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: default diff --git a/tests/e2e/testdata/vm-label-annotation/overlays/vm-label-annotation/kustomization.yaml b/tests/e2e/testdata/vm-label-annotation/overlays/vm-label-annotation/kustomization.yaml new file mode 100644 index 000000000..994b90334 --- /dev/null +++ b/tests/e2e/testdata/vm-label-annotation/overlays/vm-label-annotation/kustomization.yaml @@ -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 diff --git a/tests/e2e/testdata/vm-label-annotation/transformer.yaml b/tests/e2e/testdata/vm-label-annotation/transformer.yaml new file mode 100644 index 000000000..e827a1923 --- /dev/null +++ b/tests/e2e/testdata/vm-label-annotation/transformer.yaml @@ -0,0 +1,52 @@ +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 diff --git a/tests/e2e/testdata/vm-label-annotation/vi/kustomization.yaml b/tests/e2e/testdata/vm-label-annotation/vi/kustomization.yaml new file mode 100644 index 000000000..b807d8e2d --- /dev/null +++ b/tests/e2e/testdata/vm-label-annotation/vi/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - vi-alpine-http.yaml diff --git a/tests/e2e/testdata/vm-label-annotation/vi/vi-alpine-http.yaml b/tests/e2e/testdata/vm-label-annotation/vi/vi-alpine-http.yaml new file mode 100644 index 000000000..2bd920826 --- /dev/null +++ b/tests/e2e/testdata/vm-label-annotation/vi/vi-alpine-http.yaml @@ -0,0 +1,11 @@ +--- +apiVersion: virtualization.deckhouse.io/v1alpha2 +kind: VirtualImage +metadata: + name: vi-alpine-http +spec: + storage: ContainerRegistry + dataSource: + type: HTTP + http: + url: https://0e773854-6b4e-4e76-a65b-d9d81675451a.selstorage.ru/alpine/alpine-v3-20.qcow2 diff --git a/tests/e2e/testdata/vm/vm_label_annotation.yaml b/tests/e2e/testdata/vm/vm_label_annotation.yaml deleted file mode 100644 index 44cc6ae19..000000000 --- a/tests/e2e/testdata/vm/vm_label_annotation.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: virtualization.deckhouse.io/v1alpha2 -kind: VirtualMachine -metadata: - name: test-vm-label - namespace: test-d8-virtualization -spec: - disruptions: - restartApprovalMode: Automatic - runPolicy: AlwaysOn - osType: Generic - bootloader: BIOS - cpu: - cores: 1 - memory: - size: 1Gi - blockDeviceRefs: - - kind: VirtualImage - name: test-vm-image diff --git a/tests/e2e/tests_suite_test.go b/tests/e2e/tests_suite_test.go index 5ed071f69..ec1dec422 100644 --- a/tests/e2e/tests_suite_test.go +++ b/tests/e2e/tests_suite_test.go @@ -96,6 +96,7 @@ func init() { fmt.Sprintf("%s/%s", conf.TestData.DiskResizing, "kustomization.yaml"), fmt.Sprintf("%s/%s", conf.TestData.SizingPolicy, "kustomization.yaml"), fmt.Sprintf("%s/%s", conf.TestData.VmConfiguration, "kustomization.yaml"), + fmt.Sprintf("%s/%s", conf.TestData.VmLabelAnnotation, "kustomization.yaml"), fmt.Sprintf("%s/%s", conf.TestData.VmMigration, "kustomization.yaml"), fmt.Sprintf("%s/%s", conf.TestData.VmDiskAttachment, "kustomization.yaml"), } diff --git a/tests/e2e/vm_configuration_test.go b/tests/e2e/vm_configuration_test.go index 445a18b26..fad65bd4d 100644 --- a/tests/e2e/vm_configuration_test.go +++ b/tests/e2e/vm_configuration_test.go @@ -90,7 +90,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora manualLabel = map[string]string{"vm": "manual-conf"} ) - 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.VmConfiguration}, @@ -100,7 +100,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora }) }) - 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{ @@ -111,7 +111,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora }) }) - Context("When virtual disks are applied:", func() { + Context("When virtual disks are applied", func() { It(fmt.Sprintf("should be in %s phase", PhaseReady), func() { WaitPhaseByLabel(kc.ResourceVD, PhaseReady, kc.WaitOptions{ Labels: testCaseLabel, @@ -121,7 +121,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora }) }) - Context("When virtual machines are applied:", func() { + Context("When virtual machines are applied", func() { It(fmt.Sprintf("should be in %s phase", PhaseRunning), func() { WaitPhaseByLabel(kc.ResourceVM, PhaseRunning, kc.WaitOptions{ Labels: testCaseLabel, @@ -132,7 +132,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora }) Describe("Manual restart approval mode", func() { - Context(fmt.Sprintf("When virtual machine is in %s phase:", PhaseRunning), func() { + Context(fmt.Sprintf("When virtual machine is in %s phase", PhaseRunning), func() { It("changes the number of processor cores", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: manualLabel, @@ -147,7 +147,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora }) }) - Context("When virtual machine is patched:", func() { + Context("When virtual machine is patched", func() { It("checks the number of processor cores in specification", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: manualLabel, @@ -161,7 +161,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora }) }) - Context("When virtual machine is restarted:", func() { + Context("When virtual machine is restarted", func() { It(fmt.Sprintf("should be in %s phase", PhaseRunning), func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: manualLabel, @@ -183,7 +183,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora }) }) - Context(fmt.Sprintf("When virtual machine is in %s phase:", PhaseRunning), func() { + Context(fmt.Sprintf("When virtual machine is in %s phase", PhaseRunning), func() { It("checks that the number of processor cores was changed", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: manualLabel, @@ -199,7 +199,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora }) Describe("Automatic restart approval mode", func() { - Context(fmt.Sprintf("When virtual machine is in %s phase:", PhaseRunning), func() { + Context(fmt.Sprintf("When virtual machine is in %s phase", PhaseRunning), func() { It("changes the number of processor cores", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: automaticLabel, @@ -214,7 +214,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora }) }) - Context("When virtual machine is patched:", func() { + Context("When virtual machine is patched", func() { It("checks the number of processor cores in specification", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: automaticLabel, @@ -228,7 +228,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora }) }) - Context("When virtual machine is restarted:", func() { + Context("When virtual machine is restarted", func() { It(fmt.Sprintf("should be in %s phase", PhaseRunning), func() { WaitPhaseByLabel(kc.ResourceVM, PhaseRunning, kc.WaitOptions{ Labels: automaticLabel, @@ -238,7 +238,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora }) }) - Context(fmt.Sprintf("When virtual machine is in %s phase:", PhaseRunning), func() { + Context(fmt.Sprintf("When virtual machine is in %s phase", PhaseRunning), func() { It("checks that the number of processor cores was changed", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: automaticLabel, @@ -253,7 +253,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora }) }) - Context("When test is complited:", func() { + Context("When test is completed", func() { It("deletes test case resources", func() { DeleteTestCaseResources(ResourcesToDelete{ KustomizationDir: conf.TestData.VmConfiguration, diff --git a/tests/e2e/vm_connectivity_test.go b/tests/e2e/vm_connectivity_test.go index a71602114..8ad190982 100644 --- a/tests/e2e/vm_connectivity_test.go +++ b/tests/e2e/vm_connectivity_test.go @@ -102,7 +102,7 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() err error ) - 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.Connectivity}, @@ -112,7 +112,7 @@ var _ = Describe("VM connectivity", 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{ @@ -123,7 +123,7 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() }) }) - Context("When virtual disks are applied:", func() { + Context("When virtual disks are applied", func() { It("checks VDs phases", func() { By(fmt.Sprintf("VDs should be in %s phase", PhaseReady)) WaitPhaseByLabel(kc.ResourceVD, PhaseReady, kc.WaitOptions{ @@ -134,7 +134,7 @@ var _ = Describe("VM connectivity", 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 phase", PhaseRunning)) WaitPhaseByLabel(kc.ResourceVM, PhaseRunning, kc.WaitOptions{ @@ -145,7 +145,7 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() }) }) - Context(fmt.Sprintf("When run %s:", CurlPod), func() { + Context(fmt.Sprintf("When run %s", CurlPod), func() { It(fmt.Sprintf("status should be in %s phase", PhaseRunning), func() { jsonPath := "jsonpath={.status.phase}" waitFor := fmt.Sprintf("%s=%s", jsonPath, PhaseRunning) @@ -158,7 +158,7 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() }) }) - Context(fmt.Sprintf("When virtual machines in %s phase:", PhaseRunning), func() { + Context(fmt.Sprintf("When virtual machines in %s phase", PhaseRunning), func() { It("gets VMs and SVCs objects", func() { vmA = virtv2.VirtualMachine{} err = GetObject(kc.ResourceVM, aObjName, &vmA, kc.GetOptions{ @@ -253,7 +253,7 @@ var _ = Describe("VM connectivity", 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.Connectivity, diff --git a/tests/e2e/vm_disk_attachment_test.go b/tests/e2e/vm_disk_attachment_test.go index 5f6fd4cec..5e7a32914 100644 --- a/tests/e2e/vm_disk_attachment_test.go +++ b/tests/e2e/vm_disk_attachment_test.go @@ -122,7 +122,7 @@ var _ = Describe("Virtual disk attachment", ginkgoutil.CommonE2ETestDecorators() vmbdaName = fmt.Sprintf("%s-vm-%s", namePrefix, nameSuffix) }) - 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.VmDiskAttachment}, @@ -132,7 +132,7 @@ var _ = Describe("Virtual disk attachment", ginkgoutil.CommonE2ETestDecorators() }) }) - 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{ @@ -143,7 +143,7 @@ var _ = Describe("Virtual disk attachment", ginkgoutil.CommonE2ETestDecorators() }) }) - Context("When virtual disks are applied:", func() { + Context("When virtual disks are applied", func() { It("checks VDs phases", func() { By(fmt.Sprintf("VDs with consumers should be in %s phases", PhaseReady)) WaitPhaseByLabel(kc.ResourceVD, PhaseReady, kc.WaitOptions{ @@ -161,7 +161,7 @@ var _ = Describe("Virtual disk attachment", ginkgoutil.CommonE2ETestDecorators() }) }) - 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{ @@ -173,7 +173,7 @@ var _ = Describe("Virtual disk attachment", ginkgoutil.CommonE2ETestDecorators() }) Describe("Attachment", func() { - Context(fmt.Sprintf("When virtual machines are in %s phases:", PhaseRunning), func() { + Context(fmt.Sprintf("When virtual machines are in %s phases", PhaseRunning), func() { It("get disk count before attachment", func() { Eventually(func() error { return GetDisksMetadata(vmName, &disksBefore) @@ -211,7 +211,7 @@ var _ = Describe("Virtual disk attachment", ginkgoutil.CommonE2ETestDecorators() }) Describe("Detachment", func() { - Context(fmt.Sprintf("When virtual machines are in %s phases:", PhaseRunning), func() { + Context(fmt.Sprintf("When virtual machines are in %s phases", PhaseRunning), func() { It("get disk count before detachment", func() { Eventually(func() error { return GetDisksMetadata(vmName, &disksBefore) @@ -246,7 +246,7 @@ var _ = Describe("Virtual disk attachment", ginkgoutil.CommonE2ETestDecorators() }) }) - Context("When test is complited:", func() { + Context("When test is completed", func() { It("deletes test case resources", func() { DeleteTestCaseResources(ResourcesToDelete{ KustomizationDir: conf.TestData.VmDiskAttachment, diff --git a/tests/e2e/vm_disk_resizing_test.go b/tests/e2e/vm_disk_resizing_test.go index 93da4a308..faae2dc24 100644 --- a/tests/e2e/vm_disk_resizing_test.go +++ b/tests/e2e/vm_disk_resizing_test.go @@ -161,7 +161,7 @@ func GetVirtualMachineDisks(vmName string, config *cfg.Config) (VirtualMachineDi var _ = Describe("Virtual disk resizing", ginkgoutil.CommonE2ETestDecorators(), func() { testCaseLabel := map[string]string{"testcase": "disk-resizing"} - 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.DiskResizing}, @@ -171,7 +171,7 @@ var _ = Describe("Virtual disk resizing", ginkgoutil.CommonE2ETestDecorators(), }) }) - 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{ @@ -182,7 +182,7 @@ var _ = Describe("Virtual disk resizing", ginkgoutil.CommonE2ETestDecorators(), }) }) - Context("When virtual disks are applied:", func() { + Context("When virtual disks are applied", func() { It("checks VDs phases", func() { By(fmt.Sprintf("VDs should be in %s phases", PhaseReady)) WaitPhaseByLabel(kc.ResourceVD, PhaseReady, kc.WaitOptions{ @@ -193,7 +193,7 @@ var _ = Describe("Virtual disk resizing", ginkgoutil.CommonE2ETestDecorators(), }) }) - 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{ @@ -204,7 +204,7 @@ var _ = Describe("Virtual disk resizing", ginkgoutil.CommonE2ETestDecorators(), }) }) - 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{ @@ -216,7 +216,7 @@ var _ = Describe("Virtual disk resizing", ginkgoutil.CommonE2ETestDecorators(), }) Describe("Resizing", func() { - Context(fmt.Sprintf("When virtual machines are in %s phases:", PhaseRunning), func() { + Context(fmt.Sprintf("When virtual machines are in %s phases", PhaseRunning), func() { var ( vmDisksBefore VirtualMachineDisks vmDisksAfter VirtualMachineDisks @@ -293,7 +293,7 @@ var _ = Describe("Virtual disk resizing", ginkgoutil.CommonE2ETestDecorators(), }) }) - Context("When test is complited:", func() { + Context("When test is completed", func() { It("deletes test case resources", func() { DeleteTestCaseResources(ResourcesToDelete{ KustomizationDir: conf.TestData.DiskResizing, diff --git a/tests/e2e/vm_label_annotation_test.go b/tests/e2e/vm_label_annotation_test.go index f7193873b..e52e3087c 100644 --- a/tests/e2e/vm_label_annotation_test.go +++ b/tests/e2e/vm_label_annotation_test.go @@ -18,262 +18,285 @@ package e2e import ( "fmt" - "io/fs" - "path/filepath" "strings" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + v1 "k8s.io/api/core/v1" virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2" - "github.com/deckhouse/virtualization/tests/e2e/executor" "github.com/deckhouse/virtualization/tests/e2e/ginkgoutil" kc "github.com/deckhouse/virtualization/tests/e2e/kubectl" ) -var _ = Describe("Label and Annotation", ginkgoutil.CommonE2ETestDecorators(), func() { - imageManifest := vmPath("image.yaml") - vmManifest := vmPath("vm_label_annotation.yaml") - - const ( - labelName = "os" - labelValue = "ubuntu" - annotationName = "test-annotation" - annotationValue = "true" - ) - - getPodName := func(resourceName string) string { - getPodCMD := "get pod --no-headers -o custom-columns=':metadata.name'" - subCMD := fmt.Sprintf("-n %s %s | grep %s", conf.Namespace, getPodCMD, resourceName) - podCMD := kubectl.RawCommand(subCMD, ShortWaitDuration) - podName := strings.TrimSuffix(podCMD.StdOut(), "\n") - return podName +func AddLabel(resource kc.Resource, labels map[string]string, names ...string) error { + formattedLabels := make([]string, 0, len(labels)) + for k, v := range labels { + formattedLabels = append(formattedLabels, fmt.Sprintf("%s=%s", k, v)) } - - getRecourseLabel := func(resourceType kc.Resource, resourceName string) *executor.CMDResult { - label := fmt.Sprintf("jsonpath='{.metadata.labels.%s}'", labelName) - cmdResult := kubectl.GetResource(resourceType, resourceName, kc.GetOptions{ - Output: label, - Namespace: conf.Namespace, - }) - return cmdResult + rawResources := strings.Join(names, " ") + rawLabels := strings.Join(formattedLabels, "") + subCmd := fmt.Sprintf("label %s %s --namespace %s %s", resource, rawResources, conf.Namespace, rawLabels) + res := kubectl.RawCommand(subCmd, kc.MediumTimeout) + if res.Error() != nil { + return fmt.Errorf("cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) } + return nil +} - getRecourseAnnotation := func(resourceType kc.Resource, resourceName string) *executor.CMDResult { - annotation := fmt.Sprintf("jsonpath='{.metadata.annotations.%s}'", annotationName) - cmdResult := kubectl.GetResource(resourceType, resourceName, kc.GetOptions{ - Output: annotation, - Namespace: conf.Namespace, - }) - return cmdResult +func RemoveLabel(resource kc.Resource, labels map[string]string, names ...string) error { + formattedLabels := make([]string, 0, len(labels)) + for k := range labels { + formattedLabels = append(formattedLabels, fmt.Sprintf("%s-", k)) + } + rawResources := strings.Join(names, " ") + rawLabels := strings.Join(formattedLabels, "") + subCmd := fmt.Sprintf("label %s %s --namespace %s %s", resource, rawResources, conf.Namespace, rawLabels) + res := kubectl.RawCommand(subCmd, kc.MediumTimeout) + if res.Error() != nil { + return fmt.Errorf("cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) } + return nil +} - WaitVmStatus := func(name, phase string) { - GinkgoHelper() - WaitResource(kc.ResourceVM, name, "jsonpath={.status.phase}="+phase, LongWaitDuration) +func AddAnnotation(resource kc.Resource, annotations map[string]string, names ...string) error { + formattedAnnotations := make([]string, 0, len(annotations)) + for k, v := range annotations { + formattedAnnotations = append(formattedAnnotations, fmt.Sprintf("%s=%s", k, v)) } + rawResources := strings.Join(names, " ") + rawAnnotations := strings.Join(formattedAnnotations, "") + subCmd := fmt.Sprintf("annotate %s %s --namespace %s %s", resource, rawResources, conf.Namespace, rawAnnotations) + res := kubectl.RawCommand(subCmd, kc.MediumTimeout) + if res.Error() != nil { + return fmt.Errorf("cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) + } + return nil +} - BeforeAll(func() { - By("Apply image for vms") - ApplyFromFile(imageManifest) - WaitFromFile(imageManifest, PhaseReady, LongWaitDuration) - }) +func RemoveAnnotation(resource kc.Resource, annotations map[string]string, names ...string) error { + formattedAnnotations := make([]string, 0, len(annotations)) + for k := range annotations { + formattedAnnotations = append(formattedAnnotations, fmt.Sprintf("%s-", k)) + } + rawResources := strings.Join(names, " ") + rawAnnotations := strings.Join(formattedAnnotations, "") + subCmd := fmt.Sprintf("annotate %s %s --namespace %s %s", resource, rawResources, conf.Namespace, rawAnnotations) + res := kubectl.RawCommand(subCmd, kc.MediumTimeout) + if res.Error() != nil { + return fmt.Errorf("cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) + } + return nil +} - AfterAll(func() { - By("Delete all manifests") - files := make([]string, 0) - err := filepath.Walk(conf.VM.TestDataDir, func(path string, info fs.FileInfo, err error) error { - if err == nil && strings.HasSuffix(info.Name(), "yaml") { - files = append(files, path) - } - return nil - }) - if err != nil || len(files) == 0 { - kubectl.Delete(kc.DeleteOptions{ - Filename: []string{imageManifest}, - FilenameOption: kc.Filename, - }) - kubectl.Delete(kc.DeleteOptions{ - Filename: []string{conf.VM.TestDataDir}, - FilenameOption: kc.Filename, - }) - } else { - for _, f := range files { - kubectl.Delete(kc.DeleteOptions{ - Filename: []string{f}, - FilenameOption: kc.Filename, - }) - } +func GetActiveVirtualMachinePod(vmObj *virtv2.VirtualMachine) string { + for _, pod := range vmObj.Status.VirtualMachinePods { + if pod.Active { + return pod.Name } - }) + } + return "" +} - Context("Label", func() { - var vm *virtv2.VirtualMachine - var err error +var _ = Describe("Virtual machine label and annotation", ginkgoutil.CommonE2ETestDecorators(), func() { + testCaseLabel := map[string]string{"testcase": "vm-label-annotation"} + specialKeyValue := map[string]string{"specialKey": "specialValue"} - BeforeAll(func() { - By("Apply manifest") - vm, err = GetVMFromManifest(vmManifest) - Expect(err).NotTo(HaveOccurred()) - ApplyFromFile(vmManifest) - WaitVmStatus(vm.Name, VMStatusRunning) + Context("When resources are applied", func() { + It("result should be succeeded", func() { + res := kubectl.Apply(kc.ApplyOptions{ + Filename: []string{conf.TestData.VmLabelAnnotation}, + FilenameOption: kc.Kustomize, + }) + Expect(res.Error()).NotTo(HaveOccurred(), "cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) }) + }) - AfterAll(func() { - By("Delete manifest") - kubectl.Delete(kc.DeleteOptions{ - Filename: []string{vmManifest}, - FilenameOption: kc.Filename, + 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{ + Labels: testCaseLabel, + Namespace: conf.Namespace, + Timeout: MaxWaitTimeout, }) }) + }) - Describe(fmt.Sprintf("Add label %s=%s", labelName, labelValue), func() { - It("Labeled", func() { - subCMD := fmt.Sprintf("-n %s label vm %s %s=%s", conf.Namespace, vm.Name, labelName, labelValue) - res := kubectl.RawCommand(subCMD, ShortWaitDuration) - Expect(res.Error()).NotTo(HaveOccurred()) + Context("When virtual disks are applied", func() { + It("checks VDs phases", func() { + By(fmt.Sprintf("VDs should be in %s phases", PhaseReady)) + WaitPhaseByLabel(kc.ResourceVD, PhaseReady, kc.WaitOptions{ + Labels: testCaseLabel, + Namespace: conf.Namespace, + Timeout: MaxWaitTimeout, }) }) + }) - Describe("Check label on resource", func() { - It("VM", func() { - res := getRecourseLabel(kc.ResourceVM, vm.Name) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get VM %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(Equal(labelValue)) - }) - It("KVVM", func() { - res := getRecourseLabel(kc.ResourceKubevirtVM, vm.Name) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get KVVM %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(Equal(labelValue)) - }) - It("KVVMI", func() { - res := getRecourseLabel(kc.ResourceKubevirtVMI, vm.Name) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get KVVMI %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(Equal(labelValue)) - }) - It("POD virtlauncher", func() { - pod := getPodName(vm.Name) - res := getRecourseLabel(kc.ResourcePod, pod) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get pod %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(Equal(labelValue)) + 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{ + Labels: testCaseLabel, + Namespace: conf.Namespace, + Timeout: MaxWaitTimeout, }) }) + }) - Describe(fmt.Sprintf("Remove label %s=%s", labelName, labelValue), func() { - It("Label was removed", func() { - subCMD := fmt.Sprintf("-n %s label vm %s %s-", conf.Namespace, vm.Name, labelName) - res := kubectl.RawCommand(subCMD, ShortWaitDuration) - Expect(res.Error()).NotTo(HaveOccurred()) + Context(fmt.Sprintf("Label `VirtualMachines` in %s phase", PhaseRunning), func() { + It(fmt.Sprintf("marks VMs with label %q", specialKeyValue), func() { + res := kubectl.List(kc.ResourceVM, kc.GetOptions{ + Labels: testCaseLabel, + Namespace: conf.Namespace, + Output: "jsonpath='{.items[*].metadata.name}'", }) + Expect(res.Error()).NotTo(HaveOccurred(), "cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) + + vms := strings.Split(res.StdOut(), " ") + err := AddLabel(kc.ResourceVM, specialKeyValue, vms...) + Expect(err).NotTo(HaveOccurred(), err) }) - Describe("Label must be removed from resource", func() { - It("VM", func() { - res := getRecourseLabel(kc.ResourceVM, vm.Name) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get VM %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(BeEmpty()) - }) - It("KVVM", func() { - res := getRecourseLabel(kc.ResourceKubevirtVM, vm.Name) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get KVVM %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(BeEmpty()) - }) - It("KVVMI", func() { - res := getRecourseLabel(kc.ResourceKubevirtVMI, vm.Name) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get KVVMI %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(BeEmpty()) + It("checks VMs and pods labels after VMs labeling", func() { + res := kubectl.List(kc.ResourceVM, kc.GetOptions{ + Labels: testCaseLabel, + Namespace: conf.Namespace, + Output: "jsonpath='{.items[*].metadata.name}'", }) - It("POD virtlauncher", func() { - pod := getPodName(vm.Name) - res := getRecourseLabel(kc.ResourcePod, pod) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get pod %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(BeEmpty()) - }) - }) - }) + Expect(res.Error()).NotTo(HaveOccurred(), "cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) - Context("Annotation", func() { - var vm *virtv2.VirtualMachine + vms := strings.Split(res.StdOut(), " ") + for _, vm := range vms { + vmObj := virtv2.VirtualMachine{} + err := GetObject(kc.ResourceVM, vm, &vmObj, kc.GetOptions{Namespace: conf.Namespace}) + Expect(err).NotTo(HaveOccurred(), err) + Expect(vmObj.Labels).Should(HaveKeyWithValue("specialKey", "specialValue")) - BeforeAll(func() { - By("Apply manifest") - var err error - vm, err = GetVMFromManifest(vmManifest) - Expect(err).NotTo(HaveOccurred()) - ApplyFromFile(vmManifest) - WaitVmStatus(vm.Name, VMStatusRunning) + activePod := GetActiveVirtualMachinePod(&vmObj) + vmPodObj := v1.Pod{} + err = GetObject(kc.ResourcePod, activePod, &vmPodObj, kc.GetOptions{Namespace: conf.Namespace}) + Expect(err).NotTo(HaveOccurred(), err) + Expect(vmPodObj.Labels).Should(HaveKeyWithValue("specialKey", "specialValue")) + } }) - AfterAll(func() { - By("Delete manifest") - kubectl.Delete(kc.DeleteOptions{ - Filename: []string{vmManifest}, - FilenameOption: kc.Filename, + It(fmt.Sprintf("removes label %s from VMs", specialKeyValue), func() { + res := kubectl.List(kc.ResourceVM, kc.GetOptions{ + Labels: testCaseLabel, + Namespace: conf.Namespace, + Output: "jsonpath='{.items[*].metadata.name}'", }) + Expect(res.Error()).NotTo(HaveOccurred(), "cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) + + vms := strings.Split(res.StdOut(), " ") + err := RemoveLabel(kc.ResourceVM, specialKeyValue, vms...) + Expect(err).NotTo(HaveOccurred(), err) }) - Describe(fmt.Sprintf("Add annotation %s=%s", annotationName, annotationValue), func() { - It("Annotated", func() { - subCMD := fmt.Sprintf("-n %s annotate vm %s %s=%s", conf.Namespace, vm.Name, annotationName, - annotationValue) - res := kubectl.RawCommand(subCMD, ShortWaitDuration) - Expect(res.Error()).NotTo(HaveOccurred()) + It("checks VMs and pods labels after VMs unlabeling", func() { + res := kubectl.List(kc.ResourceVM, kc.GetOptions{ + Labels: testCaseLabel, + Namespace: conf.Namespace, + Output: "jsonpath='{.items[*].metadata.name}'", }) + Expect(res.Error()).NotTo(HaveOccurred(), "cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) + + vms := strings.Split(res.StdOut(), " ") + for _, vm := range vms { + vmObj := virtv2.VirtualMachine{} + err := GetObject(kc.ResourceVM, vm, &vmObj, kc.GetOptions{Namespace: conf.Namespace}) + Expect(err).NotTo(HaveOccurred(), err) + Expect(vmObj.Labels).ShouldNot(HaveKey("specialKey")) + + activePod := GetActiveVirtualMachinePod(&vmObj) + vmPodObj := v1.Pod{} + err = GetObject(kc.ResourcePod, activePod, &vmPodObj, kc.GetOptions{Namespace: conf.Namespace}) + Expect(err).NotTo(HaveOccurred(), err) + Expect(vmPodObj.Labels).ShouldNot(HaveKey("specialKey")) + } }) + }) - Describe("Check annotation on resource", func() { - It("VM", func() { - res := getRecourseAnnotation(kc.ResourceVM, vm.Name) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get VM %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(Equal(annotationValue)) - }) - It("KVVM", func() { - res := getRecourseAnnotation(kc.ResourceKubevirtVM, vm.Name) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get KVVM %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(Equal(annotationValue)) - }) - It("KVVMI", func() { - res := getRecourseAnnotation(kc.ResourceKubevirtVMI, vm.Name) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get KVVMI %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(Equal(annotationValue)) - }) - It("POD virtlauncher", func() { - pod := getPodName(vm.Name) - res := getRecourseAnnotation(kc.ResourcePod, pod) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get pod %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(Equal(annotationValue)) + Context(fmt.Sprintf("Annotate `VirtualMachines` in %s phase", PhaseRunning), func() { + It(fmt.Sprintf("marks VMs with annotation %q", specialKeyValue), func() { + res := kubectl.List(kc.ResourceVM, kc.GetOptions{ + Labels: testCaseLabel, + Namespace: conf.Namespace, + Output: "jsonpath='{.items[*].metadata.name}'", }) + Expect(res.Error()).NotTo(HaveOccurred(), "cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) + + vms := strings.Split(res.StdOut(), " ") + err := AddAnnotation(kc.ResourceVM, specialKeyValue, vms...) + Expect(err).NotTo(HaveOccurred(), err) }) - Describe("Remove annotation test-annotation=true", func() { - It("Was removed", func() { - subCMD := fmt.Sprintf("-n %s annotate vm %s %s-", conf.Namespace, vm.Name, annotationName) - res := kubectl.RawCommand(subCMD, ShortWaitDuration) - Expect(res.Error()).NotTo(HaveOccurred()) + It("checks VMs and pods annotations after VMs annotating", func() { + res := kubectl.List(kc.ResourceVM, kc.GetOptions{ + Labels: testCaseLabel, + Namespace: conf.Namespace, + Output: "jsonpath='{.items[*].metadata.name}'", }) + Expect(res.Error()).NotTo(HaveOccurred(), "cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) + + vms := strings.Split(res.StdOut(), " ") + for _, vm := range vms { + vmObj := virtv2.VirtualMachine{} + err := GetObject(kc.ResourceVM, vm, &vmObj, kc.GetOptions{Namespace: conf.Namespace}) + Expect(err).NotTo(HaveOccurred(), err) + Expect(vmObj.Annotations).Should(HaveKeyWithValue("specialKey", "specialValue")) + + activePod := GetActiveVirtualMachinePod(&vmObj) + vmPodObj := v1.Pod{} + err = GetObject(kc.ResourcePod, activePod, &vmPodObj, kc.GetOptions{Namespace: conf.Namespace}) + Expect(err).NotTo(HaveOccurred(), err) + Expect(vmPodObj.Annotations).Should(HaveKeyWithValue("specialKey", "specialValue")) + } }) - Describe("Annotation must be removed from resource", func() { - It("VM", func() { - res := getRecourseAnnotation(kc.ResourceVM, vm.Name) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get VM %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(BeEmpty()) - }) - It("KVVM", func() { - res := getRecourseAnnotation(kc.ResourceKubevirtVM, vm.Name) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get KVVM %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(BeEmpty()) + It(fmt.Sprintf("removes annotation %s from VMs", specialKeyValue), func() { + res := kubectl.List(kc.ResourceVM, kc.GetOptions{ + Labels: testCaseLabel, + Namespace: conf.Namespace, + Output: "jsonpath='{.items[*].metadata.name}'", }) - It("KVVMI", func() { - res := getRecourseAnnotation(kc.ResourceKubevirtVMI, vm.Name) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get KVVMI %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(BeEmpty()) + Expect(res.Error()).NotTo(HaveOccurred(), "cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) + + vms := strings.Split(res.StdOut(), " ") + err := RemoveAnnotation(kc.ResourceVM, specialKeyValue, vms...) + Expect(err).NotTo(HaveOccurred(), err) + }) + + It("checks VMs and pods annotations after VMs unannotating", func() { + res := kubectl.List(kc.ResourceVM, kc.GetOptions{ + Labels: testCaseLabel, + Namespace: conf.Namespace, + Output: "jsonpath='{.items[*].metadata.name}'", }) - It("POD virtlauncher", func() { - pod := getPodName(vm.Name) - res := getRecourseAnnotation(kc.ResourcePod, pod) - Expect(res.Error()).NotTo(HaveOccurred(), "failed to get pod %s.\n%s", vm.Name, res.StdErr()) - Expect(res.StdOut()).To(BeEmpty()) + Expect(res.Error()).NotTo(HaveOccurred(), "cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) + + vms := strings.Split(res.StdOut(), " ") + for _, vm := range vms { + vmObj := virtv2.VirtualMachine{} + err := GetObject(kc.ResourceVM, vm, &vmObj, kc.GetOptions{Namespace: conf.Namespace}) + Expect(err).NotTo(HaveOccurred(), err) + Expect(vmObj.Annotations).ShouldNot(HaveKey("specialKey")) + + activePod := GetActiveVirtualMachinePod(&vmObj) + vmPodObj := v1.Pod{} + err = GetObject(kc.ResourcePod, activePod, &vmPodObj, kc.GetOptions{Namespace: conf.Namespace}) + Expect(err).NotTo(HaveOccurred(), err) + Expect(vmPodObj.Annotations).ShouldNot(HaveKey("specialKey")) + } + }) + }) + + Context("When test is completed", func() { + It("deletes test case resources", func() { + DeleteTestCaseResources(ResourcesToDelete{ + KustomizationDir: conf.TestData.VmLabelAnnotation, }) }) }) diff --git a/tests/e2e/vm_migration_test.go b/tests/e2e/vm_migration_test.go index be89bfed4..b3887162c 100644 --- a/tests/e2e/vm_migration_test.go +++ b/tests/e2e/vm_migration_test.go @@ -77,7 +77,7 @@ func CreateMigrationManifest(vmName, filePath string, labels map[string]string) var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators(), func() { testCaseLabel := map[string]string{"testcase": "vm-migration"} - 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.VmMigration}, @@ -87,7 +87,7 @@ var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators }) }) - 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{ @@ -98,7 +98,7 @@ var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators }) }) - Context("When virtual disks are applied:", func() { + Context("When virtual disks are applied", func() { It("checks VDs phases", func() { By(fmt.Sprintf("VDs should be in %s phases", PhaseReady)) WaitPhaseByLabel(kc.ResourceVD, PhaseReady, kc.WaitOptions{ @@ -109,7 +109,7 @@ var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators }) }) - 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{ @@ -120,7 +120,7 @@ var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators }) }) - Context(fmt.Sprintf("When virtual machines are in %s phases:", PhaseRunning), func() { + Context(fmt.Sprintf("When virtual machines are in %s phases", PhaseRunning), func() { It("starts migrations", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: testCaseLabel, @@ -134,7 +134,7 @@ var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators }) }) - 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{ @@ -163,7 +163,7 @@ var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators }) }) - Context("When test is complited:", func() { + Context("When test is completed", func() { It("deletes test case resources", func() { DeleteTestCaseResources(ResourcesToDelete{ KustomizationDir: conf.TestData.VmMigration,