Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -7362,6 +7362,24 @@ public VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinatio

Map<Long, Long> volToPoolObjectMap = getVolumePoolMappingForMigrateVmWithStorage(vm, volumeToPool);

// If volumeToPool is empty and there are local storage volumes, auto-populate the mapping
if (MapUtils.isEmpty(volToPoolObjectMap) && isAnyVmVolumeUsingLocalStorage(volumes)) {
// First, find a destination host if not provided
if (destinationHost == null) {
DeployDestination deployDestination = chooseVmMigrationDestination(vm, srcHost, null);
if (deployDestination == null || deployDestination.getHost() == null) {
throw new CloudRuntimeException("Unable to find suitable destination host to migrate VM " + vm.getInstanceName());
}
destinationHost = deployDestination.getHost();
}

// Verify the destination host has local storage
if (!storageManager.isLocalStorageActiveOnHost(destinationHost.getId())) {
throw new CloudRuntimeException(String.format("Destination host %s (ID: %s) does not have local storage, but VM %s (ID: %s) has volumes using local storage",
destinationHost.getName(), destinationHost.getUuid(), vm.getInstanceName(), vm.getUuid()));
}
}
Comment on lines +7365 to +7381
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new auto-selection logic for migrating VMs with local storage lacks test coverage. Consider adding tests to verify:

  1. Auto-selection of destination host when no host is specified and VM has local storage volumes
  2. Validation that the selected destination host has local storage capability
  3. Error handling when no suitable destination host is found
  4. Behavior when user provides a destination host without volume-to-pool mappings

This would help ensure the fix for issue #10907 works correctly and prevent regressions in the future.

Copilot uses AI. Check for mistakes.

if (destinationHost == null) {
destinationHost = chooseVmMigrationDestinationUsingVolumePoolMap(vm, srcHost, volToPoolObjectMap);
}
Expand Down
Loading