Skip to content

Commit

Permalink
test(vm): run reusable tests in different namespaces
Browse files Browse the repository at this point in the history
Signed-off-by: Isteb4k <[email protected]>
  • Loading branch information
Isteb4k committed Jan 17, 2025
1 parent 761d876 commit 08e1ad3
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 79 deletions.
51 changes: 30 additions & 21 deletions tests/e2e/complex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
Expand All @@ -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())
Expand All @@ -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,
})
})
Expand All @@ -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,
})
})
Expand All @@ -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,
})
})
Expand All @@ -126,15 +135,15 @@ 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())
})

It("checks VMIPs phases", 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,
})
})
Expand All @@ -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,
})
})
Expand All @@ -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,
})
})
Expand All @@ -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,
})
})
Expand All @@ -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,
})
})
Expand All @@ -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...)
})
})
})
Expand All @@ -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...)
})
})

Expand All @@ -219,27 +228,27 @@ 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,
})
})

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...)
})
})

Expand Down
10 changes: 8 additions & 2 deletions tests/e2e/tests_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand All @@ -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,
})
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/vd_snapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit 08e1ad3

Please sign in to comment.