Skip to content

Commit b0b7d11

Browse files
committed
kvm: keep the restore volume mapping tests on the rsync path
The incremental NAS backup backport (#13877) makes a restore first ask qemu-img whether the backup references a parent, and flattens the chain with qemu-img convert when it does; only a backup without a backing file is rsynced. The volume mapping tests stubbed runSimpleBashScriptForExitValue to return 0 for every command, so the probe reported a backing chain, the restore took the convert path, and the rsync invocations these tests assert on never happened. Answer the probe with "no backing chain", as the existing restore tests do, and keep 0 for the other checks.
1 parent 1ba78e1 commit b0b7d11

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapperTest.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,12 @@ public void testRestoreOfExistingVmMapsBackupsToVolumesByUuid() throws Exception
624624
scriptMock.when(() -> Script.getExecutableAbsolutePath(anyString()))
625625
.thenAnswer(invocation -> invocation.getArgument(0));
626626
scriptMock.when(() -> Script.executeCommandForExitValue(anyLong(), any(String[].class))).thenReturn(0);
627-
scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString())).thenReturn(0);
627+
scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString()))
628+
.thenAnswer(invocation -> {
629+
String command = invocation.getArgument(0);
630+
// No backing chain, so the restore takes the rsync path this test asserts on.
631+
return command.contains("backing-filename") ? 1 : 0;
632+
});
628633
filesMock.when(() -> Files.deleteIfExists(any(Path.class))).thenReturn(true);
629634

630635
Answer result = wrapper.execute(command, libvirtComputingResource);
@@ -684,7 +689,12 @@ public void testRestoreOfExistingVmFailsWhenBackedUpVolumeIsNoLongerAttached() t
684689
scriptMock.when(() -> Script.getExecutableAbsolutePath(anyString()))
685690
.thenAnswer(invocation -> invocation.getArgument(0));
686691
scriptMock.when(() -> Script.executeCommandForExitValue(anyLong(), any(String[].class))).thenReturn(0);
687-
scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString())).thenReturn(0);
692+
scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString()))
693+
.thenAnswer(invocation -> {
694+
String command = invocation.getArgument(0);
695+
// No backing chain, so the restore takes the rsync path this test asserts on.
696+
return command.contains("backing-filename") ? 1 : 0;
697+
});
688698
filesMock.when(() -> Files.deleteIfExists(any(Path.class))).thenReturn(true);
689699

690700
Answer result = wrapper.execute(command, libvirtComputingResource);
@@ -735,7 +745,12 @@ public void testRestoreIntoNewVolumesFallsBackToDeviceIdOrder() throws Exception
735745
scriptMock.when(() -> Script.getExecutableAbsolutePath(anyString()))
736746
.thenAnswer(invocation -> invocation.getArgument(0));
737747
scriptMock.when(() -> Script.executeCommandForExitValue(anyLong(), any(String[].class))).thenReturn(0);
738-
scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString())).thenReturn(0);
748+
scriptMock.when(() -> Script.runSimpleBashScriptForExitValue(anyString()))
749+
.thenAnswer(invocation -> {
750+
String command = invocation.getArgument(0);
751+
// No backing chain, so the restore takes the rsync path this test asserts on.
752+
return command.contains("backing-filename") ? 1 : 0;
753+
});
739754
filesMock.when(() -> Files.deleteIfExists(any(Path.class))).thenReturn(true);
740755

741756
Answer result = wrapper.execute(command, libvirtComputingResource);

0 commit comments

Comments
 (0)