Skip to content

Commit

Permalink
e2e,storage migration,UpdateVMWithDV: Fetch volume name using slices
Browse files Browse the repository at this point in the history
Signed-off-by: Or Mergi <[email protected]>
  • Loading branch information
ormergi committed Sep 8, 2024
1 parent 2ecc0c6 commit 98f52f6
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tests/storage/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,11 @@ var _ = SIGDescribe("[Serial]Volumes update with migration", Serial, func() {
// TODO: right now, for simplicity, this function assumes the DV in the first position in the datavolumes templata list. Otherwise, we need
// to pass the old name of the DV to be replaces.
updateVMWithDV := func(vm *virtv1.VirtualMachine, volName, name string) {
var replacedIndex int
for i, v := range vm.Spec.Template.Spec.Volumes {
if v.Name == volName {
replacedIndex = i
break
}
}
i := slices.IndexFunc(vm.Spec.Template.Spec.Volumes, func(volume virtv1.Volume) bool {
return volume.Name == volName
})
Expect(i).To(BeNumerically(">", -1))
By(fmt.Sprintf("Replacing volume %s with DV %s", volName, name))

updatedVolume := virtv1.Volume{
Name: volName,
Expand All @@ -252,14 +250,14 @@ var _ = SIGDescribe("[Serial]Volumes update with migration", Serial, func() {

p, err := patch.New(
patch.WithReplace("/spec/dataVolumeTemplates/0/metadata/name", name),
patch.WithReplace(fmt.Sprintf("/spec/template/spec/volumes/%d", replacedIndex), updatedVolume),
patch.WithReplace(fmt.Sprintf("/spec/template/spec/volumes/%d", i), updatedVolume),
patch.WithReplace("/spec/updateVolumesStrategy", virtv1.UpdateVolumesStrategyMigration),
).GeneratePayload()
Expect(err).ToNot(HaveOccurred())
vm, err = virtClient.VirtualMachine(vm.Namespace).Patch(context.Background(), vm.Name, types.JSONPatchType, p, metav1.PatchOptions{})
Expect(err).ToNot(HaveOccurred())

Expect(vm.Spec.Template.Spec.Volumes[replacedIndex].VolumeSource.DataVolume.Name).To(Equal(name))
Expect(vm.Spec.Template.Spec.Volumes[i].VolumeSource.DataVolume.Name).To(Equal(name))
}

BeforeEach(func() {
Expand Down

0 comments on commit 98f52f6

Please sign in to comment.