Skip to content

Commit

Permalink
Merge pull request kubevirt#8556 from xpivarc/clean-windows-lane
Browse files Browse the repository at this point in the history
Move tests agnostic to Windows OS from Windows lane
  • Loading branch information
kubevirt-bot authored Oct 26, 2022
2 parents 860a35a + b39dc67 commit cfdd33b
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 99 deletions.
1 change: 1 addition & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ go_test(
"container_disk_test.go",
"credentials_test.go",
"dryrun_test.go",
"hyperv_test.go",
"infra_test.go",
"instancetype_test.go",
"kubectl_test.go",
Expand Down
152 changes: 152 additions & 0 deletions tests/hyperv_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package tests_test

import (
"context"
"fmt"
"strings"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

k8sv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"

v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/kubecli"

"kubevirt.io/kubevirt/pkg/controller"
"kubevirt.io/kubevirt/tests"
"kubevirt.io/kubevirt/tests/console"
"kubevirt.io/kubevirt/tests/libvmi"
"kubevirt.io/kubevirt/tests/util"
)

var _ = Describe("[Serial][sig-compute] Hyper-V enlightenments", func() {

var (
virtClient kubecli.KubevirtClient
err error
)
BeforeEach(func() {
virtClient, err = kubecli.GetKubevirtClient()
util.PanicOnError(err)
})

Context("VMI with HyperV re-enlightenment enabled", func() {
var reEnlightenmentVMI *v1.VirtualMachineInstance

withReEnlightenment := func(vmi *v1.VirtualMachineInstance) {
if vmi.Spec.Domain.Features == nil {
vmi.Spec.Domain.Features = &v1.Features{}
}
if vmi.Spec.Domain.Features.Hyperv == nil {
vmi.Spec.Domain.Features.Hyperv = &v1.FeatureHyperv{}
}

vmi.Spec.Domain.Features.Hyperv.Reenlightenment = &v1.FeatureState{Enabled: pointer.Bool(true)}
}

vmiWithReEnlightenment := func() *v1.VirtualMachineInstance {
options := libvmi.WithMasqueradeNetworking()
options = append(options, withReEnlightenment)
return libvmi.NewAlpine(options...)
}

BeforeEach(func() {
reEnlightenmentVMI = vmiWithReEnlightenment()
})

When("TSC frequency is exposed on the cluster", func() {
It("should be able to migrate", func() {
if !isTSCFrequencyExposed(virtClient) {
Skip("TSC frequency is not exposed on the cluster")
}

var err error
By("Creating a windows VM")
reEnlightenmentVMI, err = virtClient.VirtualMachineInstance(util.NamespaceTestDefault).Create(reEnlightenmentVMI)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStartWithTimeout(reEnlightenmentVMI, 360)

By("Migrating the VM")
migration := tests.NewRandomMigration(reEnlightenmentVMI.Name, reEnlightenmentVMI.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)

By("Checking VMI, confirm migration state")
tests.ConfirmVMIPostMigration(virtClient, reEnlightenmentVMI, migrationUID)
})
})

When("TSC frequency is not exposed on the cluster", func() {

BeforeEach(func() {
if isTSCFrequencyExposed(virtClient) {
nodeList, err := virtClient.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{})
Expect(err).ToNot(HaveOccurred())

for _, node := range nodeList.Items {
stopNodeLabeller(node.Name, virtClient)
removeTSCFrequencyFromNode(node)
}
}
})

AfterEach(func() {
nodeList, err := virtClient.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{})
Expect(err).ToNot(HaveOccurred())

for _, node := range nodeList.Items {
_, isNodeLabellerStopped := node.Annotations[v1.LabellerSkipNodeAnnotation]
Expect(isNodeLabellerStopped).To(BeTrue())

updatedNode := resumeNodeLabeller(node.Name, virtClient)
_, isNodeLabellerStopped = updatedNode.Annotations[v1.LabellerSkipNodeAnnotation]
Expect(isNodeLabellerStopped).To(BeFalse(), "after node labeller is resumed, %s annotation is expected to disappear from node", v1.LabellerSkipNodeAnnotation)
}
})

It("should be able to start successfully", func() {
var err error
By("Creating a windows VM")
reEnlightenmentVMI, err = virtClient.VirtualMachineInstance(util.NamespaceTestDefault).Create(reEnlightenmentVMI)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStartWithTimeout(reEnlightenmentVMI, 360)
Expect(console.LoginToAlpine(reEnlightenmentVMI)).To(Succeed())
})

It("should be marked as non-migratable", func() {
var err error
By("Creating a windows VM")
reEnlightenmentVMI, err = virtClient.VirtualMachineInstance(util.NamespaceTestDefault).Create(reEnlightenmentVMI)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStartWithTimeout(reEnlightenmentVMI, 360)

conditionManager := controller.NewVirtualMachineInstanceConditionManager()
isNonMigratable := func() error {
reEnlightenmentVMI, err = virtClient.VirtualMachineInstance(util.NamespaceTestDefault).Get(reEnlightenmentVMI.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())

cond := conditionManager.GetCondition(reEnlightenmentVMI, v1.VirtualMachineInstanceIsMigratable)
const errFmt = "condition " + string(v1.VirtualMachineInstanceIsMigratable) + " is expected to be %s %s"

if statusFalse := k8sv1.ConditionFalse; cond.Status != statusFalse {
return fmt.Errorf(errFmt, "of status", string(statusFalse))
}
if notMigratableNoTscReason := v1.VirtualMachineInstanceReasonNoTSCFrequencyMigratable; cond.Reason != notMigratableNoTscReason {
return fmt.Errorf(errFmt, "of reason", notMigratableNoTscReason)
}
if !strings.Contains(cond.Message, "HyperV Reenlightenment") {
return fmt.Errorf(errFmt, "with message that contains", "HyperV Reenlightenment")
}
return nil
}

Eventually(isNonMigratable, 30*time.Second, time.Second).ShouldNot(HaveOccurred())
Consistently(isNonMigratable, 15*time.Second, 3*time.Second).ShouldNot(HaveOccurred())
})
})
})

})
99 changes: 0 additions & 99 deletions tests/windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ import (
"kubevirt.io/kubevirt/tests/framework/checks"
"kubevirt.io/kubevirt/tests/libstorage"

"k8s.io/utils/pointer"

"kubevirt.io/kubevirt/pkg/controller"
"kubevirt.io/kubevirt/tests/libnode"

"kubevirt.io/kubevirt/pkg/virt-controller/watch/topology"
Expand Down Expand Up @@ -83,102 +80,6 @@ var _ = Describe("[Serial][sig-compute]Windows VirtualMachineInstance", func() {
windowsVMI.Spec.Domain.Devices.Interfaces[0].Model = "e1000"
})

Context("VMI with HyperV reenlightenment enabled", func() {
BeforeEach(func() {
windowsVMI.Spec.Domain.Features.Hyperv.Reenlightenment = &v1.FeatureState{Enabled: pointer.Bool(true)}
})

When("TSC frequency is exposed on the cluster", func() {
It("should be able to migrate", func() {
if !isTSCFrequencyExposed(virtClient) {
Skip("TSC frequency is not exposed on the cluster")
}

var err error
By("Creating a windows VM")
windowsVMI, err = virtClient.VirtualMachineInstance(util.NamespaceTestDefault).Create(windowsVMI)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStartWithTimeout(windowsVMI, 360)

By("Migrating the VM")
migration := tests.NewRandomMigration(windowsVMI.Name, windowsVMI.Namespace)
migrationUID := tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)

By("Checking VMI, confirm migration state")
tests.ConfirmVMIPostMigration(virtClient, windowsVMI, migrationUID)
})
})

When("TSC frequency is not exposed on the cluster", func() {

BeforeEach(func() {
if isTSCFrequencyExposed(virtClient) {
nodeList, err := virtClient.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{})
Expect(err).ToNot(HaveOccurred())

for _, node := range nodeList.Items {
stopNodeLabeller(node.Name, virtClient)
removeTSCFrequencyFromNode(node)
}
}
})

AfterEach(func() {
nodeList, err := virtClient.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{})
Expect(err).ToNot(HaveOccurred())

for _, node := range nodeList.Items {
_, isNodeLabellerStopped := node.Annotations[v1.LabellerSkipNodeAnnotation]
Expect(isNodeLabellerStopped).To(BeTrue())

updatedNode := resumeNodeLabeller(node.Name, virtClient)
_, isNodeLabellerStopped = updatedNode.Annotations[v1.LabellerSkipNodeAnnotation]
Expect(isNodeLabellerStopped).To(BeFalse(), "after node labeller is resumed, %s annotation is expected to disappear from node", v1.LabellerSkipNodeAnnotation)
}
})

It("should be able to start successfully", func() {
var err error
By("Creating a windows VM")
windowsVMI, err = virtClient.VirtualMachineInstance(util.NamespaceTestDefault).Create(windowsVMI)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStartWithTimeout(windowsVMI, 360)
winrnLoginCommand(virtClient, windowsVMI)
})

It("should be marked as non-migratable", func() {
var err error
By("Creating a windows VM")
windowsVMI, err = virtClient.VirtualMachineInstance(util.NamespaceTestDefault).Create(windowsVMI)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStartWithTimeout(windowsVMI, 360)

conditionManager := controller.NewVirtualMachineInstanceConditionManager()
isNonMigratable := func() error {
windowsVMI, err = virtClient.VirtualMachineInstance(util.NamespaceTestDefault).Get(windowsVMI.Name, &metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())

cond := conditionManager.GetCondition(windowsVMI, v1.VirtualMachineInstanceIsMigratable)
const errFmt = "condition " + string(v1.VirtualMachineInstanceIsMigratable) + " is expected to be %s %s"

if statusFalse := k8sv1.ConditionFalse; cond.Status != statusFalse {
return fmt.Errorf(errFmt, "of status", string(statusFalse))
}
if notMigratableNoTscReason := v1.VirtualMachineInstanceReasonNoTSCFrequencyMigratable; cond.Reason != notMigratableNoTscReason {
return fmt.Errorf(errFmt, "of reason", notMigratableNoTscReason)
}
if !strings.Contains(cond.Message, "HyperV Reenlightenment") {
return fmt.Errorf(errFmt, "with message that contains", "HyperV Reenlightenment")
}
return nil
}

Eventually(isNonMigratable, 30*time.Second, time.Second).ShouldNot(HaveOccurred())
Consistently(isNonMigratable, 15*time.Second, 3*time.Second).ShouldNot(HaveOccurred())
})
})
})

Context("with winrm connection", func() {
var winrmcliPod *k8sv1.Pod
var cli []string
Expand Down

0 comments on commit cfdd33b

Please sign in to comment.