Skip to content

Commit

Permalink
Add func testing for clearing MAC address
Browse files Browse the repository at this point in the history
Signed-off-by: Alvaro Romero <[email protected]>
  • Loading branch information
alromeros committed Dec 18, 2024
1 parent 759e626 commit 72784b5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/framework/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ func CreateRestoreForBackup(ctx context.Context, backupName, restoreName, backup
return CreateRestoreWithLabels(ctx, backupName, restoreName, backupNamespace, wait, nil)
}

func CreateRestoreWithClearedMACAddress(ctx context.Context, backupName, restoreName, backupNamespace string, wait bool) error {
return CreateRestoreWithLabels(ctx, backupName, restoreName, backupNamespace, wait, map[string]string{"velero.kubevirt.io/clear-mac-address": "true"})
}

func GetRestore(ctx context.Context, restoreName string, backupNamespace string) (*v1.Restore, error) {
checkCMD := exec.CommandContext(ctx, veleroCLI, "restore", "get", "-n", backupNamespace, "-o", "json", restoreName)

Expand Down
58 changes: 58 additions & 0 deletions tests/vm_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,64 @@ var _ = Describe("[smoke] VM Backup", func() {
),
)

It("started VM should be restored with new MAC address", func() {
// creating a started VM, so it works correctly also on WFFC storage
var err error
By("Starting a VM")
vm, err = framework.CreateStartedVirtualMachine(f.KvClient, f.Namespace.Name, framework.CreateVmWithGuestAgent("test-vm", f.StorageClass))
Expect(err).ToNot(HaveOccurred())

err = framework.WaitForVirtualMachineStatus(f.KvClient, f.Namespace.Name, vm.Name, kvv1.VirtualMachineStatusRunning)
Expect(err).ToNot(HaveOccurred())

By("Retrieving the original MAC address")
vm, err = f.KvClient.VirtualMachine(f.Namespace.Name).Get(context.TODO(), vm.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
originalMAC := vm.Spec.Template.Spec.Domain.Devices.Interfaces[0].MacAddress
if originalMAC == "" {
// This means there is no KubeMacPool running. We can simply choose a random address
originalMAC = "DE-AD-00-00-BE-AF"
update := func(vm *kvv1.VirtualMachine) *kvv1.VirtualMachine {
vm.Spec.Template.Spec.Domain.Devices.Interfaces[0].MacAddress = originalMAC
return vm
}
retryOnceOnErr(updateVm(f.KvClient, f.Namespace.Name, vm.Name, update)).Should(BeNil())

err = framework.WaitForVirtualMachineStatus(f.KvClient, f.Namespace.Name, vm.Name, kvv1.VirtualMachineStatusRunning)
Expect(err).ToNot(HaveOccurred())
}

By("Creating backup")
err = framework.CreateBackupForNamespace(timeout, backupName, f.Namespace.Name, snapshotLocation, f.BackupNamespace, true)
Expect(err).ToNot(HaveOccurred())

phase, err := framework.GetBackupPhase(timeout, backupName, f.BackupNamespace)
Expect(err).ToNot(HaveOccurred())
Expect(phase).To(Equal(velerov1api.BackupPhaseCompleted))

By("Deleting VM")
err = framework.DeleteVirtualMachine(f.KvClient, f.Namespace.Name, vm.Name)
Expect(err).ToNot(HaveOccurred())

By("Creating restore")
err = framework.CreateRestoreWithClearedMACAddress(timeout, backupName, restoreName, f.BackupNamespace, true)
Expect(err).ToNot(HaveOccurred())

rPhase, err := framework.GetRestorePhase(timeout, restoreName, f.BackupNamespace)
Expect(err).ToNot(HaveOccurred())
Expect(rPhase).To(Equal(velerov1api.RestorePhaseCompleted))

By("Verifying restored VM")
err = framework.WaitForVirtualMachineStatus(f.KvClient, f.Namespace.Name, vm.Name, kvv1.VirtualMachineStatusRunning)
Expect(err).ToNot(HaveOccurred())

By("Retrieving the restored MAC address")
vm, err = f.KvClient.VirtualMachine(f.Namespace.Name).Get(context.TODO(), vm.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
restoredMAC := vm.Spec.Template.Spec.Domain.Devices.Interfaces[0].MacAddress
Expect(restoredMAC).ToNot(Equal(originalMAC))
})

Context("VM and VMI object graph backup", func() {
Context("with instancetypes and preferences", func() {
nsDelFunc := func() {
Expand Down

0 comments on commit 72784b5

Please sign in to comment.