1818
1919import com .cloud .kubernetes .cluster .KubernetesCluster ;
2020import com .cloud .kubernetes .cluster .KubernetesClusterManagerImpl ;
21+ import com .cloud .kubernetes .cluster .KubernetesClusterVmMapVO ;
22+ import com .cloud .kubernetes .cluster .dao .KubernetesClusterVmMapDao ;
2123import com .cloud .offering .ServiceOffering ;
2224import com .cloud .service .ServiceOfferingVO ;
2325import com .cloud .service .dao .ServiceOfferingDao ;
2426import com .cloud .utils .Pair ;
27+ import com .cloud .vm .UserVmVO ;
28+ import com .cloud .vm .dao .UserVmDao ;
2529import org .junit .Assert ;
2630import org .junit .Before ;
2731import org .junit .Test ;
3034import org .mockito .Mockito ;
3135import org .mockito .junit .MockitoJUnitRunner ;
3236
37+ import java .util .List ;
38+
3339import static com .cloud .kubernetes .cluster .KubernetesServiceHelper .KubernetesClusterNodeType .DEFAULT ;
3440import static com .cloud .kubernetes .cluster .KubernetesServiceHelper .KubernetesClusterNodeType .CONTROL ;
3541
@@ -42,6 +48,10 @@ public class KubernetesClusterScaleWorkerTest {
4248 private KubernetesClusterManagerImpl clusterManager ;
4349 @ Mock
4450 private ServiceOfferingDao serviceOfferingDao ;
51+ @ Mock
52+ private KubernetesClusterVmMapDao kubernetesClusterVmMapDao ;
53+ @ Mock
54+ private UserVmDao userVmDao ;
4555
4656 private KubernetesClusterScaleWorker worker ;
4757
@@ -51,6 +61,8 @@ public class KubernetesClusterScaleWorkerTest {
5161 public void setUp () {
5262 worker = new KubernetesClusterScaleWorker (kubernetesCluster , clusterManager );
5363 worker .serviceOfferingDao = serviceOfferingDao ;
64+ worker .kubernetesClusterVmMapDao = kubernetesClusterVmMapDao ;
65+ worker .userVmDao = userVmDao ;
5466 }
5567
5668 @ Test
@@ -78,6 +90,8 @@ public void testCalculateNewClusterCountAndCapacityAllNodesScaleSize() {
7890 @ Test
7991 public void testCalculateNewClusterCountAndCapacityNodeTypeScaleControlOffering () {
8092 long controlNodes = 2L ;
93+ long kubernetesClusterId = 10L ;
94+ Mockito .when (kubernetesCluster .getId ()).thenReturn (kubernetesClusterId );
8195 Mockito .when (kubernetesCluster .getControlNodeCount ()).thenReturn (controlNodes );
8296
8397 ServiceOfferingVO existingOffering = Mockito .mock (ServiceOfferingVO .class );
@@ -90,7 +104,6 @@ public void testCalculateNewClusterCountAndCapacityNodeTypeScaleControlOffering(
90104 Mockito .when (kubernetesCluster .getCores ()).thenReturn (remainingClusterCpu + (controlNodes * existingCores ));
91105 Mockito .when (kubernetesCluster .getMemory ()).thenReturn (remainingClusterMemory + (controlNodes * existingMemory ));
92106
93- Mockito .when (kubernetesCluster .getControlServiceOfferingId ()).thenReturn (1L );
94107 Mockito .when (serviceOfferingDao .findById (1L )).thenReturn (existingOffering );
95108
96109 ServiceOfferingVO newOffering = Mockito .mock (ServiceOfferingVO .class );
@@ -99,6 +112,12 @@ public void testCalculateNewClusterCountAndCapacityNodeTypeScaleControlOffering(
99112 Mockito .when (newOffering .getCpu ()).thenReturn (newCores );
100113 Mockito .when (newOffering .getRamSize ()).thenReturn (newMemory );
101114
115+ KubernetesClusterVmMapVO controlNodeVM1 = Mockito .mock (KubernetesClusterVmMapVO .class );
116+ Mockito .when (controlNodeVM1 .getVmId ()).thenReturn (10L );
117+ UserVmVO userVmVO = Mockito .mock (UserVmVO .class );
118+ Mockito .when (userVmVO .getServiceOfferingId ()).thenReturn (defaultOfferingId );
119+ Mockito .when (userVmDao .findById (10L )).thenReturn (userVmVO );
120+ Mockito .when (kubernetesClusterVmMapDao .listByClusterIdAndVmType (kubernetesClusterId , CONTROL )).thenReturn (List .of (controlNodeVM1 ));
102121 Pair <Long , Long > newClusterCapacity = worker .calculateNewClusterCountAndCapacity (null , CONTROL , newOffering );
103122
104123 long expectedCores = remainingClusterCpu + (controlNodes * newCores );
0 commit comments