From 08e1ad35a5dbba23ce01454f2f1c21f6617c21d1 Mon Sep 17 00:00:00 2001 From: Isteb4k Date: Fri, 17 Jan 2025 12:37:52 +0100 Subject: [PATCH] test(vm): run reusable tests in different namespaces Signed-off-by: Isteb4k --- tests/e2e/complex_test.go | 51 +++++++++++++++----------- tests/e2e/tests_suite_test.go | 10 ++++-- tests/e2e/vd_snapshots_test.go | 1 - tests/e2e/vm_configuration_test.go | 57 +++++++++++++++++------------- tests/e2e/vm_connectivity_test.go | 46 ++++++++++++++---------- tests/e2e/vm_migration_test.go | 39 +++++++++++++------- 6 files changed, 125 insertions(+), 79 deletions(-) diff --git a/tests/e2e/complex_test.go b/tests/e2e/complex_test.go index b025acb5f..946e98f59 100644 --- a/tests/e2e/complex_test.go +++ b/tests/e2e/complex_test.go @@ -29,7 +29,11 @@ import ( kc "github.com/deckhouse/virtualization/tests/e2e/kubectl" ) -func AssignIPToVMIP(name string) error { +func GetComplexNamespace() string { + return conf.Namespace + "-complex" +} + +func AssignIPToVMIP(name, namespace string) error { assignErr := fmt.Sprintf("cannot patch VMIP %q with unnassigned IP address", name) unassignedIP, err := FindUnassignedIP(mc.Spec.Settings.VirtualMachineCIDRs) if err != nil { @@ -42,14 +46,14 @@ func AssignIPToVMIP(name string) error { } vmip := virtv2.VirtualMachineIPAddress{} err = GetObject(kc.ResourceVMIP, name, &vmip, kc.GetOptions{ - Namespace: conf.Namespace, + Namespace: namespace, }) if err != nil { return fmt.Errorf("%s\n%s", assignErr, err) } jsonPath := fmt.Sprintf("'jsonpath={.status.phase}=%s'", PhaseAttached) waitOpts := kc.WaitOptions{ - Namespace: conf.Namespace, + Namespace: namespace, For: jsonPath, Timeout: ShortWaitDuration, } @@ -64,14 +68,19 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { var ( testCaseLabel = map[string]string{"testcase": "complex-test"} hasNoConsumerLabel = map[string]string{"hasNoConsumer": "complex-test"} + namespace = conf.Namespace ) + if config.IsReusable() { + namespace = GetComplexNamespace() + } + Context("When virtualization resources are applied", func() { It("result should be succeeded", func() { if config.IsReusable() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr()) @@ -94,7 +103,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { By(fmt.Sprintf("VIs should be in %s phases", PhaseReady)) WaitPhaseByLabel(kc.ResourceVI, PhaseReady, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -105,7 +114,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { By(fmt.Sprintf("CVIs should be in %s phases", PhaseReady)) WaitPhaseByLabel(kc.ResourceCVI, PhaseReady, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -116,7 +125,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { By(fmt.Sprintf("VMClasses should be in %s phases", PhaseReady)) WaitPhaseByLabel(kc.ResourceVMClass, PhaseReady, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -126,7 +135,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { It("patches custom VMIP with unassigned address", func() { vmipName := fmt.Sprintf("%s-%s", namePrefix, "vm-custom-ip") Eventually(func() error { - return AssignIPToVMIP(vmipName) + return AssignIPToVMIP(vmipName, namespace) }).Should(Succeed()) }) @@ -134,7 +143,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { By(fmt.Sprintf("VMIPs should be in %s phases", PhaseAttached)) WaitPhaseByLabel(kc.ResourceVMIP, PhaseAttached, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -146,7 +155,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { WaitPhaseByLabel(kc.ResourceVD, PhaseReady, kc.WaitOptions{ ExcludedLabels: []string{"hasNoConsumer"}, Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -155,7 +164,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { By(fmt.Sprintf("VDs should be in %s phases", phaseByVolumeBindingMode)) WaitPhaseByLabel(kc.ResourceVD, phaseByVolumeBindingMode, kc.WaitOptions{ Labels: hasNoConsumerLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -166,7 +175,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { By(fmt.Sprintf("VMs should be in %s phases", PhaseRunning)) WaitPhaseByLabel(kc.ResourceVM, PhaseRunning, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -177,7 +186,7 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { By(fmt.Sprintf("VMBDAs should be in %s phases", PhaseAttached)) WaitPhaseByLabel(kc.ResourceVMBDA, PhaseAttached, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -188,13 +197,13 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { It("checks VMs external connectivity", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr()) vms := strings.Split(res.StdOut(), " ") - CheckExternalConnection(externalHost, httpStatusOk, vms...) + CheckExternalConnection(externalHost, httpStatusOk, namespace, vms...) }) }) }) @@ -204,13 +213,13 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { It("starts migrations", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr()) vms := strings.Split(res.StdOut(), " ") - MigrateVirtualMachines(testCaseLabel, conf.TestData.ComplexTest, vms...) + MigrateVirtualMachines(testCaseLabel, conf.TestData.ComplexTest, namespace, vms...) }) }) @@ -219,13 +228,13 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { By(fmt.Sprintf("KubevirtVMIMs should be in %s phases", PhaseSucceeded)) WaitPhaseByLabel(kc.ResourceKubevirtVMIM, PhaseSucceeded, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) By(fmt.Sprintf("VMs should be in %s phase", PhaseRunning)) WaitPhaseByLabel(kc.ResourceVM, PhaseRunning, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -233,13 +242,13 @@ var _ = Describe("Complex test", ginkgoutil.CommonE2ETestDecorators(), func() { It("checks VMs external connection after migrations", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr()) vms := strings.Split(res.StdOut(), " ") - CheckExternalConnection(externalHost, httpStatusOk, vms...) + CheckExternalConnection(externalHost, httpStatusOk, namespace, vms...) }) }) diff --git a/tests/e2e/tests_suite_test.go b/tests/e2e/tests_suite_test.go index 9aba1d011..511483ad7 100644 --- a/tests/e2e/tests_suite_test.go +++ b/tests/e2e/tests_suite_test.go @@ -120,7 +120,7 @@ func init() { log.Fatal(err) } } else { - log.Printf("Run test in REUSABLE mode\n") + log.Println("Run test in REUSABLE mode") } res := kubectl.CreateResource(kc.ResourceNamespace, conf.Namespace, kc.CreateOptions{}) @@ -147,7 +147,13 @@ func TestTests(t *testing.T) { func Cleanup() error { res := kubectl.Delete(kc.DeleteOptions{ - Filename: []string{conf.Namespace}, + Filename: []string{ + conf.Namespace, + GetVirtualMachineConfigurationNamespace(), + GetVirtualMachineConnectivityNamespace(), + GetVirtualMachineMigrationNamespace(), + GetComplexNamespace(), + }, IgnoreNotFound: true, Resource: kc.ResourceNamespace, }) diff --git a/tests/e2e/vd_snapshots_test.go b/tests/e2e/vd_snapshots_test.go index d891ae4eb..548308aa1 100644 --- a/tests/e2e/vd_snapshots_test.go +++ b/tests/e2e/vd_snapshots_test.go @@ -30,7 +30,6 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" sdsrepvolv1 "github.com/deckhouse/sds-replicated-volume/api/v1alpha1" - virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2" "github.com/deckhouse/virtualization/tests/e2e/config" "github.com/deckhouse/virtualization/tests/e2e/ginkgoutil" diff --git a/tests/e2e/vm_configuration_test.go b/tests/e2e/vm_configuration_test.go index 7f6eb7f1f..3978be3ef 100644 --- a/tests/e2e/vm_configuration_test.go +++ b/tests/e2e/vm_configuration_test.go @@ -38,11 +38,15 @@ const ( StageAfter = "after" ) -func ExecSshCommand(vmName, cmd string) { +func GetVirtualMachineConfigurationNamespace() string { + return conf.Namespace + "-vm-configuration" +} + +func ExecSshCommand(vmName, namespace, cmd string) { GinkgoHelper() Eventually(func() error { res := d8Virtualization.SshCommand(vmName, cmd, d8.SshOptions{ - Namespace: conf.Namespace, + Namespace: namespace, Username: conf.TestData.SshUser, IdenityFile: conf.TestData.Sshkey, }) @@ -53,9 +57,9 @@ func ExecSshCommand(vmName, cmd string) { }).WithTimeout(Timeout).WithPolling(Interval).ShouldNot(HaveOccurred()) } -func ChangeCPUCoresNumber(cpuNumber int, virtualMachines ...string) { +func ChangeCPUCoresNumber(cpuNumber int, namespace string, virtualMachines ...string) { vms := strings.Join(virtualMachines, " ") - cmd := fmt.Sprintf("patch %s --namespace %s %s --type merge --patch '{\"spec\":{\"cpu\":{\"cores\":%d}}}'", kc.ResourceVM, conf.Namespace, vms, cpuNumber) + cmd := fmt.Sprintf("patch %s --namespace %s %s --type merge --patch '{\"spec\":{\"cpu\":{\"cores\":%d}}}'", kc.ResourceVM, namespace, vms, cpuNumber) By("Patching virtual machine specification") patchRes := kubectl.RawCommand(cmd, ShortWaitDuration) Expect(patchRes.Error()).NotTo(HaveOccurred(), patchRes.StdErr()) @@ -77,11 +81,11 @@ func CheckCPUCoresNumber(approvalMode, stage string, requiredValue int, virtualM } } -func CheckCPUCoresNumberFromVirtualMachine(requiredValue string, virtualMachines ...string) { +func CheckCPUCoresNumberFromVirtualMachine(requiredValue, namespace string, virtualMachines ...string) { By("Checking the number of processor cores after changing from virtual machine") for _, vm := range virtualMachines { cmd := "nproc --all" - CheckResultSshCommand(vm, cmd, requiredValue) + CheckResultSshCommand(vm, namespace, cmd, requiredValue) } } @@ -90,14 +94,19 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora testCaseLabel = map[string]string{"testcase": "vm-configuration"} automaticLabel = map[string]string{"vm": "automatic-conf"} manualLabel = map[string]string{"vm": "manual-conf"} + namespace = conf.Namespace ) + if config.IsReusable() { + namespace = GetVirtualMachineConfigurationNamespace() + } + Context("When resources are applied", func() { It("result should be succeeded", func() { if config.IsReusable() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr()) @@ -120,7 +129,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora By(fmt.Sprintf("VIs should be in %s phases", PhaseReady)) WaitPhaseByLabel(kc.ResourceVI, PhaseReady, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -130,7 +139,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora It(fmt.Sprintf("should be in %s phase", PhaseReady), func() { WaitPhaseByLabel(kc.ResourceVD, PhaseReady, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -140,7 +149,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora It(fmt.Sprintf("should be in %s phase", PhaseRunning), func() { WaitPhaseByLabel(kc.ResourceVM, PhaseRunning, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -154,7 +163,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora It("changes the number of processor cores", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: manualLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr()) @@ -170,7 +179,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora newCPUCores = 1 + (vmResource.Spec.CPU.Cores & 1) CheckCPUCoresNumber(ManualMode, StageBefore, oldCpuCores, vms...) - ChangeCPUCoresNumber(newCPUCores, vms...) + ChangeCPUCoresNumber(newCPUCores, namespace, vms...) }) }) @@ -178,7 +187,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora It("checks the number of processor cores in specification", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: manualLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.WasSuccess()).To(Equal(true), res.StdErr()) @@ -192,7 +201,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora It(fmt.Sprintf("should be in %s phase", PhaseRunning), func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: manualLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.WasSuccess()).To(Equal(true), res.StdErr()) @@ -200,11 +209,11 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora vms := strings.Split(res.StdOut(), " ") for _, vm := range vms { cmd := "sudo reboot" - ExecSshCommand(vm, cmd) + ExecSshCommand(vm, namespace, cmd) } WaitPhaseByLabel(kc.ResourceVM, PhaseRunning, kc.WaitOptions{ Labels: manualLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -214,13 +223,13 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora It("checks that the number of processor cores was changed", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: manualLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.WasSuccess()).To(Equal(true), res.StdErr()) vms := strings.Split(res.StdOut(), " ") - CheckCPUCoresNumberFromVirtualMachine(strconv.FormatInt(int64(newCPUCores), 10), vms...) + CheckCPUCoresNumberFromVirtualMachine(strconv.FormatInt(int64(newCPUCores), 10), namespace, vms...) }) }) }) @@ -233,7 +242,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora It("changes the number of processor cores", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: automaticLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.WasSuccess()).To(Equal(true), res.StdErr()) @@ -249,7 +258,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora newCPUCores = 1 + (vmResource.Spec.CPU.Cores & 1) CheckCPUCoresNumber(AutomaticMode, StageBefore, oldCpuCores, vms...) - ChangeCPUCoresNumber(newCPUCores, vms...) + ChangeCPUCoresNumber(newCPUCores, namespace, vms...) }) }) @@ -257,7 +266,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora It("checks the number of processor cores in specification", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: automaticLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.WasSuccess()).To(Equal(true), res.StdErr()) @@ -271,7 +280,7 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora It(fmt.Sprintf("should be in %s phase", PhaseRunning), func() { WaitPhaseByLabel(kc.ResourceVM, PhaseRunning, kc.WaitOptions{ Labels: automaticLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -281,13 +290,13 @@ var _ = Describe("Virtual machine configuration", ginkgoutil.CommonE2ETestDecora It("checks that the number of processor cores was changed", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: automaticLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr()) vms := strings.Split(res.StdOut(), " ") - CheckCPUCoresNumberFromVirtualMachine(strconv.FormatInt(int64(newCPUCores), 10), vms...) + CheckCPUCoresNumberFromVirtualMachine(strconv.FormatInt(int64(newCPUCores), 10), namespace, vms...) }) }) }) diff --git a/tests/e2e/vm_connectivity_test.go b/tests/e2e/vm_connectivity_test.go index eb5e2cd22..05e8f5d3f 100644 --- a/tests/e2e/vm_connectivity_test.go +++ b/tests/e2e/vm_connectivity_test.go @@ -46,6 +46,10 @@ type PodEntrypoint struct { Args []string } +func GetVirtualMachineConnectivityNamespace() string { + return conf.Namespace + "-vm-connectivity" +} + func RunPod(podName, namespace, image string, entrypoint PodEntrypoint) *executor.CMDResult { GinkgoHelper() cmd := fmt.Sprintf("run %s --namespace %s --image=%s --labels='name=%s'", podName, namespace, image, podName) @@ -69,20 +73,20 @@ func GetResponseViaPodWithCurl(podName, namespace, host string) *executor.CMDRes return kubectl.RawCommand(cmd, ShortWaitDuration) } -func CheckExternalConnection(host, httpCode string, vms ...string) { +func CheckExternalConnection(host, httpCode, namespace string, vms ...string) { GinkgoHelper() for _, vm := range vms { By(fmt.Sprintf("Response code from %q should be %q for %q", host, httpCode, vm)) cmd := fmt.Sprintf("curl -o /dev/null -s -w \"%%{http_code}\\n\" %s", host) - CheckResultSshCommand(vm, cmd, httpCode) + CheckResultSshCommand(vm, namespace, cmd, httpCode) } } -func CheckResultSshCommand(vmName, cmd, equal string) { +func CheckResultSshCommand(vmName, namespace, cmd, equal string) { GinkgoHelper() Eventually(func() (string, error) { res := d8Virtualization.SshCommand(vmName, cmd, d8.SshOptions{ - Namespace: conf.Namespace, + Namespace: namespace, Username: conf.TestData.SshUser, IdenityFile: conf.TestData.Sshkey, }) @@ -104,14 +108,20 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() selectorA string selectorB string + + namespace = conf.Namespace ) + if config.IsReusable() { + namespace = GetVirtualMachineConnectivityNamespace() + } + Context("When resources are applied", func() { It("result should be succeeded", func() { if config.IsReusable() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr()) @@ -134,7 +144,7 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() By(fmt.Sprintf("VIs should be in %s phases", PhaseReady)) WaitPhaseByLabel(kc.ResourceVI, PhaseReady, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -145,7 +155,7 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() By(fmt.Sprintf("VDs should be in %s phase", PhaseReady)) WaitPhaseByLabel(kc.ResourceVD, PhaseReady, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -156,7 +166,7 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() By(fmt.Sprintf("VMs should be in %s phase", PhaseRunning)) WaitPhaseByLabel(kc.ResourceVM, PhaseRunning, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -166,7 +176,7 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() It(fmt.Sprintf("status should be in %s phase", PhaseRunning), func() { jsonPath := "jsonpath={.status.phase}" waitFor := fmt.Sprintf("%s=%s", jsonPath, PhaseRunning) - res := RunPod(CurlPod, conf.Namespace, conf.HelperImages.CurlImage, PodEntrypoint{ + res := RunPod(CurlPod, namespace, conf.HelperImages.CurlImage, PodEntrypoint{ Command: "sleep", Args: []string{"10000"}, }) @@ -179,23 +189,23 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() It("gets VMs and SVCs objects", func() { vmA = virtv2.VirtualMachine{} err = GetObject(kc.ResourceVM, aObjName, &vmA, kc.GetOptions{ - Namespace: conf.Namespace, + Namespace: namespace, }) Expect(err).NotTo(HaveOccurred(), err) vmB = virtv2.VirtualMachine{} err = GetObject(kc.ResourceVM, bObjName, &vmB, kc.GetOptions{ - Namespace: conf.Namespace, + Namespace: namespace, }) Expect(err).NotTo(HaveOccurred(), err) svcA = corev1.Service{} err = GetObject(kc.ResourceService, aObjName, &svcA, kc.GetOptions{ - Namespace: conf.Namespace, + Namespace: namespace, }) Expect(err).NotTo(HaveOccurred(), err) svcB = corev1.Service{} err = GetObject(kc.ResourceService, bObjName, &svcB, kc.GetOptions{ - Namespace: conf.Namespace, + Namespace: namespace, }) Expect(err).NotTo(HaveOccurred(), err) }) @@ -204,7 +214,7 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() cmd := "hostname" for _, vmName := range []string{vmA.Name, vmB.Name} { By(fmt.Sprintf("VirtualMachine %q", vmName)) - CheckResultSshCommand(vmName, cmd, vmName) + CheckResultSshCommand(vmName, namespace, cmd, vmName) } }) @@ -216,14 +226,14 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() cmd := "systemctl is-active nginx.service" for _, vmName := range []string{vmA.Name, vmB.Name} { By(fmt.Sprintf("VirtualMachine %q", vmName)) - CheckResultSshCommand(vmName, cmd, nginxActiveStatus) + CheckResultSshCommand(vmName, namespace, cmd, nginxActiveStatus) } }) It(fmt.Sprintf("gets page from service %s", aObjName), func() { service := GenerateServiceUrl(&svcA, conf.Namespace) Eventually(func() (string, error) { - res := GetResponseViaPodWithCurl(CurlPod, conf.Namespace, service) + res := GetResponseViaPodWithCurl(CurlPod, namespace, service) if res.Error() != nil { return "", fmt.Errorf("cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) } @@ -234,7 +244,7 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() It(fmt.Sprintf("gets page from service %s", bObjName), func() { service := GenerateServiceUrl(&svcB, conf.Namespace) Eventually(func() (string, error) { - res := GetResponseViaPodWithCurl(CurlPod, conf.Namespace, service) + res := GetResponseViaPodWithCurl(CurlPod, namespace, service) if res.Error() != nil { return "", fmt.Errorf("cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) } @@ -263,7 +273,7 @@ var _ = Describe("VM connectivity", ginkgoutil.CommonE2ETestDecorators(), func() By(fmt.Sprintf("Response should be from virtual machine %q", vmB.Name)) service := GenerateServiceUrl(&svcA, conf.Namespace) Eventually(func() (string, error) { - res := GetResponseViaPodWithCurl(CurlPod, conf.Namespace, service) + res := GetResponseViaPodWithCurl(CurlPod, namespace, service) if res.Error() != nil { return "", fmt.Errorf("cmd: %s\nstderr: %s", res.GetCmd(), res.StdErr()) } diff --git a/tests/e2e/vm_migration_test.go b/tests/e2e/vm_migration_test.go index aa526534b..780aae5d5 100644 --- a/tests/e2e/vm_migration_test.go +++ b/tests/e2e/vm_migration_test.go @@ -32,11 +32,17 @@ import ( ) const ( + VirtualMachineMigrationTest = "vm-migration" + InternalApiVersion = "internal.virtualization.deckhouse.io/v1" KubevirtVMIMKind = "InternalVirtualizationVirtualMachineInstanceMigration" ) -func MigrateVirtualMachines(label map[string]string, templatePath string, virtualMachines ...string) { +func GetVirtualMachineMigrationNamespace() string { + return conf.Namespace + "-vm-migration" +} + +func MigrateVirtualMachines(label map[string]string, templatePath, namespace string, virtualMachines ...string) { GinkgoHelper() migrationFilesPath := fmt.Sprintf("%s/migrations", templatePath) for _, vm := range virtualMachines { @@ -46,7 +52,7 @@ func MigrateVirtualMachines(label map[string]string, templatePath string, virtua res := kubectl.Apply(kc.ApplyOptions{ Filename: []string{migrationFilePath}, FilenameOption: kc.Filename, - Namespace: conf.Namespace, + Namespace: namespace, }) Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr()) } @@ -76,14 +82,21 @@ func CreateMigrationManifest(vmName, filePath string, labels map[string]string) } var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators(), func() { - testCaseLabel := map[string]string{"testcase": "vm-migration"} + var ( + testCaseLabel = map[string]string{"testcase": "vm-migration"} + namespace = conf.Namespace + ) + + if config.IsReusable() { + namespace = GetVirtualMachineMigrationNamespace() + } Context("When resources are applied", func() { It("result should be succeeded", func() { if config.IsReusable() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.Error()).NotTo(HaveOccurred(), res.StdErr()) @@ -106,7 +119,7 @@ var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators By(fmt.Sprintf("VIs should be in %s phases", PhaseReady)) WaitPhaseByLabel(kc.ResourceVI, PhaseReady, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -117,7 +130,7 @@ var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators By(fmt.Sprintf("VDs should be in %s phases", PhaseReady)) WaitPhaseByLabel(kc.ResourceVD, PhaseReady, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -128,7 +141,7 @@ var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators By(fmt.Sprintf("VMs should be in %s phases", PhaseRunning)) WaitPhaseByLabel(kc.ResourceVM, PhaseRunning, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -138,13 +151,13 @@ var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators It("starts migrations", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.WasSuccess()).To(Equal(true), res.StdErr()) vms := strings.Split(res.StdOut(), " ") - MigrateVirtualMachines(testCaseLabel, conf.TestData.VmMigration, vms...) + MigrateVirtualMachines(testCaseLabel, conf.TestData.VmMigration, namespace, vms...) }) }) @@ -153,13 +166,13 @@ var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators By(fmt.Sprintf("KubevirtVMIMs should be in %s phases", PhaseSucceeded)) WaitPhaseByLabel(kc.ResourceKubevirtVMIM, PhaseSucceeded, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) By(fmt.Sprintf("Virtual machines should be in %s phase", PhaseRunning)) WaitPhaseByLabel(kc.ResourceVM, PhaseRunning, kc.WaitOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Timeout: MaxWaitTimeout, }) }) @@ -167,13 +180,13 @@ var _ = Describe("Virtual machine migration", ginkgoutil.CommonE2ETestDecorators It("checks VMs external connection after migrations", func() { res := kubectl.List(kc.ResourceVM, kc.GetOptions{ Labels: testCaseLabel, - Namespace: conf.Namespace, + Namespace: namespace, Output: "jsonpath='{.items[*].metadata.name}'", }) Expect(res.WasSuccess()).To(Equal(true), res.StdErr()) vms := strings.Split(res.StdOut(), " ") - CheckExternalConnection(externalHost, httpStatusOk, vms...) + CheckExternalConnection(externalHost, httpStatusOk, namespace, vms...) }) })