Copilot commented on code in PR #12566:
URL: https://github.com/apache/cloudstack/pull/12566#discussion_r2753590975


##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -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()));
+            }
+        }

Review Comment:
   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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to