Skip to content

Commit f32807a

Browse files
committed
Fix tests
1 parent 4bb19d1 commit f32807a

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
@@ -2228,15 +2228,9 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
22282228
});
22292229
}
22302230

2231-
protected boolean existsVpcDomainRouterWithSufficientNicCapacity(long vpcId) {
2232-
DomainRouterVO vpcDomainRouter = routerDao.findOneByVpcId(vpcId);
2233-
2234-
if (vpcDomainRouter == null) {
2235-
return false;
2236-
}
2237-
2231+
protected boolean existsVpcDomainRouterWithSufficientNicCapacity(DomainRouterVO vpcDomainRouter) {
22382232
int countRouterDefaultNetworks = domainRouterJoinDao.countDefaultNetworksById(vpcDomainRouter.getId());
2239-
long countVpcNetworks = _ntwkDao.countVpcNetworks(vpcId);
2233+
long countVpcNetworks = _ntwkDao.countVpcNetworks(vpcDomainRouter.getVpcId());
22402234

22412235
Integer routerMaxNicsValue = networkOrchestrationService.getVirtualMachineMaxNicsValue(vpcDomainRouter);
22422236

@@ -2259,7 +2253,13 @@ protected void checkIfVpcNumberOfTiersIsNotExceeded(long vpcId, Account account)
22592253
}
22602254

22612255
protected void checkIfVpcHasDomainRouterWithSufficientNicCapacity(Vpc vpc) {
2262-
if (!existsVpcDomainRouterWithSufficientNicCapacity(vpc.getId())) {
2256+
DomainRouterVO vpcDomainRouter = routerDao.findOneByVpcId(vpc.getId());
2257+
if (vpcDomainRouter == null) {
2258+
logger.warn("No virtual router found for VPC {}. Skipping VR NIC capacity check.", vpc.getUuid());
2259+
return;
2260+
}
2261+
2262+
if (!existsVpcDomainRouterWithSufficientNicCapacity(vpcDomainRouter)) {
22632263
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.");
22642264
throw new CloudRuntimeException(String.format("No available virtual router found to deploy new Guest Network on VPC [%s].", vpc.getName()));
22652265
}

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ public void testCreateVpcNetwork() throws InsufficientCapacityException, Resourc
397397
Mockito.when(networkOfferingServiceMapDao.listByNetworkOfferingId(anyLong())).thenReturn(serviceMap);
398398
Mockito.when(vpcMock.getCidr()).thenReturn("10.0.0.0/8");
399399
Mockito.when(vpcMock.getNetworkDomain()).thenReturn("cs1cloud.internal");
400-
Mockito.when(manager.existsVpcDomainRouterWithSufficientNicCapacity(VPC_ID)).thenReturn(true);
401400
Mockito.doNothing().when(manager).checkIfVpcNumberOfTiersIsNotExceeded(Mockito.anyLong(), Mockito.any());
402401

403402
manager.validateNewVpcGuestNetwork("10.10.10.0/24", "10.10.10.1", accountMock, vpcMock, "cs1cloud.internal");
@@ -612,46 +611,41 @@ public void validateVpcPrivateGatewayTestAclFromDifferentVpcThrowsInvalidParamet
612611
@Test
613612
public void existsVpcDomainRouterWithSufficientNicCapacityTestUnavailableRoutersReturnsFalse() {
614613
Mockito.when(networkDao.countVpcNetworks(vpcId)).thenReturn(7L);
615-
Mockito.when(routerDao.findOneByVpcId(vpcId)).thenReturn(domainRouterVOMock);
616614
Mockito.when(domainRouterVOMock.getId()).thenReturn(1L);
615+
Mockito.when(domainRouterVOMock.getVpcId()).thenReturn(vpcId);
617616
Mockito.when(domainRouterJoinDaoMock.countDefaultNetworksById(1L)).thenReturn(2);
618617
Mockito.when(networkOrchestrationServiceMock.getVirtualMachineMaxNicsValue(domainRouterVOMock)).thenReturn(9);
619618

620-
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(vpcId);
619+
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(domainRouterVOMock);
621620

622621
Assert.assertFalse(result);
623622
}
624623

625624
@Test
626625
public void existsVpcDomainRouterWithSufficientNicCapacityTestRouterIncompatibleHypervisorTypeReturnsTrue() {
627-
Mockito.when(routerDao.findOneByVpcId(vpcId)).thenReturn(domainRouterVOMock);
628626
Mockito.when(domainRouterVOMock.getId()).thenReturn(1L);
629627
Mockito.when(domainRouterJoinDaoMock.countDefaultNetworksById(1L)).thenReturn(2);
630628
Mockito.when(networkOrchestrationServiceMock.getVirtualMachineMaxNicsValue(domainRouterVOMock)).thenReturn(null);
631629

632-
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(vpcId);
630+
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(domainRouterVOMock);
633631

634632
Assert.assertTrue(result);
635633
}
636634

637635
@Test
638636
public void existsVpcDomainRouterWithSufficientNicCapacityTestAvailableRouterReturnsTrue() {
639-
Mockito.when(networkDao.countVpcNetworks(vpcId)).thenReturn(6L);
640-
Mockito.when(routerDao.findOneByVpcId(vpcId)).thenReturn(domainRouterVOMock);
641637
Mockito.when(domainRouterVOMock.getId()).thenReturn(1L);
642638
Mockito.when(domainRouterJoinDaoMock.countDefaultNetworksById(1L)).thenReturn(2);
643639
Mockito.when(networkOrchestrationServiceMock.getVirtualMachineMaxNicsValue(domainRouterVOMock)).thenReturn(9);
644640

645-
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(vpcId);
641+
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(domainRouterVOMock);
646642

647643
Assert.assertTrue(result);
648644
}
649645

650646
@Test
651647
public void existsVpcDomainRouterWithSufficientNicCapacityTestNullRouterReturnsFalse() {
652-
Mockito.when(routerDao.findOneByVpcId(vpcId)).thenReturn(null);
653-
654-
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(vpcId);
648+
boolean result = manager.existsVpcDomainRouterWithSufficientNicCapacity(domainRouterVOMock);
655649

656650
Assert.assertFalse(result);
657651
}
@@ -667,7 +661,8 @@ public void checkIfVpcNumberOfTiersIsNotExceededTestExceededTiersThrowCloudRunti
667661
@Test
668662
public void checkIfVpcHasDomainRouterWithSufficientNicCapacityTestDomainRoutersWithoutCapacityThrowsCloudRuntimeException() {
669663
Mockito.doReturn(vpcId).when(vpcMock).getId();
670-
Mockito.doReturn(false).when(manager).existsVpcDomainRouterWithSufficientNicCapacity(vpcId);
664+
Mockito.doReturn(domainRouterVOMock).when(routerDao).findOneByVpcId(vpcId);
665+
Mockito.doReturn(false).when(manager).existsVpcDomainRouterWithSufficientNicCapacity(domainRouterVOMock);
671666

672667
Assert.assertThrows(CloudRuntimeException.class, () -> manager.checkIfVpcHasDomainRouterWithSufficientNicCapacity(vpcMock));
673668
}

0 commit comments

Comments
 (0)