2020import com .cloud .dc .DataCenterVO ;
2121import com .cloud .dc .Vlan .VlanType ;
2222import com .cloud .dc .dao .DataCenterDao ;
23+ import com .cloud .deploy .DataCenterDeployment ;
2324import com .cloud .deploy .DeploymentPlanningManager ;
2425import com .cloud .exception .InvalidParameterValueException ;
2526import com .cloud .exception .PermissionDeniedException ;
@@ -227,7 +228,7 @@ public void setup() throws IllegalAccessException, NoSuchFieldException {
227228 apiDBUtilsMock = Mockito .mockStatic (ApiDBUtils .class );
228229 // Return empty list to avoid architecture filtering in most tests
229230 apiDBUtilsMock .when (() -> ApiDBUtils .listZoneClustersArchs (Mockito .anyLong ()))
230- .thenReturn (new ArrayList <>());
231+ .thenReturn (new ArrayList <>());
231232 }
232233
233234 @ After
@@ -246,7 +247,7 @@ private void overrideDefaultConfigValue(final ConfigKey configKey, final String
246247 }
247248
248249 @ Test (expected = InvalidParameterValueException .class )
249- public void testDuplicateRegistraitons () {
250+ public void testDuplicateRegistrations () {
250251 String accountName = "account" ;
251252 String publicKeyString = "ssh-rsa very public" ;
252253 String publicKeyMaterial = spy .getPublicKeyFromKeyKeyMaterial (publicKeyString );
@@ -826,9 +827,13 @@ public void testListHostsForMigrationOfVMLxcUserVM() {
826827 @ Test
827828 public void testListHostsForMigrationOfVMGpuEnabled () {
828829 VMInstanceVO vm = mockRunningVM (1L , HypervisorType .KVM );
830+ long hostId = vm .getHostId ();
831+ HostVO srcHost = mockHost (hostId , 4L , 5L , 6L , HypervisorType .KVM );
829832 Account caller = mockRootAdminAccount ();
833+
830834 Mockito .doReturn (caller ).when (spy ).getCaller ();
831835 Mockito .when (vmInstanceDao .findById (1L )).thenReturn (vm );
836+ Mockito .doReturn (srcHost ).when (hostDao ).findById (hostId );
832837
833838 // Mock GPU detail
834839 Mockito .when (serviceOfferingDetailsDao .findDetail (vm .getServiceOfferingId (), GPU .Keys .pciDevice .toString ()))
@@ -888,7 +893,7 @@ public void testListHostsForMigrationOfVMWithSystemVM() {
888893 spy .listHostsForMigrationOfVM (1L , 0L , 20L , null );
889894
890895 // Verify storage motion capability was checked
891- Mockito .verify (hypervisorCapabilitiesDao ).isStorageMotionSupported (HypervisorType .VMware , null );
896+ Mockito .verify (hypervisorCapabilitiesDao , Mockito . atLeastOnce () ).isStorageMotionSupported (HypervisorType .VMware , null );
892897
893898 // Verify result structure and data
894899 Assert .assertNotNull (result );
@@ -952,7 +957,7 @@ public void testListHostsForMigrationOfVMWithDomainRouter() {
952957 spy .listHostsForMigrationOfVM (1L , 0L , 20L , null );
953958
954959 // Verify hypervisor capabilities were checked
955- Mockito .verify (hypervisorCapabilitiesDao ).isStorageMotionSupported (HypervisorType .KVM , "" );
960+ Mockito .verify (hypervisorCapabilitiesDao , Mockito . atLeastOnce () ).isStorageMotionSupported (HypervisorType .KVM , "" );
956961
957962 // Verify result contains expected hosts
958963 Assert .assertNotNull (result );
@@ -1097,7 +1102,7 @@ public void testListHostsForMigrationOfVMKVMWithNullHypervisorVersion() {
10971102 spy .listHostsForMigrationOfVM (1L , 0L , 20L , null );
10981103
10991104 // Verify KVM null version was converted to empty string
1100- Mockito .verify (hypervisorCapabilitiesDao ).isStorageMotionSupported (HypervisorType .KVM , "" );
1105+ Mockito .verify (hypervisorCapabilitiesDao , Mockito . atLeastOnce () ).isStorageMotionSupported (HypervisorType .KVM , "" );
11011106
11021107 // Verify result data
11031108 Assert .assertNotNull (result );
@@ -1416,7 +1421,7 @@ public void testListHostsForMigrationOfVMStorageMotionCapabilityCheck() {
14161421 spy .listHostsForMigrationOfVM (1L , 0L , 20L , null );
14171422
14181423 // Verify storage motion capability was checked for User VM
1419- Mockito .verify (hypervisorCapabilitiesDao ).isStorageMotionSupported (HypervisorType .VMware , null );
1424+ Mockito .verify (hypervisorCapabilitiesDao , Mockito . atLeastOnce () ).isStorageMotionSupported (HypervisorType .VMware , null );
14201425
14211426 // Verify response data
14221427 Assert .assertNotNull (result );
@@ -1481,7 +1486,7 @@ public void testListHostsForMigrationOfVMWithAllSupportedHypervisors() {
14811486 spy .listHostsForMigrationOfVM (1L , 0L , 20L , null );
14821487
14831488 // Verify hypervisor is in supported hypervisors list
1484- Mockito .verify (hypervisorCapabilitiesDao ).isStorageMotionSupported (hypervisorType , version );
1489+ Mockito .verify (hypervisorCapabilitiesDao , Mockito . atLeastOnce () ).isStorageMotionSupported (hypervisorType , version );
14851490
14861491 // Verify validation passed for this hypervisor
14871492 Assert .assertNotNull ("Result should not be null for " + hypervisorType , result );
@@ -1508,8 +1513,6 @@ public void testListHostsForMigrationOfVMSourceHostNotFound() {
15081513 Account caller = mockRootAdminAccount ();
15091514 Mockito .doReturn (caller ).when (spy ).getCaller ();
15101515 Mockito .when (vmInstanceDao .findById (1L )).thenReturn (vm );
1511- Mockito .when (serviceOfferingDetailsDao .findDetail (vm .getServiceOfferingId (), GPU .Keys .pciDevice .toString ()))
1512- .thenReturn (null );
15131516 Mockito .when (hostDao .findById (vm .getHostId ())).thenReturn (null );
15141517
15151518 spy .listHostsForMigrationOfVM (1L , 0L , 20L , null );
@@ -1589,7 +1592,7 @@ public void testListHostsForMigrationOfVMStorageMotionCheckForSystemVM() {
15891592 spy .listHostsForMigrationOfVM (1L , 0L , 20L , null );
15901593
15911594 // Verify that storage motion capability was checked for system VM (VMware is in hypervisorTypes list)
1592- Mockito .verify (hypervisorCapabilitiesDao ).isStorageMotionSupported (HypervisorType .VMware , null );
1595+ Mockito .verify (hypervisorCapabilitiesDao , Mockito . atLeastOnce () ).isStorageMotionSupported (HypervisorType .VMware , null );
15931596
15941597 // Verify response structure
15951598 Assert .assertNotNull (result );
@@ -1642,7 +1645,7 @@ public void testListHostsForMigrationOfVMStorageMotionCheckForUserVM() {
16421645 spy .listHostsForMigrationOfVM (1L , 0L , 20L , null );
16431646
16441647 // Verify User VM can migrate with storage (User VM type always checks)
1645- Mockito .verify (hypervisorCapabilitiesDao ).isStorageMotionSupported (HypervisorType .KVM , "" );
1648+ Mockito .verify (hypervisorCapabilitiesDao , Mockito . atLeastOnce () ).isStorageMotionSupported (HypervisorType .KVM , "" );
16461649
16471650 // Verify response data
16481651 Assert .assertNotNull (result );
@@ -1695,7 +1698,7 @@ public void testListHostsForMigrationOfVMWithoutStorageMotionClusterScope() {
16951698 spy .listHostsForMigrationOfVM (1L , 0L , 20L , null );
16961699
16971700 // Verify XenServer without storage motion was checked
1698- Mockito .verify (hypervisorCapabilitiesDao ).isStorageMotionSupported (HypervisorType .XenServer , null );
1701+ Mockito .verify (hypervisorCapabilitiesDao , Mockito . atLeastOnce () ).isStorageMotionSupported (HypervisorType .XenServer , null );
16991702 // Verify cluster-scoped search was used (not zone-wide)
17001703 Mockito .verify (spy ).searchForServers (
17011704 Mockito .eq (0L ), Mockito .eq (20L ), Mockito .isNull (), Mockito .any (Type .class ),
@@ -1845,14 +1848,14 @@ public void testListHostsForMigrationOfVMVmwareStorageMotionCheck() {
18451848 Mockito .doReturn (caller ).when (spy ).getCaller ();
18461849 Mockito .when (vmInstanceDao .findById (1L )).thenReturn (vm );
18471850 Mockito .when (serviceOfferingDetailsDao .findDetail (vm .getServiceOfferingId (), GPU .Keys .pciDevice .toString ()))
1848- .thenReturn (null );
1851+ .thenReturn (null );
18491852
18501853 HostVO srcHost = mockHost (100L , 1L , 1L , 1L , HypervisorType .VMware );
18511854 Mockito .when (hostDao .findById (vm .getHostId ())).thenReturn (srcHost );
18521855
18531856 // VMware with DomainRouter should still check storage motion
18541857 Mockito .when (hypervisorCapabilitiesDao .isStorageMotionSupported (HypervisorType .VMware , null ))
1855- .thenReturn (true );
1858+ .thenReturn (true );
18561859
18571860 ServiceOfferingVO offering = Mockito .mock (ServiceOfferingVO .class );
18581861 Mockito .when (offeringDao .findById (vm .getId (), vm .getServiceOfferingId ())).thenReturn (offering );
@@ -1880,7 +1883,7 @@ public void testListHostsForMigrationOfVMVmwareStorageMotionCheck() {
18801883 spy .listHostsForMigrationOfVM (1L , 0L , 20L , null );
18811884
18821885 // Verify VMware always checks storage motion (hypervisorTypes list includes VMware)
1883- Mockito .verify (hypervisorCapabilitiesDao ).isStorageMotionSupported (HypervisorType .VMware , null );
1886+ Mockito .verify (hypervisorCapabilitiesDao , Mockito . atLeastOnce () ).isStorageMotionSupported (HypervisorType .VMware , null );
18841887
18851888 // Verify response
18861889 Assert .assertNotNull (result );
@@ -2074,4 +2077,32 @@ private DiskOfferingVO mockSharedDiskOffering(Long id) {
20742077 Mockito .when (diskOffering .isUseLocalStorage ()).thenReturn (false );
20752078 return diskOffering ;
20762079 }
2080+
2081+ @ Test
2082+ public void createDeploymentPlanForMigrationListingTestAllocatesInAnyClusterWhenStorageMigrationIsSupported () {
2083+ VMInstanceVO vm = mockRunningVM (1L , HypervisorType .KVM );
2084+ HostVO srcHost = mockHost (vm .getHostId (), 1L , 2L , 3L , HypervisorType .KVM );
2085+
2086+ Mockito .doReturn (true ).when (spy ).isStorageMigrationSupported (vm , srcHost );
2087+
2088+ DataCenterDeployment deploymentPlan = spy .createDeploymentPlanForMigrationListing (vm , srcHost );
2089+
2090+ Assert .assertEquals (3L , deploymentPlan .getDataCenterId ());
2091+ Assert .assertEquals (2L , (long ) deploymentPlan .getPodId ());
2092+ Assert .assertNull (deploymentPlan .getClusterId ());
2093+ }
2094+
2095+ @ Test
2096+ public void createDeploymentPlanForMigrationListingTestAllocatesInSourceClusterWhenStorageMigrationIsNotSupported () {
2097+ VMInstanceVO vm = mockRunningVM (1L , HypervisorType .XenServer );
2098+ HostVO srcHost = mockHost (vm .getHostId (), 4L , 5L , 6L , HypervisorType .XenServer );
2099+
2100+ Mockito .doReturn (false ).when (spy ).isStorageMigrationSupported (vm , srcHost );
2101+
2102+ DataCenterDeployment deploymentPlan = spy .createDeploymentPlanForMigrationListing (vm , srcHost );
2103+
2104+ Assert .assertEquals (6L , deploymentPlan .getDataCenterId ());
2105+ Assert .assertEquals (5L , (long ) deploymentPlan .getPodId ());
2106+ Assert .assertEquals (4L , (long ) deploymentPlan .getClusterId ());
2107+ }
20772108}
0 commit comments