Skip to content

Commit

Permalink
volume-migration: add unit tests for CanVolumesUpdateMigration
Browse files Browse the repository at this point in the history
Signed-off-by: Alice Frosi <[email protected]>
  • Loading branch information
alicefr committed Jun 7, 2024
1 parent e07f304 commit 0b4f0c8
Showing 1 changed file with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,87 @@ var _ = Describe("Volume Migration", func() {
)

})

Context("CanVolumesUpdateMigration", func() {
DescribeTable("should validate if the VMI can be migrate due to a volume update", func(vmi *v1.VirtualMachineInstance, exectedRes bool) {
Expect(volumemigration.CanVolumesUpdateMigration(vmi)).To(Equal(exectedRes))
},
Entry("with nil VMI", nil, false),
Entry("without migrated volumes", libvmi.New(), false),
Entry("with valid migrated volumes", libvmi.New(libvmi.WithStatus(
&v1.VirtualMachineInstanceStatus{
MigratedVolumes: []v1.StorageMigratedVolumeInfo{
{
VolumeName: "disk0",
SourcePVCInfo: &v1.PersistentVolumeClaimInfo{ClaimName: "src"},
DestinationPVCInfo: &v1.PersistentVolumeClaimInfo{ClaimName: "dst"},
},
},
Conditions: []v1.VirtualMachineInstanceCondition{
v1.VirtualMachineInstanceCondition{
Type: v1.VirtualMachineInstanceIsMigratable,
Status: k8sv1.ConditionFalse,
Reason: v1.VirtualMachineInstanceReasonDisksNotMigratable,
},
},
})), true),
Entry("with valid migrated volumes but unmigratable VMI", libvmi.New(libvmi.WithStatus(
&v1.VirtualMachineInstanceStatus{
MigratedVolumes: []v1.StorageMigratedVolumeInfo{
{
VolumeName: "disk0",
SourcePVCInfo: &v1.PersistentVolumeClaimInfo{ClaimName: "src"},
DestinationPVCInfo: &v1.PersistentVolumeClaimInfo{ClaimName: "dst"},
},
},
Conditions: []v1.VirtualMachineInstanceCondition{
v1.VirtualMachineInstanceCondition{
Type: v1.VirtualMachineInstanceIsMigratable,
Status: k8sv1.ConditionFalse,
Reason: v1.VirtualMachineInstanceReasonDisksNotMigratable,
},
v1.VirtualMachineInstanceCondition{
Type: v1.VirtualMachineInstanceIsMigratable,
Status: k8sv1.ConditionFalse,
Reason: v1.VirtualMachineInstanceReasonInterfaceNotMigratable,
},
},
})), false),
Entry("with valid migrated volumes but with an additional RWO volume", libvmi.New(libvmi.WithStatus(
&v1.VirtualMachineInstanceStatus{
MigratedVolumes: []v1.StorageMigratedVolumeInfo{
{
VolumeName: "disk0",
SourcePVCInfo: &v1.PersistentVolumeClaimInfo{ClaimName: "src"},
DestinationPVCInfo: &v1.PersistentVolumeClaimInfo{ClaimName: "dst"},
},
},
Conditions: []v1.VirtualMachineInstanceCondition{
v1.VirtualMachineInstanceCondition{
Type: v1.VirtualMachineInstanceIsMigratable,
Status: k8sv1.ConditionFalse,
Reason: v1.VirtualMachineInstanceReasonDisksNotMigratable,
},
},
VolumeStatus: []v1.VolumeStatus{
{
Name: "disk0",
PersistentVolumeClaimInfo: &v1.PersistentVolumeClaimInfo{
ClaimName: "src",
AccessModes: []k8sv1.PersistentVolumeAccessMode{k8sv1.ReadWriteOnce},
},
},
{
Name: "disk1",
PersistentVolumeClaimInfo: &v1.PersistentVolumeClaimInfo{
ClaimName: "src",
AccessModes: []k8sv1.PersistentVolumeAccessMode{k8sv1.ReadWriteOnce},
},
},
},
})), false),
)
})
})

func addPVC(vmi *v1.VirtualMachineInstance, diskName, claim string) {
Expand Down

0 comments on commit 0b4f0c8

Please sign in to comment.