Skip to content

Commit f27804f

Browse files
committed
Fix tests
1 parent 7940a7c commit f27804f

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,15 +2223,9 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
22232223
});
22242224
}
22252225

2226-
protected boolean existsVpcDomainRouterWithSufficientNicCapacity(long vpcId) {
2227-
DomainRouterVO vpcDomainRouter = routerDao.findOneByVpcId(vpcId);
2228-
2229-
if (vpcDomainRouter == null) {
2230-
return false;
2231-
}
2232-
2226+
protected boolean existsVpcDomainRouterWithSufficientNicCapacity(DomainRouterVO vpcDomainRouter) {
22332227
int countRouterDefaultNetworks = domainRouterJoinDao.countDefaultNetworksById(vpcDomainRouter.getId());
2234-
long countVpcNetworks = _ntwkDao.countVpcNetworks(vpcId);
2228+
long countVpcNetworks = _ntwkDao.countVpcNetworks(vpcDomainRouter.getVpcId());
22352229

22362230
Integer routerMaxNicsValue = networkOrchestrationService.getVirtualMachineMaxNicsValue(vpcDomainRouter);
22372231

@@ -2254,7 +2248,13 @@ protected void checkIfVpcNumberOfTiersIsNotExceeded(long vpcId, Account account)
22542248
}
22552249

22562250
protected void checkIfVpcHasDomainRouterWithSufficientNicCapacity(Vpc vpc) {
2257-
if (!existsVpcDomainRouterWithSufficientNicCapacity(vpc.getId())) {
2251+
DomainRouterVO vpcDomainRouter = routerDao.findOneByVpcId(vpc.getId());
2252+
if (vpcDomainRouter == null) {
2253+
logger.warn("No virtual router found for VPC {}. Skipping VR NIC capacity check.", vpc.getUuid());
2254+
return;
2255+
}
2256+
2257+
if (!existsVpcDomainRouterWithSufficientNicCapacity(vpcDomainRouter)) {
22582258
logger.warn("Failed to create a new VPC Guest Network because no virtual routers were found with sufficient NIC capacity. The number of VPC Guest networks cannot exceed the number of NICs a virtual router can have.");
22592259
throw new CloudRuntimeException(String.format("No available virtual router found to deploy new Guest Network on VPC [%s].", vpc.getName()));
22602260
}

server/src/test/java/com/cloud/network/vpc/VpcManagerImplTest.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ public void testCreateVpcNetwork() throws InsufficientCapacityException, Resourc
382382
Mockito.when(networkOfferingServiceMapDao.listByNetworkOfferingId(anyLong())).thenReturn(serviceMap);
383383
Mockito.when(vpcMock.getCidr()).thenReturn("10.0.0.0/8");
384384
Mockito.when(vpcMock.getNetworkDomain()).thenReturn("cs1cloud.internal");
385-
Mockito.when(manager.existsVpcDomainRouterWithSufficientNicCapacity(VPC_ID)).thenReturn(true);
386385
Mockito.doNothing().when(manager).checkIfVpcNumberOfTiersIsNotExceeded(Mockito.anyLong(), Mockito.any());
387386

388387
manager.validateNewVpcGuestNetwork("10.10.10.0/24", "10.10.10.1", accountMock, vpcMock, "cs1cloud.internal");
@@ -597,46 +596,41 @@ public void validateVpcPrivateGatewayTestAclFromDifferentVpcThrowsInvalidParamet
597596
@Test
598597
public void existsVpcDomainRouterWithSufficientNicCapacityTestUnavailableRoutersReturnsFalse() {
599598
Mockito.when(networkDao.countVpcNetworks(vpcId)).thenReturn(7L);
600-
Mockito.when(routerDao.findOneByVpcId(vpcId)).thenReturn(domainRouterVOMock);
601599
Mockito.when(domainRouterVOMock.getId()).thenReturn(1L);
600+
Mockito.when(domainRouterVOMock.getVpcId()).thenReturn(vpcId);
602601
Mockito.when(domainRouterJoinDaoMock.countDefaultNetworksById(1L)).thenReturn(2);
603602
Mockito.when(networkOrchestrationServiceMock.getVirtualMachineMaxNicsValue(domainRouterVOMock)).thenReturn(9);
604603

605-
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(vpcId);
604+
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(domainRouterVOMock);
606605

607606
Assert.assertFalse(result);
608607
}
609608

610609
@Test
611610
public void existsVpcDomainRouterWithSufficientNicCapacityTestRouterIncompatibleHypervisorTypeReturnsTrue() {
612-
Mockito.when(routerDao.findOneByVpcId(vpcId)).thenReturn(domainRouterVOMock);
613611
Mockito.when(domainRouterVOMock.getId()).thenReturn(1L);
614612
Mockito.when(domainRouterJoinDaoMock.countDefaultNetworksById(1L)).thenReturn(2);
615613
Mockito.when(networkOrchestrationServiceMock.getVirtualMachineMaxNicsValue(domainRouterVOMock)).thenReturn(null);
616614

617-
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(vpcId);
615+
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(domainRouterVOMock);
618616

619617
Assert.assertTrue(result);
620618
}
621619

622620
@Test
623621
public void existsVpcDomainRouterWithSufficientNicCapacityTestAvailableRouterReturnsTrue() {
624-
Mockito.when(networkDao.countVpcNetworks(vpcId)).thenReturn(6L);
625-
Mockito.when(routerDao.findOneByVpcId(vpcId)).thenReturn(domainRouterVOMock);
626622
Mockito.when(domainRouterVOMock.getId()).thenReturn(1L);
627623
Mockito.when(domainRouterJoinDaoMock.countDefaultNetworksById(1L)).thenReturn(2);
628624
Mockito.when(networkOrchestrationServiceMock.getVirtualMachineMaxNicsValue(domainRouterVOMock)).thenReturn(9);
629625

630-
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(vpcId);
626+
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(domainRouterVOMock);
631627

632628
Assert.assertTrue(result);
633629
}
634630

635631
@Test
636632
public void existsVpcDomainRouterWithSufficientNicCapacityTestNullRouterReturnsFalse() {
637-
Mockito.when(routerDao.findOneByVpcId(vpcId)).thenReturn(null);
638-
639-
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(vpcId);
633+
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(domainRouterVOMock);
640634

641635
Assert.assertFalse(result);
642636
}
@@ -652,7 +646,8 @@ public void checkIfVpcNumberOfTiersIsNotExceededTestExceededTiersThrowCloudRunti
652646
@Test
653647
public void checkIfVpcHasDomainRouterWithSufficientNicCapacityTestDomainRoutersWithoutCapacityThrowsCloudRuntimeException() {
654648
Mockito.doReturn(vpcId).when(vpcMock).getId();
655-
Mockito.doReturn(false).when(manager).existsVpcDomainRouterWithSufficientNicCapacity(vpcId);
649+
Mockito.doReturn(domainRouterVOMock).when(routerDao).findOneByVpcId(vpcId);
650+
Mockito.doReturn(false).when(manager).existsVpcDomainRouterWithSufficientNicCapacity(domainRouterVOMock);
656651

657652
Assert.assertThrows(CloudRuntimeException.class, () -> manager.checkIfVpcHasDomainRouterWithSufficientNicCapacity(vpcMock));
658653
}

0 commit comments

Comments
 (0)