Skip to content

Commit

Permalink
Add test case for live migration behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Zhuchen Wang <zcwang@google.com>
  • Loading branch information
zhuchenwang committed Oct 3, 2022
1 parent 9653842 commit 1463529
Showing 1 changed file with 62 additions and 12 deletions.
74 changes: 62 additions & 12 deletions tests/vmi_vsock_test.go
Expand Up @@ -25,6 +25,7 @@ import (
expect "github.com/google/goexpect"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
k8sv1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"

virtconfig "kubevirt.io/kubevirt/pkg/virt-config"
Expand All @@ -46,7 +47,7 @@ var _ = Describe("[Serial][sig-compute]Vsock", func() {
Expect(err).ToNot(HaveOccurred())
})

Context("", func() {
Context("VM creation", func() {
It("should expose a Vsock device", func() {
checks.SkipTestIfNoFeatureGate(virtconfig.VsockGate)
By("Creating a VMI with Vsock enabled")
Expand Down Expand Up @@ -76,21 +77,70 @@ var _ = Describe("[Serial][sig-compute]Vsock", func() {
&expect.BSnd{S: "ls /dev/vsock\n"},
&expect.BExp{R: "/dev/vsock"},
}, 300)).To(Succeed(), "Could not find a vsock device")
})
})

Context("Live migration", func() {
affinity := &k8sv1.Affinity{
NodeAffinity: &k8sv1.NodeAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []k8sv1.PreferredSchedulingTerm{
{
Preference: k8sv1.NodeSelectorTerm{
MatchExpressions: []k8sv1.NodeSelectorRequirement{
{
Key: "kubernetes.io/hostname",
Operator: k8sv1.NodeSelectorOpIn,
Values: []string{"node02"},
},
},
},
Weight: 1,
},
},
},
}

It("migrate the vmi with CID 4", func() {
checks.SkipTestIfNoFeatureGate(virtconfig.VsockGate)
By("Creating a VMI with Vsock enabled")
vmi := tests.NewRandomFedoraVMI()
vmi.Spec.Domain.Devices.AutoattachVsock = pointer.Bool(true)
vmi.Spec.Affinity = affinity
vmi = tests.RunVMIAndExpectLaunch(vmi, 60)

By("creating valid libvirt domain")
domain, err := tests.GetRunningVirtualMachineInstanceDomainXML(virtClient, vmi)
Expect(err).ToNot(HaveOccurred())
domSpec := &api.DomainSpec{}
Expect(xml.Unmarshal([]byte(domain), domSpec)).To(Succeed())
Expect(domSpec.Devices.Vsock.CID.Auto).To(Equal("no"))
Expect(domSpec.Devices.Vsock.CID.Address).To(Equal("3"))

By("Creating a new VMI with Vsock enabled on the same node")
vmi2 := tests.NewRandomFedoraVMI()
vmi2.Spec.Domain.Devices.AutoattachVsock = pointer.Bool(true)
vmi2.Spec.Affinity = affinity
vmi2 = tests.RunVMIAndExpectLaunch(vmi2, 60)

By("creating valid libvirt domain")
domain2, err := tests.GetRunningVirtualMachineInstanceDomainXML(virtClient, vmi2)
Expect(err).ToNot(HaveOccurred())
domSpec2 := &api.DomainSpec{}
Expect(xml.Unmarshal([]byte(domain2), domSpec2)).To(Succeed())
Expect(domSpec2.Devices.Vsock.CID.Auto).To(Equal("no"))
Expect(domSpec2.Devices.Vsock.CID.Address).To(Equal("4"))

By("Migrating the VMI")
By("Migrating the 2nd VMI")
checks.SkipIfMigrationIsNotPossible()
migration := tests.NewRandomMigration(vmi.Name, vmi.Namespace)
migration := tests.NewRandomMigration(vmi2.Name, vmi2.Namespace)
tests.RunMigrationAndExpectCompletion(virtClient, migration, tests.MigrationWaitTime)

By("Ensuring the Vsock is still present")
Expect(console.SafeExpectBatch(vmi, []expect.Batcher{
&expect.BSnd{S: "ls /dev/vsock-vhost\n"},
&expect.BExp{R: "/dev/vsock-vhost"},
}, 300)).To(Succeed(), "Could not find a vsock-vhost device")
Expect(console.SafeExpectBatch(vmi, []expect.Batcher{
&expect.BSnd{S: "ls /dev/vsock\n"},
&expect.BExp{R: "/dev/vsock"},
}, 300)).To(Succeed(), "Could not find a vsock device")
domain2, err = tests.GetRunningVirtualMachineInstanceDomainXML(virtClient, vmi2)
Expect(err).ToNot(HaveOccurred())
domSpec2 = &api.DomainSpec{}
Expect(xml.Unmarshal([]byte(domain2), domSpec2)).To(Succeed())
Expect(domSpec2.Devices.Vsock.CID.Auto).To(Equal("no"))
Expect(domSpec2.Devices.Vsock.CID.Address).To(Equal("4")) // Libevirt retain the CID. The virt-handler allocation doesn't work in live migration
})
})
})

0 comments on commit 1463529

Please sign in to comment.