Skip to content

Commit fb60564

Browse files
authored
core: fix instance snapshot failure (#14543)
Fix null volume list in KVM disk-only VM snapshot commands Populate the inherited volume list from the volume/path pairs so UEFI NVRAM backup can locate the root volume without throwing a NullPointerException. Update the NVRAM regression test to use a real snapshot command instead of mocking the missing list. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 2a4d7d9 commit fb60564

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

‎core/src/main/java/com/cloud/agent/api/storage/CreateDiskOnlyVmSnapshotCommand.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.cloudstack.storage.to.VolumeObjectTO;
2727

2828
import java.util.List;
29+
import java.util.stream.Collectors;
2930

3031
public class CreateDiskOnlyVmSnapshotCommand extends VMSnapshotBaseCommand {
3132

@@ -41,7 +42,8 @@ public CreateDiskOnlyVmSnapshotCommand(String vmName, VMSnapshotTO snapshot, Lis
4142

4243
public CreateDiskOnlyVmSnapshotCommand(String vmName, String vmUuid, VMSnapshotTO snapshot, List<Pair<VolumeObjectTO, String>> volumeTosAndNewPaths, String guestOSType,
4344
VirtualMachine.State vmState, boolean uefiEnabled) {
44-
super(vmName, snapshot, null, guestOSType);
45+
super(vmName, snapshot, volumeTosAndNewPaths == null ? null : volumeTosAndNewPaths.stream()
46+
.map(Pair::first).collect(Collectors.toList()), guestOSType);
4547
this.vmUuid = vmUuid;
4648
this.vmState = vmState;
4749
this.volumeTosAndNewPaths = volumeTosAndNewPaths;

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.cloud.storage.Storage;
6060
import com.cloud.storage.Volume;
6161
import com.cloud.utils.Pair;
62+
import com.cloud.vm.VirtualMachine;
6263

6364
public class LibvirtDiskOnlyVMSnapshotCommandWrapperTest {
6465

@@ -68,21 +69,17 @@ public void testBackupNvramIfNeededCopiesActiveNvram() throws Exception {
6869
LibvirtComputingResource resource = mock(LibvirtComputingResource.class);
6970
KVMStoragePoolManager storagePoolManager = mock(KVMStoragePoolManager.class);
7071
KVMStoragePool storagePool = mock(KVMStoragePool.class);
71-
CreateDiskOnlyVmSnapshotCommand command = mock(CreateDiskOnlyVmSnapshotCommand.class);
7272
VMSnapshotTO vmSnapshotTO = mock(VMSnapshotTO.class);
7373
PrimaryDataStoreTO dataStoreTO = mock(PrimaryDataStoreTO.class);
7474
VolumeObjectTO rootVolume = mock(VolumeObjectTO.class);
75+
CreateDiskOnlyVmSnapshotCommand command = new CreateDiskOnlyVmSnapshotCommand("vm-name", "vm-uuid", vmSnapshotTO,
76+
List.of(new Pair<>(rootVolume, "snapshot-volume-path")), null, VirtualMachine.State.Running, true);
7577

7678
Path activeNvram = Files.createTempFile("active-", ".fd");
7779
Files.writeString(activeNvram, "snapshot-nvram");
7880
Path poolDirectory = Files.createTempDirectory("pool-");
7981

80-
when(command.isUefiEnabled()).thenReturn(true);
81-
when(command.getVmUuid()).thenReturn("vm-uuid");
82-
when(command.getVmName()).thenReturn("vm-name");
83-
when(command.getTarget()).thenReturn(vmSnapshotTO);
8482
when(vmSnapshotTO.getId()).thenReturn(42L);
85-
when(command.getVolumeTOs()).thenReturn(List.of(rootVolume));
8683
when(rootVolume.getVolumeType()).thenReturn(Volume.Type.ROOT);
8784
when(rootVolume.getDataStore()).thenReturn(dataStoreTO);
8885
when(dataStoreTO.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem);

0 commit comments

Comments
 (0)