Copilot commented on code in PR #13099:
URL: https://github.com/apache/cloudstack/pull/13099#discussion_r3186800873
##########
server/src/test/java/org/apache/cloudstack/cluster/ClusterDrsServiceImplTest.java:
##########
@@ -852,6 +852,49 @@ public void testGetBestMigration() throws
ConfigurationException {
assertEquals(vm1, bestMigration.first());
}
+ @Test
+ public void testGetBestMigrationSkipsPassthroughVm() throws
ConfigurationException {
+ ClusterVO cluster = Mockito.mock(ClusterVO.class);
+ Mockito.when(cluster.getId()).thenReturn(1L);
+
+ HostVO destHost = Mockito.mock(HostVO.class);
+ Mockito.when(destHost.getClusterId()).thenReturn(1L);
+
+ VMInstanceVO vmPassthrough = Mockito.mock(VMInstanceVO.class);
+ Mockito.when(vmPassthrough.getId()).thenReturn(1L);
+
Mockito.when(vmPassthrough.getType()).thenReturn(VirtualMachine.Type.User);
+
Mockito.when(vmPassthrough.getState()).thenReturn(VirtualMachine.State.Running);
+
Mockito.when(vmPassthrough.getDetails()).thenReturn(Collections.emptyMap());
+
+ VMInstanceVO vmNormal = Mockito.mock(VMInstanceVO.class);
+ Mockito.when(vmNormal.getId()).thenReturn(2L);
+ Mockito.when(vmNormal.getType()).thenReturn(VirtualMachine.Type.User);
+
Mockito.when(vmNormal.getState()).thenReturn(VirtualMachine.State.Running);
+ Mockito.when(vmNormal.getDetails()).thenReturn(Collections.emptyMap());
+
+ List<VirtualMachine> vmList = new ArrayList<>();
+ vmList.add(vmPassthrough);
+ vmList.add(vmNormal);
+
+ ServiceOffering serviceOffering = Mockito.mock(ServiceOffering.class);
+ Map<Long, ServiceOffering> vmIdServiceOfferingMap = new HashMap<>();
+ vmIdServiceOfferingMap.put(vmPassthrough.getId(), serviceOffering);
+ vmIdServiceOfferingMap.put(vmNormal.getId(), serviceOffering);
+
+ Mockito.when(managementServer.listHostsForMigrationOfVM(vmPassthrough,
0L, 500L, null, vmList))
+ .thenThrow(new InvalidParameterValueException("Unsupported
operation, VM uses host passthrough, cannot migrate"));
+ Mockito.when(managementServer.listHostsForMigrationOfVM(vmNormal, 0L,
500L, null, vmList)).thenReturn(
+ new Ternary<>(new Pair<>(List.of(destHost), 1),
List.of(destHost), Map.of(destHost, false)));
+ Mockito.when(balancedAlgorithm.getMetrics(cluster, vmNormal,
serviceOffering, destHost, new HashMap<>(),
+ new HashMap<>(), false)).thenReturn(new Ternary<>(1.0, 0.5,
1.5));
+
+ Pair<VirtualMachine, Host> bestMigration =
clusterDrsService.getBestMigration(cluster, balancedAlgorithm,
+ vmList, vmIdServiceOfferingMap, new HashMap<>(), new
HashMap<>());
Review Comment:
This new unit test uses outdated method signatures:
`ClusterDrsAlgorithm#getMetrics` is a 10-parameter method (see
api/src/main/java/org/apache/cloudstack/cluster/ClusterDrsAlgorithm.java), but
the test stubs a 7-parameter call, which won’t compile. Similarly,
`ClusterDrsServiceImpl#getBestMigration` currently requires the
compatible-hosts/storage-motion/excludes caches (9 parameters total); the
6-argument invocation here won’t compile. Please update the test to follow the
same setup/stubbing pattern as `testGetBestMigration()` above (build the
required caches + capacity maps and stub `getMetrics` with matchers for the
10-arg signature).
--
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]