mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Remove duplicate network state checks before shutdown network (#8462)
This commit is contained in:
parent
313a165e62
commit
9055610034
@ -3026,30 +3026,21 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||||||
@Override
|
@Override
|
||||||
@DB
|
@DB
|
||||||
public boolean shutdownNetwork(final long networkId, final ReservationContext context, final boolean cleanupElements) {
|
public boolean shutdownNetwork(final long networkId, final ReservationContext context, final boolean cleanupElements) {
|
||||||
NetworkVO network = _networksDao.findById(networkId);
|
NetworkVO network = null;
|
||||||
if (network.getState() == Network.State.Allocated) {
|
|
||||||
s_logger.debug("Network is already shutdown: " + network);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (network.getState() != Network.State.Implemented && network.getState() != Network.State.Shutdown) {
|
|
||||||
s_logger.debug("Network is not implemented: " + network);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//do global lock for the network
|
//do global lock for the network
|
||||||
network = _networksDao.acquireInLockTable(networkId, NetworkLockTimeout.value());
|
network = _networksDao.acquireInLockTable(networkId, NetworkLockTimeout.value());
|
||||||
if (network == null) {
|
if (network == null) {
|
||||||
s_logger.warn("Unable to acquire lock for the network " + network + " as a part of network shutdown");
|
s_logger.warn("Network with id: " + networkId + " doesn't exist, or unable to acquire lock for it as a part of network shutdown");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Lock is acquired for network " + network + " as a part of network shutdown");
|
s_logger.debug("Lock is acquired for network " + network + " as a part of network shutdown");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (network.getState() == Network.State.Allocated) {
|
if (network.getState() == Network.State.Allocated) {
|
||||||
s_logger.debug("Network is already shutdown: " + network);
|
s_logger.debug(String.format("Network [%s] is in Allocated state, no need to shutdown.", network));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package org.apache.cloudstack.engine.orchestration;
|
package org.apache.cloudstack.engine.orchestration;
|
||||||
|
|
||||||
|
import static org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService.NetworkLockTimeout;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
@ -70,6 +71,7 @@ import com.cloud.network.guru.NetworkGuru;
|
|||||||
import com.cloud.network.vpc.VpcManager;
|
import com.cloud.network.vpc.VpcManager;
|
||||||
import com.cloud.network.vpc.VpcVO;
|
import com.cloud.network.vpc.VpcVO;
|
||||||
import com.cloud.offerings.NetworkOfferingVO;
|
import com.cloud.offerings.NetworkOfferingVO;
|
||||||
|
import com.cloud.utils.db.EntityManager;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.cloud.utils.net.Ip;
|
import com.cloud.utils.net.Ip;
|
||||||
import com.cloud.vm.DomainRouterVO;
|
import com.cloud.vm.DomainRouterVO;
|
||||||
@ -95,7 +97,7 @@ import junit.framework.TestCase;
|
|||||||
public class NetworkOrchestratorTest extends TestCase {
|
public class NetworkOrchestratorTest extends TestCase {
|
||||||
static final Logger s_logger = Logger.getLogger(NetworkOrchestratorTest.class);
|
static final Logger s_logger = Logger.getLogger(NetworkOrchestratorTest.class);
|
||||||
|
|
||||||
NetworkOrchestrator testOrchastrator = Mockito.spy(new NetworkOrchestrator());
|
NetworkOrchestrator testOrchestrator = Mockito.spy(new NetworkOrchestrator());
|
||||||
|
|
||||||
private String guruName = "GuestNetworkGuru";
|
private String guruName = "GuestNetworkGuru";
|
||||||
private String dhcpProvider = "VirtualRouter";
|
private String dhcpProvider = "VirtualRouter";
|
||||||
@ -114,21 +116,22 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
// make class-scope mocks
|
// make class-scope mocks
|
||||||
testOrchastrator._nicDao = mock(NicDao.class);
|
testOrchestrator._nicDao = mock(NicDao.class);
|
||||||
testOrchastrator._networksDao = mock(NetworkDao.class);
|
testOrchestrator._networksDao = mock(NetworkDao.class);
|
||||||
testOrchastrator._networkModel = mock(NetworkModel.class);
|
testOrchestrator._networkModel = mock(NetworkModel.class);
|
||||||
testOrchastrator._nicSecondaryIpDao = mock(NicSecondaryIpDao.class);
|
testOrchestrator._nicSecondaryIpDao = mock(NicSecondaryIpDao.class);
|
||||||
testOrchastrator._ntwkSrvcDao = mock(NetworkServiceMapDao.class);
|
testOrchestrator._ntwkSrvcDao = mock(NetworkServiceMapDao.class);
|
||||||
testOrchastrator._nicIpAliasDao = mock(NicIpAliasDao.class);
|
testOrchestrator._nicIpAliasDao = mock(NicIpAliasDao.class);
|
||||||
testOrchastrator._ipAddressDao = mock(IPAddressDao.class);
|
testOrchestrator._ipAddressDao = mock(IPAddressDao.class);
|
||||||
testOrchastrator._vlanDao = mock(VlanDao.class);
|
testOrchestrator._vlanDao = mock(VlanDao.class);
|
||||||
testOrchastrator._networkModel = mock(NetworkModel.class);
|
testOrchestrator._networkModel = mock(NetworkModel.class);
|
||||||
testOrchastrator._nicExtraDhcpOptionDao = mock(NicExtraDhcpOptionDao.class);
|
testOrchestrator._nicExtraDhcpOptionDao = mock(NicExtraDhcpOptionDao.class);
|
||||||
testOrchastrator.routerDao = mock(DomainRouterDao.class);
|
testOrchestrator.routerDao = mock(DomainRouterDao.class);
|
||||||
testOrchastrator.routerNetworkDao = mock(RouterNetworkDao.class);
|
testOrchestrator.routerNetworkDao = mock(RouterNetworkDao.class);
|
||||||
testOrchastrator._vpcMgr = mock(VpcManager.class);
|
testOrchestrator._vpcMgr = mock(VpcManager.class);
|
||||||
testOrchastrator.routerJoinDao = mock(DomainRouterJoinDao.class);
|
testOrchestrator.routerJoinDao = mock(DomainRouterJoinDao.class);
|
||||||
testOrchastrator._ipAddrMgr = mock(IpAddressManager.class);
|
testOrchestrator._ipAddrMgr = mock(IpAddressManager.class);
|
||||||
|
testOrchestrator._entityMgr = mock(EntityManager.class);
|
||||||
DhcpServiceProvider provider = mock(DhcpServiceProvider.class);
|
DhcpServiceProvider provider = mock(DhcpServiceProvider.class);
|
||||||
|
|
||||||
Map<Network.Capability, String> capabilities = new HashMap<Network.Capability, String>();
|
Map<Network.Capability, String> capabilities = new HashMap<Network.Capability, String>();
|
||||||
@ -137,13 +140,13 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
when(provider.getCapabilities()).thenReturn(services);
|
when(provider.getCapabilities()).thenReturn(services);
|
||||||
capabilities.put(Network.Capability.DhcpAccrossMultipleSubnets, "true");
|
capabilities.put(Network.Capability.DhcpAccrossMultipleSubnets, "true");
|
||||||
|
|
||||||
when(testOrchastrator._ntwkSrvcDao.getProviderForServiceInNetwork(Matchers.anyLong(), Matchers.eq(Service.Dhcp))).thenReturn(dhcpProvider);
|
when(testOrchestrator._ntwkSrvcDao.getProviderForServiceInNetwork(Matchers.anyLong(), Matchers.eq(Service.Dhcp))).thenReturn(dhcpProvider);
|
||||||
when(testOrchastrator._networkModel.getElementImplementingProvider(dhcpProvider)).thenReturn(provider);
|
when(testOrchestrator._networkModel.getElementImplementingProvider(dhcpProvider)).thenReturn(provider);
|
||||||
|
|
||||||
when(guru.getName()).thenReturn(guruName);
|
when(guru.getName()).thenReturn(guruName);
|
||||||
List<NetworkGuru> networkGurus = new ArrayList<NetworkGuru>();
|
List<NetworkGuru> networkGurus = new ArrayList<NetworkGuru>();
|
||||||
networkGurus.add(guru);
|
networkGurus.add(guru);
|
||||||
testOrchastrator.networkGurus = networkGurus;
|
testOrchestrator.networkGurus = networkGurus;
|
||||||
|
|
||||||
when(networkOffering.getGuestType()).thenReturn(GuestType.L2);
|
when(networkOffering.getGuestType()).thenReturn(GuestType.L2);
|
||||||
when(networkOffering.getId()).thenReturn(networkOfferingId);
|
when(networkOffering.getId()).thenReturn(networkOfferingId);
|
||||||
@ -158,21 +161,21 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
|
|
||||||
// make sure that release dhcp will be called
|
// make sure that release dhcp will be called
|
||||||
when(vm.getType()).thenReturn(Type.User);
|
when(vm.getType()).thenReturn(Type.User);
|
||||||
when(testOrchastrator._networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)).thenReturn(true);
|
when(testOrchestrator._networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)).thenReturn(true);
|
||||||
when(network.getTrafficType()).thenReturn(TrafficType.Guest);
|
when(network.getTrafficType()).thenReturn(TrafficType.Guest);
|
||||||
when(network.getGuestType()).thenReturn(GuestType.Shared);
|
when(network.getGuestType()).thenReturn(GuestType.Shared);
|
||||||
when(testOrchastrator._nicDao.listByNetworkIdTypeAndGatewayAndBroadcastUri(nic.getNetworkId(), VirtualMachine.Type.User, nic.getIPv4Gateway(), nic.getBroadcastUri()))
|
when(testOrchestrator._nicDao.listByNetworkIdTypeAndGatewayAndBroadcastUri(nic.getNetworkId(), VirtualMachine.Type.User, nic.getIPv4Gateway(), nic.getBroadcastUri()))
|
||||||
.thenReturn(new ArrayList<NicVO>());
|
.thenReturn(new ArrayList<NicVO>());
|
||||||
|
|
||||||
when(network.getGuruName()).thenReturn(guruName);
|
when(network.getGuruName()).thenReturn(guruName);
|
||||||
when(testOrchastrator._networksDao.findById(nic.getNetworkId())).thenReturn(network);
|
when(testOrchestrator._networksDao.findById(nic.getNetworkId())).thenReturn(network);
|
||||||
|
|
||||||
testOrchastrator.removeNic(vm, nic);
|
testOrchestrator.removeNic(vm, nic);
|
||||||
|
|
||||||
verify(nic, times(1)).setState(Nic.State.Deallocating);
|
verify(nic, times(1)).setState(Nic.State.Deallocating);
|
||||||
verify(testOrchastrator._networkModel, times(2)).getElementImplementingProvider(dhcpProvider);
|
verify(testOrchestrator._networkModel, times(2)).getElementImplementingProvider(dhcpProvider);
|
||||||
verify(testOrchastrator._ntwkSrvcDao, times(2)).getProviderForServiceInNetwork(network.getId(), Service.Dhcp);
|
verify(testOrchestrator._ntwkSrvcDao, times(2)).getProviderForServiceInNetwork(network.getId(), Service.Dhcp);
|
||||||
verify(testOrchastrator._networksDao, times(2)).findById(nic.getNetworkId());
|
verify(testOrchestrator._networksDao, times(2)).findById(nic.getNetworkId());
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testDontRemoveDhcpServiceFromDomainRouter() {
|
public void testDontRemoveDhcpServiceFromDomainRouter() {
|
||||||
@ -185,14 +188,14 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
when(vm.getType()).thenReturn(Type.DomainRouter);
|
when(vm.getType()).thenReturn(Type.DomainRouter);
|
||||||
|
|
||||||
when(network.getGuruName()).thenReturn(guruName);
|
when(network.getGuruName()).thenReturn(guruName);
|
||||||
when(testOrchastrator._networksDao.findById(nic.getNetworkId())).thenReturn(network);
|
when(testOrchestrator._networksDao.findById(nic.getNetworkId())).thenReturn(network);
|
||||||
|
|
||||||
testOrchastrator.removeNic(vm, nic);
|
testOrchestrator.removeNic(vm, nic);
|
||||||
|
|
||||||
verify(nic, times(1)).setState(Nic.State.Deallocating);
|
verify(nic, times(1)).setState(Nic.State.Deallocating);
|
||||||
verify(testOrchastrator._networkModel, never()).getElementImplementingProvider(dhcpProvider);
|
verify(testOrchestrator._networkModel, never()).getElementImplementingProvider(dhcpProvider);
|
||||||
verify(testOrchastrator._ntwkSrvcDao, never()).getProviderForServiceInNetwork(network.getId(), Service.Dhcp);
|
verify(testOrchestrator._ntwkSrvcDao, never()).getProviderForServiceInNetwork(network.getId(), Service.Dhcp);
|
||||||
verify(testOrchastrator._networksDao, times(1)).findById(nic.getNetworkId());
|
verify(testOrchestrator._networksDao, times(1)).findById(nic.getNetworkId());
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testDontRemoveDhcpServiceWhenNotProvided() {
|
public void testDontRemoveDhcpServiceWhenNotProvided() {
|
||||||
@ -203,45 +206,45 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
|
|
||||||
// make sure that release dhcp will *not* be called
|
// make sure that release dhcp will *not* be called
|
||||||
when(vm.getType()).thenReturn(Type.User);
|
when(vm.getType()).thenReturn(Type.User);
|
||||||
when(testOrchastrator._networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)).thenReturn(false);
|
when(testOrchestrator._networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)).thenReturn(false);
|
||||||
|
|
||||||
when(network.getGuruName()).thenReturn(guruName);
|
when(network.getGuruName()).thenReturn(guruName);
|
||||||
when(testOrchastrator._networksDao.findById(nic.getNetworkId())).thenReturn(network);
|
when(testOrchestrator._networksDao.findById(nic.getNetworkId())).thenReturn(network);
|
||||||
|
|
||||||
testOrchastrator.removeNic(vm, nic);
|
testOrchestrator.removeNic(vm, nic);
|
||||||
|
|
||||||
verify(nic, times(1)).setState(Nic.State.Deallocating);
|
verify(nic, times(1)).setState(Nic.State.Deallocating);
|
||||||
verify(testOrchastrator._networkModel, never()).getElementImplementingProvider(dhcpProvider);
|
verify(testOrchestrator._networkModel, never()).getElementImplementingProvider(dhcpProvider);
|
||||||
verify(testOrchastrator._ntwkSrvcDao, never()).getProviderForServiceInNetwork(network.getId(), Service.Dhcp);
|
verify(testOrchestrator._ntwkSrvcDao, never()).getProviderForServiceInNetwork(network.getId(), Service.Dhcp);
|
||||||
verify(testOrchastrator._networksDao, times(1)).findById(nic.getNetworkId());
|
verify(testOrchestrator._networksDao, times(1)).findById(nic.getNetworkId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckL2OfferingServicesEmptyServices() {
|
public void testCheckL2OfferingServicesEmptyServices() {
|
||||||
when(testOrchastrator._networkModel.listNetworkOfferingServices(networkOfferingId)).thenReturn(new ArrayList<>());
|
when(testOrchestrator._networkModel.listNetworkOfferingServices(networkOfferingId)).thenReturn(new ArrayList<>());
|
||||||
when(testOrchastrator._networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.UserData)).thenReturn(false);
|
when(testOrchestrator._networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.UserData)).thenReturn(false);
|
||||||
testOrchastrator.checkL2OfferingServices(networkOffering);
|
testOrchestrator.checkL2OfferingServices(networkOffering);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckL2OfferingServicesUserDataOnly() {
|
public void testCheckL2OfferingServicesUserDataOnly() {
|
||||||
when(testOrchastrator._networkModel.listNetworkOfferingServices(networkOfferingId)).thenReturn(Arrays.asList(Service.UserData));
|
when(testOrchestrator._networkModel.listNetworkOfferingServices(networkOfferingId)).thenReturn(Arrays.asList(Service.UserData));
|
||||||
when(testOrchastrator._networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.UserData)).thenReturn(true);
|
when(testOrchestrator._networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.UserData)).thenReturn(true);
|
||||||
testOrchastrator.checkL2OfferingServices(networkOffering);
|
testOrchestrator.checkL2OfferingServices(networkOffering);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = InvalidParameterValueException.class)
|
@Test(expected = InvalidParameterValueException.class)
|
||||||
public void testCheckL2OfferingServicesMultipleServicesIncludingUserData() {
|
public void testCheckL2OfferingServicesMultipleServicesIncludingUserData() {
|
||||||
when(testOrchastrator._networkModel.listNetworkOfferingServices(networkOfferingId)).thenReturn(Arrays.asList(Service.UserData, Service.Dhcp));
|
when(testOrchestrator._networkModel.listNetworkOfferingServices(networkOfferingId)).thenReturn(Arrays.asList(Service.UserData, Service.Dhcp));
|
||||||
when(testOrchastrator._networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.UserData)).thenReturn(true);
|
when(testOrchestrator._networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.UserData)).thenReturn(true);
|
||||||
testOrchastrator.checkL2OfferingServices(networkOffering);
|
testOrchestrator.checkL2OfferingServices(networkOffering);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = InvalidParameterValueException.class)
|
@Test(expected = InvalidParameterValueException.class)
|
||||||
public void testCheckL2OfferingServicesMultipleServicesNotIncludingUserData() {
|
public void testCheckL2OfferingServicesMultipleServicesNotIncludingUserData() {
|
||||||
when(testOrchastrator._networkModel.listNetworkOfferingServices(networkOfferingId)).thenReturn(Arrays.asList(Service.Dns, Service.Dhcp));
|
when(testOrchestrator._networkModel.listNetworkOfferingServices(networkOfferingId)).thenReturn(Arrays.asList(Service.Dns, Service.Dhcp));
|
||||||
when(testOrchastrator._networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.UserData)).thenReturn(false);
|
when(testOrchestrator._networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.UserData)).thenReturn(false);
|
||||||
testOrchastrator.checkL2OfferingServices(networkOffering);
|
testOrchestrator.checkL2OfferingServices(networkOffering);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -253,7 +256,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 0l, false, IPAddressVO.State.Free, "192.168.100.1", "255.255.255.0", "00-88-14-4D-4C-FB",
|
configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 0l, false, IPAddressVO.State.Free, "192.168.100.1", "255.255.255.0", "00-88-14-4D-4C-FB",
|
||||||
requestedNicProfile, null, "192.168.100.150");
|
requestedNicProfile, null, "192.168.100.150");
|
||||||
|
|
||||||
testOrchastrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, nicProfile, network);
|
testOrchestrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, nicProfile, network);
|
||||||
|
|
||||||
verifyAndAssert("192.168.100.150", "192.168.100.1", "255.255.255.0", nicProfile, 1, 1);
|
verifyAndAssert("192.168.100.150", "192.168.100.1", "255.255.255.0", nicProfile, 1, 1);
|
||||||
}
|
}
|
||||||
@ -267,7 +270,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 0l, false, IPAddressVO.State.Free, "192.168.100.1", "255.255.255.0", "00-88-14-4D-4C-FB",
|
configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 0l, false, IPAddressVO.State.Free, "192.168.100.1", "255.255.255.0", "00-88-14-4D-4C-FB",
|
||||||
requestedNicProfile, "00-88-14-4D-4C-FB", "192.168.100.150");
|
requestedNicProfile, "00-88-14-4D-4C-FB", "192.168.100.150");
|
||||||
|
|
||||||
testOrchastrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, nicProfile, network);
|
testOrchestrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, nicProfile, network);
|
||||||
|
|
||||||
verifyAndAssert("192.168.100.150", "192.168.100.1", "255.255.255.0", nicProfile, 1, 0);
|
verifyAndAssert("192.168.100.150", "192.168.100.1", "255.255.255.0", nicProfile, 1, 0);
|
||||||
}
|
}
|
||||||
@ -294,7 +297,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
|
|
||||||
configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 0l, false, IPAddressVO.State.Free, "192.168.100.1", "255.255.255.0", "00-88-14-4D-4C-FB",
|
configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 0l, false, IPAddressVO.State.Free, "192.168.100.1", "255.255.255.0", "00-88-14-4D-4C-FB",
|
||||||
requestedNicProfile, null, requestedIpv4Address);
|
requestedNicProfile, null, requestedIpv4Address);
|
||||||
testOrchastrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, nicProfile, network);
|
testOrchestrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, nicProfile, network);
|
||||||
|
|
||||||
verifyAndAssert(null, null, null, nicProfile, 0, 0);
|
verifyAndAssert(null, null, null, nicProfile, 0, 0);
|
||||||
}
|
}
|
||||||
@ -321,7 +324,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
|
|
||||||
configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 0l, false, IPAddressVO.State.Free, ipv4Gateway, "255.255.255.0", "00-88-14-4D-4C-FB",
|
configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 0l, false, IPAddressVO.State.Free, ipv4Gateway, "255.255.255.0", "00-88-14-4D-4C-FB",
|
||||||
requestedNicProfile, "00-88-14-4D-4C-FB", "192.168.100.150");
|
requestedNicProfile, "00-88-14-4D-4C-FB", "192.168.100.150");
|
||||||
testOrchastrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, nicProfile, network);
|
testOrchestrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, nicProfile, network);
|
||||||
verifyAndAssert(null, null, null, nicProfile, 1, 0);
|
verifyAndAssert(null, null, null, nicProfile, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,7 +350,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
|
|
||||||
configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 0l, false, IPAddressVO.State.Free, "192.168.100.1", ipv4Netmask, "00-88-14-4D-4C-FB",
|
configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 0l, false, IPAddressVO.State.Free, "192.168.100.1", ipv4Netmask, "00-88-14-4D-4C-FB",
|
||||||
requestedNicProfile, "00-88-14-4D-4C-FB", "192.168.100.150");
|
requestedNicProfile, "00-88-14-4D-4C-FB", "192.168.100.150");
|
||||||
testOrchastrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, nicProfile, network);
|
testOrchestrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, nicProfile, network);
|
||||||
verifyAndAssert(null, null, null, nicProfile, 1, 0);
|
verifyAndAssert(null, null, null, nicProfile, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,9 +362,9 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
|
|
||||||
configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 0l, false, IPAddressVO.State.Free, "192.168.100.1", "255.255.255.0", "00-88-14-4D-4C-FB",
|
configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 0l, false, IPAddressVO.State.Free, "192.168.100.1", "255.255.255.0", "00-88-14-4D-4C-FB",
|
||||||
requestedNicProfile, "00-88-14-4D-4C-FB", "192.168.100.150");
|
requestedNicProfile, "00-88-14-4D-4C-FB", "192.168.100.150");
|
||||||
when(testOrchastrator._vlanDao.findByNetworkIdAndIpv4(Mockito.anyLong(), Mockito.anyString())).thenReturn(null);
|
when(testOrchestrator._vlanDao.findByNetworkIdAndIpv4(Mockito.anyLong(), Mockito.anyString())).thenReturn(null);
|
||||||
|
|
||||||
testOrchastrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, nicProfile, network);
|
testOrchestrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, nicProfile, network);
|
||||||
verifyAndAssert(null, null, null, nicProfile, 0, 0);
|
verifyAndAssert(null, null, null, nicProfile, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,21 +380,21 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
when(ipVoSpy.getState()).thenReturn(state);
|
when(ipVoSpy.getState()).thenReturn(state);
|
||||||
|
|
||||||
if (ipVoIsNull) {
|
if (ipVoIsNull) {
|
||||||
when(testOrchastrator._ipAddressDao.findByIpAndSourceNetworkId(Mockito.anyLong(), Mockito.anyString())).thenReturn(ipVoSpy);
|
when(testOrchestrator._ipAddressDao.findByIpAndSourceNetworkId(Mockito.anyLong(), Mockito.anyString())).thenReturn(ipVoSpy);
|
||||||
} else {
|
} else {
|
||||||
when(testOrchastrator._ipAddressDao.findByIpAndSourceNetworkId(Mockito.anyLong(), Mockito.anyString())).thenReturn(ipVoSpy);
|
when(testOrchestrator._ipAddressDao.findByIpAndSourceNetworkId(Mockito.anyLong(), Mockito.anyString())).thenReturn(ipVoSpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
VlanVO vlanSpy = Mockito.spy(new VlanVO(Vlan.VlanType.DirectAttached, "vlanTag", vlanGateway, vlanNetmask, 0l, "192.168.100.100 - 192.168.100.200", 0l, new Long(0l),
|
VlanVO vlanSpy = Mockito.spy(new VlanVO(Vlan.VlanType.DirectAttached, "vlanTag", vlanGateway, vlanNetmask, 0l, "192.168.100.100 - 192.168.100.200", 0l, new Long(0l),
|
||||||
"ip6Gateway", "ip6Cidr", "ip6Range"));
|
"ip6Gateway", "ip6Cidr", "ip6Range"));
|
||||||
|
|
||||||
Mockito.doReturn(0l).when(vlanSpy).getId();
|
Mockito.doReturn(0l).when(vlanSpy).getId();
|
||||||
when(testOrchastrator._vlanDao.findByNetworkIdAndIpv4(Mockito.anyLong(), Mockito.anyString())).thenReturn(vlanSpy);
|
when(testOrchestrator._vlanDao.findByNetworkIdAndIpv4(Mockito.anyLong(), Mockito.anyString())).thenReturn(vlanSpy);
|
||||||
when(testOrchastrator._ipAddressDao.acquireInLockTable(Mockito.anyLong())).thenReturn(ipVoSpy);
|
when(testOrchestrator._ipAddressDao.acquireInLockTable(Mockito.anyLong())).thenReturn(ipVoSpy);
|
||||||
when(testOrchastrator._ipAddressDao.update(Mockito.anyLong(), Mockito.any(IPAddressVO.class))).thenReturn(true);
|
when(testOrchestrator._ipAddressDao.update(Mockito.anyLong(), Mockito.any(IPAddressVO.class))).thenReturn(true);
|
||||||
when(testOrchastrator._ipAddressDao.releaseFromLockTable(Mockito.anyLong())).thenReturn(true);
|
when(testOrchestrator._ipAddressDao.releaseFromLockTable(Mockito.anyLong())).thenReturn(true);
|
||||||
try {
|
try {
|
||||||
when(testOrchastrator._networkModel.getNextAvailableMacAddressInNetwork(Mockito.anyLong())).thenReturn(macAddress);
|
when(testOrchestrator._networkModel.getNextAvailableMacAddressInNetwork(Mockito.anyLong())).thenReturn(macAddress);
|
||||||
} catch (InsufficientAddressCapacityException e) {
|
} catch (InsufficientAddressCapacityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -399,9 +402,9 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
|
|
||||||
private void verifyAndAssert(String requestedIpv4Address, String ipv4Gateway, String ipv4Netmask, NicProfile nicProfile, int acquireLockAndCheckIfIpv4IsFreeTimes,
|
private void verifyAndAssert(String requestedIpv4Address, String ipv4Gateway, String ipv4Netmask, NicProfile nicProfile, int acquireLockAndCheckIfIpv4IsFreeTimes,
|
||||||
int nextMacAddressTimes) {
|
int nextMacAddressTimes) {
|
||||||
verify(testOrchastrator, times(acquireLockAndCheckIfIpv4IsFreeTimes)).acquireLockAndCheckIfIpv4IsFree(Mockito.any(Network.class), Mockito.anyString());
|
verify(testOrchestrator, times(acquireLockAndCheckIfIpv4IsFreeTimes)).acquireLockAndCheckIfIpv4IsFree(Mockito.any(Network.class), Mockito.anyString());
|
||||||
try {
|
try {
|
||||||
verify(testOrchastrator._networkModel, times(nextMacAddressTimes)).getNextAvailableMacAddressInNetwork(Mockito.anyLong());
|
verify(testOrchestrator._networkModel, times(nextMacAddressTimes)).getNextAvailableMacAddressInNetwork(Mockito.anyLong());
|
||||||
} catch (InsufficientAddressCapacityException e) {
|
} catch (InsufficientAddressCapacityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -443,27 +446,27 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
ipVoSpy.setState(state);
|
ipVoSpy.setState(state);
|
||||||
ipVoSpy.setState(state);
|
ipVoSpy.setState(state);
|
||||||
if (isIPAddressVONull) {
|
if (isIPAddressVONull) {
|
||||||
when(testOrchastrator._ipAddressDao.findByIpAndSourceNetworkId(Mockito.anyLong(), Mockito.anyString())).thenReturn(null);
|
when(testOrchestrator._ipAddressDao.findByIpAndSourceNetworkId(Mockito.anyLong(), Mockito.anyString())).thenReturn(null);
|
||||||
} else {
|
} else {
|
||||||
when(testOrchastrator._ipAddressDao.findByIpAndSourceNetworkId(Mockito.anyLong(), Mockito.anyString())).thenReturn(ipVoSpy);
|
when(testOrchestrator._ipAddressDao.findByIpAndSourceNetworkId(Mockito.anyLong(), Mockito.anyString())).thenReturn(ipVoSpy);
|
||||||
}
|
}
|
||||||
when(testOrchastrator._ipAddressDao.acquireInLockTable(Mockito.anyLong())).thenReturn(ipVoSpy);
|
when(testOrchestrator._ipAddressDao.acquireInLockTable(Mockito.anyLong())).thenReturn(ipVoSpy);
|
||||||
when(testOrchastrator._ipAddressDao.releaseFromLockTable(Mockito.anyLong())).thenReturn(true);
|
when(testOrchestrator._ipAddressDao.releaseFromLockTable(Mockito.anyLong())).thenReturn(true);
|
||||||
when(testOrchastrator._ipAddressDao.update(Mockito.anyLong(), Mockito.any(IPAddressVO.class))).thenReturn(true);
|
when(testOrchestrator._ipAddressDao.update(Mockito.anyLong(), Mockito.any(IPAddressVO.class))).thenReturn(true);
|
||||||
|
|
||||||
testOrchastrator.acquireLockAndCheckIfIpv4IsFree(network, "192.168.100.150");
|
testOrchestrator.acquireLockAndCheckIfIpv4IsFree(network, "192.168.100.150");
|
||||||
|
|
||||||
verify(testOrchastrator._ipAddressDao, Mockito.times(findByIpTimes)).findByIpAndSourceNetworkId(Mockito.anyLong(), Mockito.anyString());
|
verify(testOrchestrator._ipAddressDao, Mockito.times(findByIpTimes)).findByIpAndSourceNetworkId(Mockito.anyLong(), Mockito.anyString());
|
||||||
verify(testOrchastrator._ipAddressDao, Mockito.times(acquireLockTimes)).acquireInLockTable(Mockito.anyLong());
|
verify(testOrchestrator._ipAddressDao, Mockito.times(acquireLockTimes)).acquireInLockTable(Mockito.anyLong());
|
||||||
verify(testOrchastrator._ipAddressDao, Mockito.times(releaseFromLockTimes)).releaseFromLockTable(Mockito.anyLong());
|
verify(testOrchestrator._ipAddressDao, Mockito.times(releaseFromLockTimes)).releaseFromLockTable(Mockito.anyLong());
|
||||||
verify(testOrchastrator._ipAddressDao, Mockito.times(updateTimes)).update(Mockito.anyLong(), Mockito.any(IPAddressVO.class));
|
verify(testOrchestrator._ipAddressDao, Mockito.times(updateTimes)).update(Mockito.anyLong(), Mockito.any(IPAddressVO.class));
|
||||||
verify(testOrchastrator, Mockito.times(validateTimes)).validateLockedRequestedIp(Mockito.any(IPAddressVO.class), Mockito.any(IPAddressVO.class));
|
verify(testOrchestrator, Mockito.times(validateTimes)).validateLockedRequestedIp(Mockito.any(IPAddressVO.class), Mockito.any(IPAddressVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = InvalidParameterValueException.class)
|
@Test(expected = InvalidParameterValueException.class)
|
||||||
public void validateLockedRequestedIpTestNullLockedIp() {
|
public void validateLockedRequestedIpTestNullLockedIp() {
|
||||||
IPAddressVO ipVoSpy = Mockito.spy(new IPAddressVO(new Ip("192.168.100.100"), 0l, 0l, 0l, true));
|
IPAddressVO ipVoSpy = Mockito.spy(new IPAddressVO(new Ip("192.168.100.100"), 0l, 0l, 0l, true));
|
||||||
testOrchastrator.validateLockedRequestedIp(ipVoSpy, null);
|
testOrchestrator.validateLockedRequestedIp(ipVoSpy, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -478,7 +481,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
IPAddressVO lockedIp = ipVoSpy;
|
IPAddressVO lockedIp = ipVoSpy;
|
||||||
lockedIp.setState(states[i]);
|
lockedIp.setState(states[i]);
|
||||||
try {
|
try {
|
||||||
testOrchastrator.validateLockedRequestedIp(ipVoSpy, lockedIp);
|
testOrchestrator.validateLockedRequestedIp(ipVoSpy, lockedIp);
|
||||||
} catch (InvalidParameterValueException e) {
|
} catch (InvalidParameterValueException e) {
|
||||||
expectedException = true;
|
expectedException = true;
|
||||||
}
|
}
|
||||||
@ -491,7 +494,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
IPAddressVO ipVoSpy = Mockito.spy(new IPAddressVO(new Ip("192.168.100.100"), 0l, 0l, 0l, true));
|
IPAddressVO ipVoSpy = Mockito.spy(new IPAddressVO(new Ip("192.168.100.100"), 0l, 0l, 0l, true));
|
||||||
IPAddressVO lockedIp = ipVoSpy;
|
IPAddressVO lockedIp = ipVoSpy;
|
||||||
lockedIp.setState(State.Free);
|
lockedIp.setState(State.Free);
|
||||||
testOrchastrator.validateLockedRequestedIp(ipVoSpy, lockedIp);
|
testOrchestrator.validateLockedRequestedIp(ipVoSpy, lockedIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -502,16 +505,16 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
|
|
||||||
when(vm.getType()).thenReturn(Type.User);
|
when(vm.getType()).thenReturn(Type.User);
|
||||||
when(network.getGuruName()).thenReturn(guruName);
|
when(network.getGuruName()).thenReturn(guruName);
|
||||||
when(testOrchastrator._networksDao.findById(nic.getNetworkId())).thenReturn(network);
|
when(testOrchestrator._networksDao.findById(nic.getNetworkId())).thenReturn(network);
|
||||||
|
|
||||||
Long nicId = 1L;
|
Long nicId = 1L;
|
||||||
when(nic.getId()).thenReturn(nicId);
|
when(nic.getId()).thenReturn(nicId);
|
||||||
when(vm.getParameter(VirtualMachineProfile.Param.PreserveNics)).thenReturn(true);
|
when(vm.getParameter(VirtualMachineProfile.Param.PreserveNics)).thenReturn(true);
|
||||||
|
|
||||||
testOrchastrator.removeNic(vm, nic);
|
testOrchestrator.removeNic(vm, nic);
|
||||||
|
|
||||||
verify(nic, never()).setState(Nic.State.Deallocating);
|
verify(nic, never()).setState(Nic.State.Deallocating);
|
||||||
verify(testOrchastrator._nicDao, never()).remove(nicId);
|
verify(testOrchestrator._nicDao, never()).remove(nicId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encodeVlanIdIntoBroadcastUriTestVxlan() {
|
public void encodeVlanIdIntoBroadcastUriTestVxlan() {
|
||||||
@ -570,7 +573,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
|
|
||||||
@Test(expected = InvalidParameterValueException.class)
|
@Test(expected = InvalidParameterValueException.class)
|
||||||
public void encodeVlanIdIntoBroadcastUriTestNullNetwork() {
|
public void encodeVlanIdIntoBroadcastUriTestNullNetwork() {
|
||||||
URI resultUri = testOrchastrator.encodeVlanIdIntoBroadcastUri("vxlan://123", null);
|
URI resultUri = testOrchestrator.encodeVlanIdIntoBroadcastUri("vxlan://123", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void encodeVlanIdIntoBroadcastUriPrepareAndTest(String vlanId, String isolationMethod, String expectedIsolation, String expectedUri) {
|
private void encodeVlanIdIntoBroadcastUriPrepareAndTest(String vlanId, String isolationMethod, String expectedIsolation, String expectedUri) {
|
||||||
@ -579,7 +582,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
isolationMethods.add(isolationMethod);
|
isolationMethods.add(isolationMethod);
|
||||||
physicalNetwork.setIsolationMethods(isolationMethods);
|
physicalNetwork.setIsolationMethods(isolationMethods);
|
||||||
|
|
||||||
URI resultUri = testOrchastrator.encodeVlanIdIntoBroadcastUri(vlanId, physicalNetwork);
|
URI resultUri = testOrchestrator.encodeVlanIdIntoBroadcastUri(vlanId, physicalNetwork);
|
||||||
|
|
||||||
Assert.assertEquals(expectedIsolation, resultUri.getScheme());
|
Assert.assertEquals(expectedIsolation, resultUri.getScheme());
|
||||||
Assert.assertEquals(expectedUri, resultUri.toString());
|
Assert.assertEquals(expectedUri, resultUri.toString());
|
||||||
@ -597,17 +600,17 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
Mockito.when(network.getDns2()).thenReturn(ip4Dns[1]);
|
Mockito.when(network.getDns2()).thenReturn(ip4Dns[1]);
|
||||||
Mockito.when(network.getIp6Dns1()).thenReturn(ip6Dns[0]);
|
Mockito.when(network.getIp6Dns1()).thenReturn(ip6Dns[0]);
|
||||||
Mockito.when(network.getIp6Dns2()).thenReturn(ip6Dns[1]);
|
Mockito.when(network.getIp6Dns2()).thenReturn(ip6Dns[1]);
|
||||||
Mockito.when(testOrchastrator._networkModel.getNetworkRate(networkId, vmId)).thenReturn(networkRate);
|
Mockito.when(testOrchestrator._networkModel.getNetworkRate(networkId, vmId)).thenReturn(networkRate);
|
||||||
NicVO nicVO = Mockito.mock(NicVO.class);
|
NicVO nicVO = Mockito.mock(NicVO.class);
|
||||||
Mockito.when(nicVO.isDefaultNic()).thenReturn(isDefaultNic);
|
Mockito.when(nicVO.isDefaultNic()).thenReturn(isDefaultNic);
|
||||||
Mockito.when(testOrchastrator._nicDao.findById(nicId)).thenReturn(nicVO);
|
Mockito.when(testOrchestrator._nicDao.findById(nicId)).thenReturn(nicVO);
|
||||||
Mockito.when(testOrchastrator._nicDao.update(nicId, nicVO)).thenReturn(true);
|
Mockito.when(testOrchestrator._nicDao.update(nicId, nicVO)).thenReturn(true);
|
||||||
Mockito.when(testOrchastrator._networkModel.isSecurityGroupSupportedInNetwork(network)).thenReturn(false);
|
Mockito.when(testOrchestrator._networkModel.isSecurityGroupSupportedInNetwork(network)).thenReturn(false);
|
||||||
Mockito.when(testOrchastrator._networkModel.getNetworkTag(hypervisorType, network)).thenReturn(null);
|
Mockito.when(testOrchestrator._networkModel.getNetworkTag(hypervisorType, network)).thenReturn(null);
|
||||||
Mockito.when(testOrchastrator._ntwkSrvcDao.getDistinctProviders(networkId)).thenReturn(new ArrayList<>());
|
Mockito.when(testOrchestrator._ntwkSrvcDao.getDistinctProviders(networkId)).thenReturn(new ArrayList<>());
|
||||||
testOrchastrator.networkElements = new ArrayList<>();
|
testOrchestrator.networkElements = new ArrayList<>();
|
||||||
Mockito.when(testOrchastrator._nicExtraDhcpOptionDao.listByNicId(nicId)).thenReturn(new ArrayList<>());
|
Mockito.when(testOrchestrator._nicExtraDhcpOptionDao.listByNicId(nicId)).thenReturn(new ArrayList<>());
|
||||||
Mockito.when(testOrchastrator._ntwkSrvcDao.areServicesSupportedInNetwork(networkId, Service.Dhcp)).thenReturn(false);
|
Mockito.when(testOrchestrator._ntwkSrvcDao.areServicesSupportedInNetwork(networkId, Service.Dhcp)).thenReturn(false);
|
||||||
VirtualMachineProfile virtualMachineProfile = Mockito.mock(VirtualMachineProfile.class);
|
VirtualMachineProfile virtualMachineProfile = Mockito.mock(VirtualMachineProfile.class);
|
||||||
Mockito.when(virtualMachineProfile.getType()).thenReturn(vmType);
|
Mockito.when(virtualMachineProfile.getType()).thenReturn(vmType);
|
||||||
Mockito.when(virtualMachineProfile.getId()).thenReturn(vmId);
|
Mockito.when(virtualMachineProfile.getId()).thenReturn(vmId);
|
||||||
@ -636,7 +639,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
Mockito.when(vpcVO.getIp4Dns1()).thenReturn(null);
|
Mockito.when(vpcVO.getIp4Dns1()).thenReturn(null);
|
||||||
Mockito.when(vpcVO.getIp6Dns1()).thenReturn(null);
|
Mockito.when(vpcVO.getIp6Dns1()).thenReturn(null);
|
||||||
}
|
}
|
||||||
Mockito.when(testOrchastrator._vpcMgr.getActiveVpc(vpcId)).thenReturn(vpcVO);
|
Mockito.when(testOrchestrator._vpcMgr.getActiveVpc(vpcId)).thenReturn(vpcVO);
|
||||||
} else {
|
} else {
|
||||||
Mockito.when(routerVO.getVpcId()).thenReturn(null);
|
Mockito.when(routerVO.getVpcId()).thenReturn(null);
|
||||||
Long routerNetworkId = 2L;
|
Long routerNetworkId = 2L;
|
||||||
@ -650,13 +653,13 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
Mockito.when(routerNetworkVO.getDns1()).thenReturn(null);
|
Mockito.when(routerNetworkVO.getDns1()).thenReturn(null);
|
||||||
Mockito.when(routerNetworkVO.getIp6Dns1()).thenReturn(null);
|
Mockito.when(routerNetworkVO.getIp6Dns1()).thenReturn(null);
|
||||||
}
|
}
|
||||||
Mockito.when(testOrchastrator.routerNetworkDao.getRouterNetworks(vmId)).thenReturn(List.of(routerNetworkId));
|
Mockito.when(testOrchestrator.routerNetworkDao.getRouterNetworks(vmId)).thenReturn(List.of(routerNetworkId));
|
||||||
Mockito.when(testOrchastrator._networksDao.findById(routerNetworkId)).thenReturn(routerNetworkVO);
|
Mockito.when(testOrchestrator._networksDao.findById(routerNetworkId)).thenReturn(routerNetworkVO);
|
||||||
}
|
}
|
||||||
Mockito.when(testOrchastrator.routerDao.findById(vmId)).thenReturn(routerVO);
|
Mockito.when(testOrchestrator.routerDao.findById(vmId)).thenReturn(routerVO);
|
||||||
NicProfile profile = null;
|
NicProfile profile = null;
|
||||||
try {
|
try {
|
||||||
profile = testOrchastrator.prepareNic(virtualMachineProfile, deployDestination, reservationContext, nicId, network);
|
profile = testOrchestrator.prepareNic(virtualMachineProfile, deployDestination, reservationContext, nicId, network);
|
||||||
} catch (InsufficientCapacityException | ResourceUnavailableException e) {
|
} catch (InsufficientCapacityException | ResourceUnavailableException e) {
|
||||||
Assert.fail(String.format("Failure with exception %s", e.getMessage()));
|
Assert.fail(String.format("Failure with exception %s", e.getMessage()));
|
||||||
}
|
}
|
||||||
@ -725,7 +728,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
Mockito.when(dataCenter.getNetworkType()).thenReturn(DataCenter.NetworkType.Advanced);
|
Mockito.when(dataCenter.getNetworkType()).thenReturn(DataCenter.NetworkType.Advanced);
|
||||||
Mockito.when(network.getGateway()).thenReturn(networkGateway);
|
Mockito.when(network.getGateway()).thenReturn(networkGateway);
|
||||||
Mockito.when(network.getCidr()).thenReturn(networkCidr);
|
Mockito.when(network.getCidr()).thenReturn(networkCidr);
|
||||||
Pair<String, String> pair = testOrchastrator.getNetworkGatewayAndNetmaskForNicImport(network, dataCenter, ipAddress);
|
Pair<String, String> pair = testOrchestrator.getNetworkGatewayAndNetmaskForNicImport(network, dataCenter, ipAddress);
|
||||||
Assert.assertNotNull(pair);
|
Assert.assertNotNull(pair);
|
||||||
Assert.assertEquals(networkGateway, pair.first());
|
Assert.assertEquals(networkGateway, pair.first());
|
||||||
Assert.assertEquals(networkNetmask, pair.second());
|
Assert.assertEquals(networkNetmask, pair.second());
|
||||||
@ -745,9 +748,9 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
Mockito.when(vlan.getVlanNetmask()).thenReturn(defaultNetworkNetmask);
|
Mockito.when(vlan.getVlanNetmask()).thenReturn(defaultNetworkNetmask);
|
||||||
Mockito.when(dataCenter.getNetworkType()).thenReturn(DataCenter.NetworkType.Basic);
|
Mockito.when(dataCenter.getNetworkType()).thenReturn(DataCenter.NetworkType.Basic);
|
||||||
Mockito.when(ipAddressVO.getVlanId()).thenReturn(1L);
|
Mockito.when(ipAddressVO.getVlanId()).thenReturn(1L);
|
||||||
Mockito.when(testOrchastrator._vlanDao.findById(1L)).thenReturn(vlan);
|
Mockito.when(testOrchestrator._vlanDao.findById(1L)).thenReturn(vlan);
|
||||||
Mockito.when(testOrchastrator._ipAddressDao.findByIp(ipAddress)).thenReturn(ipAddressVO);
|
Mockito.when(testOrchestrator._ipAddressDao.findByIp(ipAddress)).thenReturn(ipAddressVO);
|
||||||
Pair<String, String> pair = testOrchastrator.getNetworkGatewayAndNetmaskForNicImport(network, dataCenter, ipAddress);
|
Pair<String, String> pair = testOrchestrator.getNetworkGatewayAndNetmaskForNicImport(network, dataCenter, ipAddress);
|
||||||
Assert.assertNotNull(pair);
|
Assert.assertNotNull(pair);
|
||||||
Assert.assertEquals(defaultNetworkGateway, pair.first());
|
Assert.assertEquals(defaultNetworkGateway, pair.first());
|
||||||
Assert.assertEquals(defaultNetworkNetmask, pair.second());
|
Assert.assertEquals(defaultNetworkNetmask, pair.second());
|
||||||
@ -759,7 +762,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
DataCenter dataCenter = Mockito.mock(DataCenter.class);
|
DataCenter dataCenter = Mockito.mock(DataCenter.class);
|
||||||
Network.IpAddresses ipAddresses = Mockito.mock(Network.IpAddresses.class);
|
Network.IpAddresses ipAddresses = Mockito.mock(Network.IpAddresses.class);
|
||||||
Mockito.when(network.getGuestType()).thenReturn(GuestType.L2);
|
Mockito.when(network.getGuestType()).thenReturn(GuestType.L2);
|
||||||
Assert.assertNull(testOrchastrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses));
|
Assert.assertNull(testOrchestrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -771,8 +774,8 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
Mockito.when(dataCenter.getNetworkType()).thenReturn(DataCenter.NetworkType.Advanced);
|
Mockito.when(dataCenter.getNetworkType()).thenReturn(DataCenter.NetworkType.Advanced);
|
||||||
String ipAddress = "10.1.10.10";
|
String ipAddress = "10.1.10.10";
|
||||||
Mockito.when(ipAddresses.getIp4Address()).thenReturn(ipAddress);
|
Mockito.when(ipAddresses.getIp4Address()).thenReturn(ipAddress);
|
||||||
Mockito.when(testOrchastrator._ipAddrMgr.acquireGuestIpAddress(network, ipAddress)).thenReturn(ipAddress);
|
Mockito.when(testOrchestrator._ipAddrMgr.acquireGuestIpAddress(network, ipAddress)).thenReturn(ipAddress);
|
||||||
String guestIp = testOrchastrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses);
|
String guestIp = testOrchestrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses);
|
||||||
Assert.assertEquals(ipAddress, guestIp);
|
Assert.assertEquals(ipAddress, guestIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -793,8 +796,8 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
Mockito.when(ipAddressVO.getState()).thenReturn(State.Free);
|
Mockito.when(ipAddressVO.getState()).thenReturn(State.Free);
|
||||||
Mockito.when(network.getId()).thenReturn(networkId);
|
Mockito.when(network.getId()).thenReturn(networkId);
|
||||||
Mockito.when(dataCenter.getId()).thenReturn(dataCenterId);
|
Mockito.when(dataCenter.getId()).thenReturn(dataCenterId);
|
||||||
Mockito.when(testOrchastrator._ipAddressDao.findBySourceNetworkIdAndDatacenterIdAndState(networkId, dataCenterId, State.Free)).thenReturn(ipAddressVO);
|
Mockito.when(testOrchestrator._ipAddressDao.findBySourceNetworkIdAndDatacenterIdAndState(networkId, dataCenterId, State.Free)).thenReturn(ipAddressVO);
|
||||||
String ipAddress = testOrchastrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses);
|
String ipAddress = testOrchestrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses);
|
||||||
Assert.assertEquals(freeIp, ipAddress);
|
Assert.assertEquals(freeIp, ipAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -816,8 +819,8 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
Mockito.when(network.getId()).thenReturn(networkId);
|
Mockito.when(network.getId()).thenReturn(networkId);
|
||||||
Mockito.when(dataCenter.getId()).thenReturn(dataCenterId);
|
Mockito.when(dataCenter.getId()).thenReturn(dataCenterId);
|
||||||
Mockito.when(ipAddresses.getIp4Address()).thenReturn(requestedIp);
|
Mockito.when(ipAddresses.getIp4Address()).thenReturn(requestedIp);
|
||||||
Mockito.when(testOrchastrator._ipAddressDao.findByIp(requestedIp)).thenReturn(ipAddressVO);
|
Mockito.when(testOrchestrator._ipAddressDao.findByIp(requestedIp)).thenReturn(ipAddressVO);
|
||||||
String ipAddress = testOrchastrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses);
|
String ipAddress = testOrchestrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses);
|
||||||
Assert.assertEquals(requestedIp, ipAddress);
|
Assert.assertEquals(requestedIp, ipAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -839,7 +842,54 @@ public class NetworkOrchestratorTest extends TestCase {
|
|||||||
Mockito.when(network.getId()).thenReturn(networkId);
|
Mockito.when(network.getId()).thenReturn(networkId);
|
||||||
Mockito.when(dataCenter.getId()).thenReturn(dataCenterId);
|
Mockito.when(dataCenter.getId()).thenReturn(dataCenterId);
|
||||||
Mockito.when(ipAddresses.getIp4Address()).thenReturn(requestedIp);
|
Mockito.when(ipAddresses.getIp4Address()).thenReturn(requestedIp);
|
||||||
Mockito.when(testOrchastrator._ipAddressDao.findByIp(requestedIp)).thenReturn(ipAddressVO);
|
Mockito.when(testOrchestrator._ipAddressDao.findByIp(requestedIp)).thenReturn(ipAddressVO);
|
||||||
testOrchastrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses);
|
testOrchestrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShutdownNetworkAcquireLockFailed() {
|
||||||
|
ReservationContext reservationContext = Mockito.mock(ReservationContext.class);
|
||||||
|
NetworkVO network = mock(NetworkVO.class);
|
||||||
|
long networkId = 1;
|
||||||
|
when(testOrchestrator._networksDao.acquireInLockTable(Mockito.anyLong(), Mockito.anyInt())).thenReturn(null);
|
||||||
|
|
||||||
|
boolean shutdownNetworkStatus = testOrchestrator.shutdownNetwork(networkId, reservationContext, false);
|
||||||
|
Assert.assertFalse(shutdownNetworkStatus);
|
||||||
|
|
||||||
|
verify(testOrchestrator._networksDao, times(1)).acquireInLockTable(networkId, NetworkLockTimeout.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShutdownNetworkInAllocatedState() {
|
||||||
|
ReservationContext reservationContext = Mockito.mock(ReservationContext.class);
|
||||||
|
NetworkVO network = mock(NetworkVO.class);
|
||||||
|
long networkId = 1;
|
||||||
|
when(testOrchestrator._networksDao.acquireInLockTable(Mockito.anyLong(), Mockito.anyInt())).thenReturn(network);
|
||||||
|
when(network.getId()).thenReturn(networkId);
|
||||||
|
when(network.getState()).thenReturn(Network.State.Allocated);
|
||||||
|
|
||||||
|
boolean shutdownNetworkStatus = testOrchestrator.shutdownNetwork(networkId, reservationContext, false);
|
||||||
|
Assert.assertTrue(shutdownNetworkStatus);
|
||||||
|
|
||||||
|
verify(network, times(1)).getState();
|
||||||
|
verify(testOrchestrator._networksDao, times(1)).acquireInLockTable(networkId, NetworkLockTimeout.value());
|
||||||
|
verify(testOrchestrator._networksDao, times(1)).releaseFromLockTable(networkId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShutdownNetworkInImplementingState() {
|
||||||
|
ReservationContext reservationContext = Mockito.mock(ReservationContext.class);
|
||||||
|
NetworkVO network = mock(NetworkVO.class);
|
||||||
|
long networkId = 1;
|
||||||
|
when(testOrchestrator._networksDao.acquireInLockTable(Mockito.anyLong(), Mockito.anyInt())).thenReturn(network);
|
||||||
|
when(network.getId()).thenReturn(networkId);
|
||||||
|
when(network.getState()).thenReturn(Network.State.Implementing);
|
||||||
|
|
||||||
|
boolean shutdownNetworkStatus = testOrchestrator.shutdownNetwork(networkId, reservationContext, false);
|
||||||
|
Assert.assertFalse(shutdownNetworkStatus);
|
||||||
|
|
||||||
|
verify(network, times(3)).getState();
|
||||||
|
verify(testOrchestrator._networksDao, times(1)).acquireInLockTable(networkId, NetworkLockTimeout.value());
|
||||||
|
verify(testOrchestrator._networksDao, times(1)).releaseFromLockTable(networkId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user