mirror of https://github.com/apache/cloudstack.git
Merge branch 'nsx-integration' of https://github.com/apache/cloudstack into nsx-fix-code-smells
This commit is contained in:
commit
03c936dbfe
|
|
@ -23,14 +23,16 @@ import org.junit.Test;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
|
|
||||||
public class CreateNetworkOfferingCmdTest {
|
public class CreateNetworkOfferingCmdTest {
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private CreateNetworkOfferingCmd createNetworkOfferingCmd = new CreateNetworkOfferingCmd();
|
private CreateNetworkOfferingCmd createNetworkOfferingCmd = new CreateNetworkOfferingCmd();
|
||||||
|
|
||||||
|
String netName = "network";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createVpcNtwkOffWithEmptyDisplayText() {
|
public void createVpcNtwkOffWithEmptyDisplayText() {
|
||||||
String netName = "network";
|
|
||||||
ReflectionTestUtils.setField(createNetworkOfferingCmd, "networkOfferingName", netName);
|
ReflectionTestUtils.setField(createNetworkOfferingCmd, "networkOfferingName", netName);
|
||||||
Assert.assertEquals(createNetworkOfferingCmd.getDisplayText(), netName);
|
Assert.assertEquals(createNetworkOfferingCmd.getDisplayText(), netName);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,8 @@
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<excludes>
|
<excludes>
|
||||||
<exclude>**/org/apache/cloudstack/agent/api/</exclude>
|
<exclude>org/apache/cloudstack/agent/api/*</exclude>
|
||||||
<exclude>**/org/apache/cloudstack/api/response/*</exclude>
|
<exclude>org/apache/cloudstack/api/response/*</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
||||||
|
|
@ -270,15 +270,11 @@ public class NsxGuestNetworkGuruTest {
|
||||||
when(vmProfile.getVirtualMachine()).thenReturn(virtualMachine);
|
when(vmProfile.getVirtualMachine()).thenReturn(virtualMachine);
|
||||||
when(virtualMachine.getType()).thenReturn(VirtualMachine.Type.DomainRouter);
|
when(virtualMachine.getType()).thenReturn(VirtualMachine.Type.DomainRouter);
|
||||||
when(network.getId()).thenReturn(2L);
|
when(network.getId()).thenReturn(2L);
|
||||||
// when(offering.getId()).thenReturn(11L);
|
|
||||||
// when(networkModel.getNetworkIp4Dns(any(Network.class), nullable(DataCenter.class))).thenReturn(dns);
|
|
||||||
// when(networkModel.getNextAvailableMacAddressInNetwork(anyLong())).thenReturn(macAddress);
|
|
||||||
when(nicProfile.getMacAddress()).thenReturn(macAddress);
|
when(nicProfile.getMacAddress()).thenReturn(macAddress);
|
||||||
when(networkOfferingDao.isIpv6Supported(anyLong())).thenReturn(false);
|
when(networkOfferingDao.isIpv6Supported(anyLong())).thenReturn(false);
|
||||||
when(network.getDataCenterId()).thenReturn(1L);
|
when(network.getDataCenterId()).thenReturn(1L);
|
||||||
when(network.getAccountId()).thenReturn(5L);
|
when(network.getAccountId()).thenReturn(5L);
|
||||||
when(network.getVpcId()).thenReturn(51L);
|
when(network.getVpcId()).thenReturn(51L);
|
||||||
// when(account.getDomainId()).thenReturn(2L);
|
|
||||||
when(dcDao.findById(anyLong())).thenReturn(Mockito.mock(DataCenterVO.class));
|
when(dcDao.findById(anyLong())).thenReturn(Mockito.mock(DataCenterVO.class));
|
||||||
when(accountDao.findById(anyLong())).thenReturn(Mockito.mock(AccountVO.class));
|
when(accountDao.findById(anyLong())).thenReturn(Mockito.mock(AccountVO.class));
|
||||||
when(vpcDao.findById(anyLong())).thenReturn(Mockito.mock(VpcVO.class));
|
when(vpcDao.findById(anyLong())).thenReturn(Mockito.mock(VpcVO.class));
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,40 @@
|
||||||
// under the License.
|
// under the License.
|
||||||
package com.cloud.configuration;
|
package com.cloud.configuration;
|
||||||
|
|
||||||
|
import com.cloud.capacity.dao.CapacityDao;
|
||||||
|
import com.cloud.dc.DataCenterVO;
|
||||||
|
import com.cloud.dc.VlanVO;
|
||||||
|
import com.cloud.dc.dao.DataCenterDao;
|
||||||
|
import com.cloud.dc.dao.DataCenterIpAddressDao;
|
||||||
|
import com.cloud.dc.dao.DedicatedResourceDao;
|
||||||
|
import com.cloud.dc.dao.HostPodDao;
|
||||||
|
import com.cloud.dc.dao.VlanDao;
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
|
import com.cloud.host.dao.HostDao;
|
||||||
|
import com.cloud.network.Network;
|
||||||
|
import com.cloud.network.NetworkModel;
|
||||||
|
import com.cloud.network.NetworkService;
|
||||||
|
import com.cloud.network.Networks;
|
||||||
|
import com.cloud.network.dao.IPAddressDao;
|
||||||
|
import com.cloud.network.dao.NsxProviderDao;
|
||||||
|
import com.cloud.network.dao.PhysicalNetworkDao;
|
||||||
|
import com.cloud.network.element.NsxProviderVO;
|
||||||
|
import com.cloud.offering.NetworkOffering;
|
||||||
|
import com.cloud.offerings.NetworkOfferingVO;
|
||||||
|
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||||
import com.cloud.storage.StorageManager;
|
import com.cloud.storage.StorageManager;
|
||||||
|
import com.cloud.storage.dao.VMTemplateZoneDao;
|
||||||
|
import com.cloud.storage.dao.VolumeDao;
|
||||||
import com.cloud.utils.net.NetUtils;
|
import com.cloud.utils.net.NetUtils;
|
||||||
|
import com.cloud.vm.dao.VMInstanceDao;
|
||||||
|
import org.apache.cloudstack.annotation.dao.AnnotationDao;
|
||||||
|
import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd;
|
||||||
|
import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd;
|
||||||
|
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||||
import org.apache.cloudstack.framework.config.ConfigDepot;
|
import org.apache.cloudstack.framework.config.ConfigDepot;
|
||||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||||
|
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||||
|
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
@ -29,19 +58,97 @@ import org.mockito.Mock;
|
||||||
import org.mockito.MockedStatic;
|
import org.mockito.MockedStatic;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.mockito.Mockito.lenient;
|
||||||
|
import static org.mockito.Mockito.anyString;
|
||||||
|
import static org.mockito.Mockito.anyBoolean;
|
||||||
|
import static org.mockito.Mockito.doNothing;
|
||||||
|
import static org.mockito.Mockito.nullable;
|
||||||
|
import static org.mockito.Mockito.anyMap;
|
||||||
|
import static org.mockito.Mockito.anyList;
|
||||||
|
import static org.mockito.Mockito.anyInt;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class ConfigurationManagerImplTest {
|
public class ConfigurationManagerImplTest {
|
||||||
@Mock
|
@Mock
|
||||||
ConfigDepot configDepot;
|
ConfigDepot configDepot;
|
||||||
|
@Mock
|
||||||
|
NsxProviderDao nsxProviderDao;
|
||||||
|
@Mock
|
||||||
|
DataCenterDao zoneDao;
|
||||||
|
@Mock
|
||||||
|
HostDao hostDao;
|
||||||
|
@Mock
|
||||||
|
HostPodDao podDao;
|
||||||
|
@Mock
|
||||||
|
DataCenterIpAddressDao ipAddressDao;
|
||||||
|
@Mock
|
||||||
|
IPAddressDao publicIpAddressDao;
|
||||||
|
@Mock
|
||||||
|
VMInstanceDao vmInstanceDao;
|
||||||
|
@Mock
|
||||||
|
VolumeDao volumeDao;
|
||||||
|
@Mock
|
||||||
|
PhysicalNetworkDao physicalNetworkDao;
|
||||||
|
@Mock
|
||||||
|
ImageStoreDao imageStoreDao;
|
||||||
|
@Mock
|
||||||
|
VlanDao vlanDao;
|
||||||
|
@Mock
|
||||||
|
VMTemplateZoneDao vmTemplateZoneDao;
|
||||||
|
@Mock
|
||||||
|
CapacityDao capacityDao;
|
||||||
|
@Mock
|
||||||
|
DedicatedResourceDao dedicatedResourceDao;
|
||||||
|
@Mock
|
||||||
|
AnnotationDao annotationDao;
|
||||||
|
@Mock
|
||||||
|
ConfigurationDao configDao;
|
||||||
|
@Mock
|
||||||
|
NetworkOfferingDao networkOfferingDao;
|
||||||
|
@Mock
|
||||||
|
NetworkService networkService;
|
||||||
|
@Mock
|
||||||
|
NetworkModel networkModel;
|
||||||
|
|
||||||
ConfigurationManagerImpl configurationManagerImplSpy = Mockito.spy(new ConfigurationManagerImpl());
|
ConfigurationManagerImpl configurationManagerImplSpy = Mockito.spy(new ConfigurationManagerImpl());
|
||||||
|
DeleteZoneCmd deleteZoneCmd;
|
||||||
|
CreateNetworkOfferingCmd createNetworkOfferingCmd;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
configurationManagerImplSpy._configDepot = configDepot;
|
configurationManagerImplSpy._configDepot = configDepot;
|
||||||
|
configurationManagerImplSpy.nsxProviderDao = nsxProviderDao;
|
||||||
|
configurationManagerImplSpy._zoneDao = zoneDao;
|
||||||
|
configurationManagerImplSpy._hostDao = hostDao;
|
||||||
|
configurationManagerImplSpy._podDao = podDao;
|
||||||
|
configurationManagerImplSpy._privateIpAddressDao = ipAddressDao;
|
||||||
|
configurationManagerImplSpy._publicIpAddressDao = publicIpAddressDao;
|
||||||
|
configurationManagerImplSpy._vmInstanceDao = vmInstanceDao;
|
||||||
|
configurationManagerImplSpy._volumeDao = volumeDao;
|
||||||
|
configurationManagerImplSpy._physicalNetworkDao = physicalNetworkDao;
|
||||||
|
configurationManagerImplSpy._imageStoreDao = imageStoreDao;
|
||||||
|
configurationManagerImplSpy._vlanDao = vlanDao;
|
||||||
|
configurationManagerImplSpy._capacityDao = capacityDao;
|
||||||
|
configurationManagerImplSpy._dedicatedDao = dedicatedResourceDao;
|
||||||
|
configurationManagerImplSpy._configDao = configDao;
|
||||||
|
configurationManagerImplSpy._networkOfferingDao = networkOfferingDao;
|
||||||
|
configurationManagerImplSpy._networkSvc = networkService;
|
||||||
|
configurationManagerImplSpy._networkModel = networkModel;
|
||||||
|
ReflectionTestUtils.setField(configurationManagerImplSpy, "templateZoneDao", vmTemplateZoneDao);
|
||||||
|
ReflectionTestUtils.setField(configurationManagerImplSpy, "annotationDao", annotationDao);
|
||||||
|
|
||||||
|
deleteZoneCmd = Mockito.mock(DeleteZoneCmd.class);
|
||||||
|
createNetworkOfferingCmd = Mockito.mock(CreateNetworkOfferingCmd.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -250,4 +357,55 @@ public class ConfigurationManagerImplTest {
|
||||||
Mockito.doReturn(key).when(configurationManagerImplSpy._configDepot).get("config.iprange");
|
Mockito.doReturn(key).when(configurationManagerImplSpy._configDepot).get("config.iprange");
|
||||||
configurationManagerImplSpy.validateIpAddressRelatedConfigValues("config.iprange", "192.168.1.1-192.168.1.100");
|
configurationManagerImplSpy.validateIpAddressRelatedConfigValues("config.iprange", "192.168.1.1-192.168.1.100");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteZoneInvokesDeleteNsxProviderWhenNSXIsEnabled() {
|
||||||
|
NsxProviderVO nsxProviderVO = Mockito.mock(NsxProviderVO.class);
|
||||||
|
DataCenterVO dataCenterVO = Mockito.mock(DataCenterVO.class);
|
||||||
|
|
||||||
|
when(nsxProviderDao.findByZoneId(anyLong())).thenReturn(nsxProviderVO);
|
||||||
|
when(zoneDao.findById(anyLong())).thenReturn(dataCenterVO);
|
||||||
|
lenient().when(hostDao.findByDataCenterId(anyLong())).thenReturn(Collections.emptyList());
|
||||||
|
when(podDao.listByDataCenterId(anyLong())).thenReturn(Collections.emptyList());
|
||||||
|
when(ipAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
|
||||||
|
when(publicIpAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
|
||||||
|
when(vmInstanceDao.listByZoneId(anyLong())).thenReturn(Collections.emptyList());
|
||||||
|
when(volumeDao.findByDc(anyLong())).thenReturn(Collections.emptyList());
|
||||||
|
when(physicalNetworkDao.listByZone(anyLong())).thenReturn(Collections.emptyList());
|
||||||
|
when(imageStoreDao.findByZone(any(ZoneScope.class), nullable(Boolean.class))).thenReturn(Collections.emptyList());
|
||||||
|
when(vlanDao.listByZone(anyLong())).thenReturn(List.of(Mockito.mock(VlanVO.class)));
|
||||||
|
when(nsxProviderVO.getId()).thenReturn(1L);
|
||||||
|
when(zoneDao.remove(anyLong())).thenReturn(true);
|
||||||
|
when(capacityDao.removeBy(nullable(Short.class), anyLong(), nullable(Long.class), nullable(Long.class), nullable(Long.class))).thenReturn(true);
|
||||||
|
when(dedicatedResourceDao.findByZoneId(anyLong())).thenReturn(null);
|
||||||
|
lenient().when(annotationDao.removeByEntityType(anyString(), anyString())).thenReturn(true);
|
||||||
|
|
||||||
|
configurationManagerImplSpy.deleteZone(deleteZoneCmd);
|
||||||
|
|
||||||
|
verify(nsxProviderDao, times(1)).remove(anyLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateNetworkOfferingForNsx() {
|
||||||
|
NetworkOfferingVO offeringVO = Mockito.mock(NetworkOfferingVO.class);
|
||||||
|
|
||||||
|
when(createNetworkOfferingCmd.isForNsx()).thenReturn(true);
|
||||||
|
when(createNetworkOfferingCmd.getNsxMode()).thenReturn(NetworkOffering.NsxMode.NATTED.name());
|
||||||
|
when(createNetworkOfferingCmd.getTraffictype()).thenReturn(Networks.TrafficType.Guest.name());
|
||||||
|
when(createNetworkOfferingCmd.getGuestIpType()).thenReturn(Network.GuestType.Isolated.name());
|
||||||
|
when(createNetworkOfferingCmd.getAvailability()).thenReturn(NetworkOffering.Availability.Optional.name());
|
||||||
|
lenient().when(configurationManagerImplSpy.createNetworkOffering(anyString(), anyString(), any(Networks.TrafficType.class), anyString(),
|
||||||
|
anyBoolean(), any(NetworkOffering.Availability.class), anyInt(), anyMap(), anyBoolean(), any(Network.GuestType.class),
|
||||||
|
anyBoolean(), anyLong(), anyBoolean(), anyMap(), anyBoolean(), anyBoolean(), anyMap(), anyBoolean(), anyInt(),
|
||||||
|
anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyString(), anyList(), anyList(), anyBoolean(), any(NetUtils.InternetProtocol.class)))
|
||||||
|
.thenReturn(offeringVO);
|
||||||
|
when(configDao.getValue(anyString())).thenReturn("1000");
|
||||||
|
lenient().when(networkOfferingDao.persist(any(NetworkOfferingVO.class), anyMap())).thenReturn(offeringVO);
|
||||||
|
doNothing().when(networkService).validateIfServiceOfferingIsActiveAndSystemVmTypeIsDomainRouter(anyLong());
|
||||||
|
doNothing().when(networkModel).canProviderSupportServices(anyMap());
|
||||||
|
|
||||||
|
NetworkOffering offering = configurationManagerImplSpy.createNetworkOffering(createNetworkOfferingCmd);
|
||||||
|
|
||||||
|
Assert.assertNotNull(offering);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,33 @@
|
||||||
package com.cloud.network;
|
package com.cloud.network;
|
||||||
|
|
||||||
import com.cloud.dc.DataCenter;
|
import com.cloud.dc.DataCenter;
|
||||||
|
import com.cloud.dc.VlanVO;
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
|
import com.cloud.network.addr.PublicIp;
|
||||||
|
import com.cloud.network.dao.IPAddressVO;
|
||||||
|
import com.cloud.network.dao.NetworkServiceMapDao;
|
||||||
|
import com.cloud.network.dao.NetworkServiceMapVO;
|
||||||
|
import com.cloud.network.dao.NetworkVO;
|
||||||
|
import com.cloud.network.element.NetworkElement;
|
||||||
|
import com.cloud.network.element.VpcVirtualRouterElement;
|
||||||
|
import com.cloud.offerings.NetworkOfferingVO;
|
||||||
|
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
|
import com.cloud.utils.net.Ip;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.ArgumentMatchers;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class NetworkModelImplTest {
|
public class NetworkModelImplTest {
|
||||||
final String[] ip4Dns1 = {"5.5.5.5", "6.6.6.6"};
|
final String[] ip4Dns1 = {"5.5.5.5", "6.6.6.6"};
|
||||||
|
|
@ -33,6 +54,15 @@ public class NetworkModelImplTest {
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private NetworkModelImpl networkModel = new NetworkModelImpl();
|
private NetworkModelImpl networkModel = new NetworkModelImpl();
|
||||||
|
|
||||||
|
private NetworkOfferingDao networkOfferingDao;
|
||||||
|
private NetworkServiceMapDao networkServiceMapDao;
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
networkOfferingDao = Mockito.mock(NetworkOfferingDao.class);
|
||||||
|
networkServiceMapDao = Mockito.mock(NetworkServiceMapDao.class);
|
||||||
|
networkModel._networkOfferingDao = networkOfferingDao;
|
||||||
|
networkModel._ntwkSrvcDao = networkServiceMapDao;
|
||||||
|
}
|
||||||
private void prepareMocks(boolean isIp6, Network network, DataCenter zone,
|
private void prepareMocks(boolean isIp6, Network network, DataCenter zone,
|
||||||
String dns1, String dns2, String dns3, String dns4) {
|
String dns1, String dns2, String dns3, String dns4) {
|
||||||
if (isIp6) {
|
if (isIp6) {
|
||||||
|
|
@ -140,4 +170,35 @@ public class NetworkModelImplTest {
|
||||||
public void testVerifyIp6DnsPairValid() {
|
public void testVerifyIp6DnsPairValid() {
|
||||||
networkModel.verifyIp6DnsPair(ip6Dns1[0], ip6Dns1[1]);
|
networkModel.verifyIp6DnsPair(ip6Dns1[0], ip6Dns1[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetProviderToIpList() {
|
||||||
|
Set<Network.Service> services1 = new HashSet<>(List.of(Network.Service.Firewall));
|
||||||
|
Set<Network.Service> services2 = new HashSet<>(List.of(Network.Service.SourceNat));
|
||||||
|
Ip ip1 = new Ip("10.10.10.10");
|
||||||
|
Ip ip2 = new Ip("10.10.10.10");
|
||||||
|
IPAddressVO ipAddressVO1 = new IPAddressVO(ip1, 1L, 0x0ac00000L, 2L, true);
|
||||||
|
IPAddressVO ipAddressVO2 = new IPAddressVO(ip2, 1L, 0x0ac00000L, 2L, true);
|
||||||
|
VlanVO vlanVO = new VlanVO();
|
||||||
|
vlanVO.setNetworkId(15L);
|
||||||
|
PublicIpAddress publicIpAddress1 = new PublicIp(ipAddressVO1, vlanVO, 0x0ac00000L);
|
||||||
|
PublicIpAddress publicIpAddress2 = new PublicIp(ipAddressVO2, vlanVO, 0x0ac00000L);
|
||||||
|
NetworkOfferingVO networkOfferingVO = new NetworkOfferingVO();
|
||||||
|
networkOfferingVO.setForVpc(true);
|
||||||
|
networkOfferingVO.setForNsx(false);
|
||||||
|
Network network = new NetworkVO();
|
||||||
|
List<NetworkServiceMapVO> networkServiceMapVOs = new ArrayList<>();
|
||||||
|
networkServiceMapVOs.add(new NetworkServiceMapVO(15L, Network.Service.Firewall, Network.Provider.VPCVirtualRouter));
|
||||||
|
networkServiceMapVOs.add(new NetworkServiceMapVO(15L, Network.Service.SourceNat, Network.Provider.VPCVirtualRouter));
|
||||||
|
NetworkElement element = new VpcVirtualRouterElement();
|
||||||
|
|
||||||
|
ReflectionTestUtils.setField(networkModel, "networkElements", List.of(element));
|
||||||
|
Mockito.when(networkOfferingDao.findById(ArgumentMatchers.anyLong())).thenReturn(networkOfferingVO);
|
||||||
|
Mockito.when(networkServiceMapDao.getServicesInNetwork(ArgumentMatchers.anyLong())).thenReturn(networkServiceMapVOs);
|
||||||
|
Map<PublicIpAddress, Set<Network.Service>> ipToServices = new HashMap<>();
|
||||||
|
ipToServices.put(publicIpAddress1, services1);
|
||||||
|
ipToServices.put(publicIpAddress2, services2);
|
||||||
|
Map<Network.Provider, ArrayList<PublicIpAddress>> result = networkModel.getProviderToIpList(network, ipToServices);
|
||||||
|
Assert.assertNotNull(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,21 +16,93 @@
|
||||||
// under the License.
|
// under the License.
|
||||||
package com.cloud.network.router;
|
package com.cloud.network.router;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.Command;
|
||||||
import com.cloud.agent.api.routing.VmDataCommand;
|
import com.cloud.agent.api.routing.VmDataCommand;
|
||||||
|
import com.cloud.agent.manager.Commands;
|
||||||
|
import com.cloud.configuration.ConfigurationManager;
|
||||||
|
import com.cloud.dc.DataCenter;
|
||||||
|
import com.cloud.dc.DataCenterVO;
|
||||||
|
import com.cloud.dc.VlanVO;
|
||||||
|
import com.cloud.dc.dao.DataCenterDao;
|
||||||
|
import com.cloud.dc.dao.VlanDao;
|
||||||
|
import com.cloud.network.NetworkModel;
|
||||||
|
import com.cloud.network.PublicIpAddress;
|
||||||
|
import com.cloud.network.addr.PublicIp;
|
||||||
|
import com.cloud.network.dao.IPAddressDao;
|
||||||
|
import com.cloud.network.dao.IPAddressVO;
|
||||||
|
import com.cloud.network.dao.NetworkDao;
|
||||||
|
import com.cloud.network.dao.NetworkDetailsDao;
|
||||||
|
import com.cloud.network.dao.NetworkVO;
|
||||||
|
import com.cloud.network.vpc.VpcVO;
|
||||||
|
import com.cloud.network.vpc.dao.VpcDao;
|
||||||
|
import com.cloud.offering.NetworkOffering;
|
||||||
|
import com.cloud.offerings.NetworkOfferingVO;
|
||||||
|
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||||
|
import com.cloud.offerings.dao.NetworkOfferingDetailsDao;
|
||||||
|
import com.cloud.utils.net.Ip;
|
||||||
|
import com.cloud.vm.NicVO;
|
||||||
|
import com.cloud.vm.VirtualMachine;
|
||||||
|
import com.cloud.vm.dao.NicDao;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentMatchers;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class CommandSetupHelperTest {
|
public class CommandSetupHelperTest {
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
protected CommandSetupHelper commandSetupHelper = new CommandSetupHelper();
|
protected CommandSetupHelper commandSetupHelper = new CommandSetupHelper();
|
||||||
|
@Mock
|
||||||
|
NicDao nicDao;
|
||||||
|
@Mock
|
||||||
|
NetworkDao networkDao;
|
||||||
|
@Mock
|
||||||
|
IPAddressDao ipAddressDao;
|
||||||
|
@Mock
|
||||||
|
VlanDao vlanDao;
|
||||||
|
@Mock
|
||||||
|
NetworkModel networkModel;
|
||||||
|
@Mock
|
||||||
|
NetworkOfferingDao networkOfferingDao;
|
||||||
|
@Mock
|
||||||
|
ConfigurationManager configurationManager;
|
||||||
|
@Mock
|
||||||
|
NetworkOfferingDetailsDao networkOfferingDetailsDao;
|
||||||
|
@Mock
|
||||||
|
NetworkDetailsDao networkDetailsDao;
|
||||||
|
@Mock
|
||||||
|
VpcDao vpcDao;
|
||||||
|
@Mock
|
||||||
|
RouterControlHelper routerControlHelper;
|
||||||
|
@Mock
|
||||||
|
DataCenterDao dcDao;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
ReflectionTestUtils.setField(commandSetupHelper, "_nicDao", nicDao);
|
||||||
|
ReflectionTestUtils.setField(commandSetupHelper, "_networkDao", networkDao);
|
||||||
|
ReflectionTestUtils.setField(commandSetupHelper, "_ipAddressDao", ipAddressDao);
|
||||||
|
ReflectionTestUtils.setField(commandSetupHelper, "_vlanDao", vlanDao);
|
||||||
|
ReflectionTestUtils.setField(commandSetupHelper, "_networkModel", networkModel);
|
||||||
|
ReflectionTestUtils.setField(commandSetupHelper, "_networkOfferingDao", networkOfferingDao);
|
||||||
|
ReflectionTestUtils.setField(commandSetupHelper, "networkOfferingDetailsDao", networkOfferingDetailsDao);
|
||||||
|
ReflectionTestUtils.setField(commandSetupHelper, "networkDetailsDao", networkDetailsDao);
|
||||||
|
ReflectionTestUtils.setField(commandSetupHelper, "_vpcDao", vpcDao);
|
||||||
|
ReflectionTestUtils.setField(commandSetupHelper, "_routerControlHelper", routerControlHelper);
|
||||||
|
ReflectionTestUtils.setField(commandSetupHelper, "_dcDao", dcDao);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUserDataDetails() {
|
public void testUserDataDetails() {
|
||||||
|
|
@ -79,4 +151,46 @@ public class CommandSetupHelperTest {
|
||||||
Assert.assertEquals("value1", metadataFile1[2]);
|
Assert.assertEquals("value1", metadataFile1[2]);
|
||||||
Assert.assertEquals("value2", metadataFile2[2]);
|
Assert.assertEquals("value2", metadataFile2[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateVpcAssociatePublicIP() {
|
||||||
|
VirtualRouter router = Mockito.mock(VirtualRouter.class);
|
||||||
|
Ip ip = new Ip("10.10.10.10");
|
||||||
|
IPAddressVO ipAddressVO = new IPAddressVO(ip, 1L, 0x0ac00000L, 2L, true);
|
||||||
|
VlanVO vlanVO = new VlanVO();
|
||||||
|
vlanVO.setNetworkId(15L);
|
||||||
|
PublicIpAddress publicIpAddress = new PublicIp(ipAddressVO, vlanVO, 0x0ac00000L);
|
||||||
|
List<PublicIpAddress> pubIpList = new ArrayList<>(1);
|
||||||
|
pubIpList.add(publicIpAddress);
|
||||||
|
Commands commands = new Commands(Command.OnError.Stop);
|
||||||
|
Map<String, String> vlanMacAddress = new HashMap<>();
|
||||||
|
NicVO nicVO = new NicVO("nic", 1L, 2L, VirtualMachine.Type.User);
|
||||||
|
NetworkVO networkVO = new NetworkVO();
|
||||||
|
networkVO.setNetworkOfferingId(12L);
|
||||||
|
List<IPAddressVO> userIps = List.of(ipAddressVO);
|
||||||
|
NetworkOfferingVO networkOfferingVO = new NetworkOfferingVO();
|
||||||
|
Map<NetworkOffering.Detail, String> details = new HashMap<>();
|
||||||
|
VpcVO vpc = new VpcVO();
|
||||||
|
DataCenterVO dc = new DataCenterVO(1L, null, null, null, null, null, null, null, null, null, DataCenter.NetworkType.Advanced, null, null);
|
||||||
|
|
||||||
|
Mockito.when(router.getId()).thenReturn(14L);
|
||||||
|
Mockito.when(router.getDataCenterId()).thenReturn(4L);
|
||||||
|
Mockito.when(nicDao.listByVmId(ArgumentMatchers.anyLong())).thenReturn(List.of(nicVO));
|
||||||
|
Mockito.when(networkDao.findById(ArgumentMatchers.anyLong())).thenReturn(networkVO);
|
||||||
|
Mockito.when(ipAddressDao.listByAssociatedVpc(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Boolean.class))).thenReturn(userIps);
|
||||||
|
Mockito.when(vlanDao.findById(ArgumentMatchers.anyLong())).thenReturn(vlanVO);
|
||||||
|
Mockito.when(networkModel.getNetworkRate(ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong())).thenReturn(1200);
|
||||||
|
Mockito.when(networkModel.getNetwork(ArgumentMatchers.anyLong())).thenReturn(networkVO);
|
||||||
|
Mockito.when(networkOfferingDao.findById(ArgumentMatchers.anyLong())).thenReturn(networkOfferingVO);
|
||||||
|
Mockito.when(configurationManager.getNetworkOfferingNetworkRate(ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong())).thenReturn(1200);
|
||||||
|
Mockito.when(networkModel.isSecurityGroupSupportedInNetwork(networkVO)).thenReturn(false);
|
||||||
|
Mockito.when(networkOfferingDetailsDao.getNtwkOffDetails(ArgumentMatchers.anyLong())).thenReturn(details);
|
||||||
|
Mockito.when(networkDetailsDao.findDetail(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString())).thenReturn(null);
|
||||||
|
Mockito.when(vpcDao.findById(ArgumentMatchers.anyLong())).thenReturn(vpc);
|
||||||
|
Mockito.when(routerControlHelper.getRouterControlIp(ArgumentMatchers.anyLong())).thenReturn("10.1.11.101");
|
||||||
|
Mockito.when(dcDao.findById(ArgumentMatchers.anyLong())).thenReturn(dc);
|
||||||
|
|
||||||
|
commandSetupHelper.createVpcAssociatePublicIPCommands(router, pubIpList, commands, vlanMacAddress);
|
||||||
|
Assert.assertEquals(2, commands.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,11 @@ import com.cloud.agent.manager.Commands;
|
||||||
import com.cloud.exception.AgentUnavailableException;
|
import com.cloud.exception.AgentUnavailableException;
|
||||||
import com.cloud.exception.OperationTimedoutException;
|
import com.cloud.exception.OperationTimedoutException;
|
||||||
import com.cloud.exception.ResourceUnavailableException;
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
|
import com.cloud.network.NetworkModel;
|
||||||
|
import com.cloud.network.dao.NetworkDao;
|
||||||
|
import com.cloud.vm.dao.NicDao;
|
||||||
|
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
|
|
@ -51,6 +56,20 @@ public class NetworkHelperImplTest {
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
protected NetworkHelperImpl nwHelper = new NetworkHelperImpl();
|
protected NetworkHelperImpl nwHelper = new NetworkHelperImpl();
|
||||||
|
@Mock
|
||||||
|
NetworkOrchestrationService networkOrchestrationService;
|
||||||
|
@Mock
|
||||||
|
NetworkDao networkDao;
|
||||||
|
@Mock
|
||||||
|
NetworkModel networkModel;
|
||||||
|
@Mock
|
||||||
|
NicDao nicDao;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
nwHelper._networkDao = networkDao;
|
||||||
|
nwHelper._networkModel = networkModel;
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected=ResourceUnavailableException.class)
|
@Test(expected=ResourceUnavailableException.class)
|
||||||
public void testSendCommandsToRouterWrongRouterVersion()
|
public void testSendCommandsToRouterWrongRouterVersion()
|
||||||
|
|
@ -168,5 +187,4 @@ public class NetworkHelperImplTest {
|
||||||
verify(answer1, times(0)).getResult();
|
verify(answer1, times(0)).getResult();
|
||||||
assertFalse(result);
|
assertFalse(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue