mirror of https://github.com/apache/cloudstack.git
InternalLB: unittests for InternalLoadBalancerVMManager
This commit is contained in:
parent
63babe4b7e
commit
440e8484d6
|
|
@ -183,7 +183,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
|
|||
return false;
|
||||
}
|
||||
|
||||
if ((internalLbVms == null) || (internalLbVms.size() == 0)) {
|
||||
if (internalLbVms == null || internalLbVms.isEmpty()) {
|
||||
throw new ResourceUnavailableException("Can't deploy " + this.getName() + " to handle LB rules",
|
||||
DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
|
@ -220,7 +220,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
|
|||
return false;
|
||||
}
|
||||
|
||||
if ((internalLbVms == null) || (internalLbVms.size() == 0)) {
|
||||
if (internalLbVms == null || internalLbVms.isEmpty()) {
|
||||
throw new ResourceUnavailableException("Can't deploy " + this.getName() + " to handle LB rules",
|
||||
DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
|
@ -365,7 +365,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
|
|||
return false;
|
||||
}
|
||||
|
||||
if ((internalLbVms == null) || (internalLbVms.size() == 0)) {
|
||||
if (internalLbVms == null || internalLbVms.isEmpty()) {
|
||||
throw new ResourceUnavailableException("Can't find/deploy internal lb vm to handle LB rules",
|
||||
DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -483,7 +483,7 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
}
|
||||
|
||||
Network guestNetwork = _ntwkModel.getNetwork(guestNetworkId);
|
||||
Nic guestNic = _nicDao.findByInstanceIdAndNetworkId(guestNetwork.getId(), internalLbVm.getId());
|
||||
Nic guestNic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), internalLbVm.getId());
|
||||
NicProfile guestNicProfile = new NicProfile(guestNic, guestNetwork, guestNic.getBroadcastUri(), guestNic.getIsolationUri(),
|
||||
_ntwkModel.getNetworkRate(guestNetwork.getId(), internalLbVm.getId()),
|
||||
_ntwkModel.isSecurityGroupSupportedInNetwork(guestNetwork),
|
||||
|
|
@ -573,7 +573,7 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
@Override
|
||||
public List<DomainRouterVO> deployInternalLbVm(Network guestNetwork, Ip requestedGuestIp, DeployDestination dest,
|
||||
Account owner, Map<Param, Object> params) throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
|
||||
List<DomainRouterVO> internalLbVms = findOrDeployInternalLbVm(guestNetwork, requestedGuestIp, dest, owner, params);
|
||||
|
||||
|
|
@ -586,6 +586,9 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
|
||||
if (internalLbVms != null) {
|
||||
runningInternalLbVms = new ArrayList<DomainRouterVO>();
|
||||
} else {
|
||||
s_logger.debug("Have no internal lb vms to start");
|
||||
return null;
|
||||
}
|
||||
|
||||
for (DomainRouterVO internalLbVm : internalLbVms) {
|
||||
|
|
@ -607,7 +610,7 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
Account owner, Map<Param, Object> params) throws ConcurrentOperationException,
|
||||
InsufficientCapacityException, ResourceUnavailableException {
|
||||
|
||||
List<DomainRouterVO> internalLbs = new ArrayList<DomainRouterVO>();
|
||||
List<DomainRouterVO> internalLbVms = new ArrayList<DomainRouterVO>();
|
||||
Network lock = _networkDao.acquireInLockTable(guestNetwork.getId(), _ntwkMgr.getNetworkLockTimeout());
|
||||
if (lock == null) {
|
||||
throw new ConcurrentOperationException("Unable to lock network " + guestNetwork.getId());
|
||||
|
|
@ -617,17 +620,7 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
s_logger.debug("Lock is acquired for network id " + lock.getId() + " as a part of internal lb startup in " + dest);
|
||||
}
|
||||
|
||||
// Check if providers are supported in the physical networks
|
||||
VirtualRouterProviderType type = VirtualRouterProviderType.InternalLbVm;
|
||||
Long physicalNetworkId = _ntwkModel.getPhysicalNetworkId(guestNetwork);
|
||||
PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, type.toString());
|
||||
if (provider == null) {
|
||||
throw new CloudRuntimeException("Cannot find service provider " + type.toString() + " in physical network " + physicalNetworkId);
|
||||
}
|
||||
VirtualRouterProvider internalLbProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), type);
|
||||
if (internalLbProvider == null) {
|
||||
throw new CloudRuntimeException("Cannot find provider " + type.toString() + " as service provider " + provider.getId());
|
||||
}
|
||||
long internalLbProviderId = getInternalLbProviderId(guestNetwork);
|
||||
|
||||
try {
|
||||
assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup ||
|
||||
|
|
@ -635,23 +628,23 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
+ guestNetwork;
|
||||
assert guestNetwork.getTrafficType() == TrafficType.Guest;
|
||||
|
||||
// 3) deploy internal lb vm
|
||||
//deploy internal lb vm
|
||||
Pair<DeploymentPlan, List<DomainRouterVO>> planAndInternalLbVms = getDeploymentPlanAndInternalLbVms(dest, guestNetwork.getId(), requestedGuestIp);
|
||||
internalLbs = planAndInternalLbVms.second();
|
||||
internalLbVms = planAndInternalLbVms.second();
|
||||
DeploymentPlan plan = planAndInternalLbVms.first();
|
||||
|
||||
if (internalLbs.size() > 0) {
|
||||
s_logger.debug("Found " + internalLbs.size() + " internal lb vms for the requested IP " + requestedGuestIp.addr());
|
||||
return internalLbs;
|
||||
if (internalLbVms.size() > 0) {
|
||||
s_logger.debug("Found " + internalLbVms.size() + " internal lb vms for the requested IP " + requestedGuestIp.addr());
|
||||
return internalLbVms;
|
||||
}
|
||||
|
||||
List<Pair<NetworkVO, NicProfile>> networks = createInternalLbVmNetworks(guestNetwork, plan, requestedGuestIp);
|
||||
//don't start the internal lb as we are holding the network lock that needs to be released at the end of router allocation
|
||||
DomainRouterVO internalLbVm = deployInternalLbVm(owner, dest, plan, params, internalLbProvider, _internalLbVmOfferingId, guestNetwork.getVpcId(),
|
||||
//Pass startVm=false as we are holding the network lock that needs to be released at the end of vm allocation
|
||||
DomainRouterVO internalLbVm = deployInternalLbVm(owner, dest, plan, params, internalLbProviderId, _internalLbVmOfferingId, guestNetwork.getVpcId(),
|
||||
networks, false);
|
||||
if (internalLbVm != null) {
|
||||
_internalLbVmDao.addRouterToGuestNetwork(internalLbVm, guestNetwork);
|
||||
internalLbs.add(internalLbVm);
|
||||
internalLbVms.add(internalLbVm);
|
||||
}
|
||||
} finally {
|
||||
if (lock != null) {
|
||||
|
|
@ -661,7 +654,24 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
}
|
||||
}
|
||||
}
|
||||
return internalLbs;
|
||||
return internalLbVms;
|
||||
}
|
||||
|
||||
protected long getInternalLbProviderId(Network guestNetwork) {
|
||||
VirtualRouterProviderType type = VirtualRouterProviderType.InternalLbVm;
|
||||
long physicalNetworkId = _ntwkModel.getPhysicalNetworkId(guestNetwork);
|
||||
|
||||
PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, type.toString());
|
||||
if (provider == null) {
|
||||
throw new CloudRuntimeException("Cannot find service provider " + type.toString() + " in physical network " + physicalNetworkId);
|
||||
}
|
||||
|
||||
VirtualRouterProvider internalLbProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), type);
|
||||
if (internalLbProvider == null) {
|
||||
throw new CloudRuntimeException("Cannot find provider " + type.toString() + " as service provider " + provider.getId());
|
||||
}
|
||||
|
||||
return internalLbProvider.getId();
|
||||
}
|
||||
|
||||
protected List<Pair<NetworkVO, NicProfile>> createInternalLbVmNetworks(Network guestNetwork, DeploymentPlan plan, Ip guestIp) throws ConcurrentOperationException,
|
||||
|
|
@ -712,12 +722,12 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
|
||||
@Override
|
||||
public List<DomainRouterVO> findInternalLbVms(long guestNetworkId, Ip requestedGuestIp) {
|
||||
List<DomainRouterVO> internalLbVms = _internalLbVmDao.listByNetworkAndRole(guestNetworkId, Role.INTERNAL_LB_VM);
|
||||
if (requestedGuestIp != null) {
|
||||
List<DomainRouterVO> internalLbVms = _internalLbVmDao.listByNetworkAndRole(guestNetworkId, Role.INTERNAL_LB_VM);
|
||||
if (requestedGuestIp != null && !internalLbVms.isEmpty()) {
|
||||
Iterator<DomainRouterVO> it = internalLbVms.iterator();
|
||||
while (it.hasNext()) {
|
||||
DomainRouterVO vm = it.next();
|
||||
Nic nic = _nicDao.findByInstanceIdAndNetworkId(guestNetworkId, vm.getId());
|
||||
Nic nic = _nicDao.findByNtwkIdAndInstanceId(guestNetworkId, vm.getId());
|
||||
if (!nic.getIp4Address().equalsIgnoreCase(requestedGuestIp.addr())) {
|
||||
it.remove();
|
||||
}
|
||||
|
|
@ -728,7 +738,7 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
|
||||
|
||||
protected DomainRouterVO deployInternalLbVm(Account owner, DeployDestination dest, DeploymentPlan plan, Map<Param, Object> params,
|
||||
VirtualRouterProvider internalLbProvider, long svcOffId, Long vpcId,
|
||||
long internalLbProviderId, long svcOffId, Long vpcId,
|
||||
List<Pair<NetworkVO, NicProfile>> networks, boolean startVm) throws ConcurrentOperationException,
|
||||
InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException,
|
||||
StorageUnavailableException, ResourceUnavailableException {
|
||||
|
|
@ -758,7 +768,7 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
continue;
|
||||
}
|
||||
|
||||
internalLbVm = new DomainRouterVO(id, routerOffering.getId(), internalLbProvider.getId(),
|
||||
internalLbVm = new DomainRouterVO(id, routerOffering.getId(), internalLbProviderId,
|
||||
VirtualMachineName.getSystemVmName(id, _instance, _internalLbVmNamePrefix), template.getId(), template.getHypervisorType(),
|
||||
template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false,
|
||||
RedundantState.UNKNOWN, false, false, VirtualMachine.Type.InternalLoadBalancerVm, vpcId);
|
||||
|
|
@ -849,17 +859,21 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean applyLoadBalancingRules(Network network, final List<LoadBalancingRule> rules, List<? extends VirtualRouter> internalLbVms) throws ResourceUnavailableException {
|
||||
public boolean applyLoadBalancingRules(Network network, final List<LoadBalancingRule> rules, List<? extends VirtualRouter> internalLbVms)
|
||||
throws ResourceUnavailableException {
|
||||
if (rules == null || rules.isEmpty()) {
|
||||
s_logger.debug("No lb rules to be applied for network " + network);
|
||||
return true;
|
||||
}
|
||||
|
||||
//only one internal lb vm is supported per ip address at this time
|
||||
if (internalLbVms == null || internalLbVms.isEmpty()) {
|
||||
throw new CloudRuntimeException("Can't apply the lb rules on network " + network + " as the list of internal lb vms is empty");
|
||||
}
|
||||
|
||||
VirtualRouter lbVm = internalLbVms.get(0);
|
||||
if (lbVm.getState() == State.Running) {
|
||||
return sendLBRules(lbVm, rules, network.getId());
|
||||
|
||||
} else if (lbVm.getState() == State.Stopped || lbVm.getState() == State.Stopping) {
|
||||
s_logger.debug("Internal LB VM " + lbVm.getInstanceName() + " is in " + lbVm.getState() +
|
||||
", so not sending apply lb rules commands to the backend");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,388 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.internallbvm;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRuleVO;
|
||||
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.NetworkModel;
|
||||
import com.cloud.network.dao.NetworkVO;
|
||||
import com.cloud.network.lb.LoadBalancingRule;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.Ip;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VirtualMachineManager;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
|
||||
/**
|
||||
* Set of unittests for InternalLoadBalancerVMManager
|
||||
*
|
||||
*/
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="classpath:/lb_mgr.xml")
|
||||
public class InternalLBVMManagerTest extends TestCase {
|
||||
//The interface to test
|
||||
@Inject InternalLoadBalancerVMManager _lbVmMgr;
|
||||
|
||||
//Mocked interfaces
|
||||
@Inject AccountManager _accountMgr;
|
||||
@Inject ServiceOfferingDao _svcOffDao;
|
||||
@Inject DomainRouterDao _domainRouterDao;
|
||||
@Inject NicDao _nicDao;
|
||||
@Inject AgentManager _agentMgr;
|
||||
@Inject NetworkModel _ntwkModel;
|
||||
@Inject VirtualMachineManager _itMgr;
|
||||
@Inject DataCenterDao _dcDao;
|
||||
|
||||
long validNtwkId = 1L;
|
||||
long invalidNtwkId = 2L;
|
||||
String requestedIp = "10.1.1.1";
|
||||
DomainRouterVO vm = null;
|
||||
NetworkVO ntwk = createNetwork();
|
||||
long validVmId = 1L;
|
||||
long invalidVmId = 2L;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
//mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
|
||||
Mockito.when(_accountMgr.getAccount(1L)).thenReturn(new AccountVO());
|
||||
ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1,
|
||||
1, 1, 1, false, "alena", false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
|
||||
off = setId(off, 1);
|
||||
Mockito.when(_svcOffDao.persistSystemServiceOffering(Mockito.any(ServiceOfferingVO.class))).thenReturn(off);
|
||||
|
||||
ComponentContext.initComponentsLifeCycle();
|
||||
|
||||
vm = new DomainRouterVO(1L,off.getId(),1,"alena",1,HypervisorType.XenServer,1,1,1,
|
||||
false, 0,false,null,false,false,
|
||||
VirtualMachine.Type.InternalLoadBalancerVm, null);
|
||||
vm.setRole(Role.INTERNAL_LB_VM);
|
||||
vm = setId(vm, 1);
|
||||
vm.setPrivateIpAddress("10.2.2.2");
|
||||
NicVO nic = new NicVO("somereserver", 1L, 1L, VirtualMachine.Type.InternalLoadBalancerVm);
|
||||
nic.setIp4Address(requestedIp);
|
||||
|
||||
List<DomainRouterVO> emptyList = new ArrayList<DomainRouterVO>();
|
||||
List<DomainRouterVO> nonEmptyList = new ArrayList<DomainRouterVO>();
|
||||
nonEmptyList.add(vm);
|
||||
|
||||
Mockito.when(_domainRouterDao.listByNetworkAndRole(invalidNtwkId, Role.INTERNAL_LB_VM)).thenReturn(emptyList);
|
||||
Mockito.when(_domainRouterDao.listByNetworkAndRole(validNtwkId, Role.INTERNAL_LB_VM)).thenReturn(nonEmptyList);
|
||||
|
||||
Mockito.when(_nicDao.findByNtwkIdAndInstanceId(validNtwkId, 1)).thenReturn(nic);
|
||||
Mockito.when(_nicDao.findByNtwkIdAndInstanceId(invalidNtwkId, 1)).thenReturn(nic);
|
||||
|
||||
Answer answer= new Answer(null, true, null);
|
||||
Answer[] answers = new Answer[1];
|
||||
answers[0] = answer;
|
||||
|
||||
try {
|
||||
Mockito.when(_agentMgr.send(Mockito.anyLong(), Mockito.any(Commands.class))).thenReturn(answers);
|
||||
} catch (AgentUnavailableException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (OperationTimedoutException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
createNetwork();
|
||||
Mockito.when(_ntwkModel.getNetwork(Mockito.anyLong())).thenReturn(ntwk);
|
||||
|
||||
|
||||
Mockito.when(_itMgr.toNicTO(Mockito.any(NicProfile.class), Mockito.any(HypervisorType.class))).thenReturn(null);
|
||||
Mockito.when(_domainRouterDao.findById(Mockito.anyLong())).thenReturn(vm);
|
||||
DataCenterVO dc = new DataCenterVO
|
||||
(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null);
|
||||
Mockito.when(_dcDao.findById(Mockito.anyLong())).thenReturn(dc);
|
||||
|
||||
|
||||
try {
|
||||
Mockito.when(_itMgr.expunge(Mockito.any(DomainRouterVO.class), Mockito.any(User.class), Mockito.any(Account.class))).thenReturn(true);
|
||||
} catch (ResourceUnavailableException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(vm);
|
||||
Mockito.when(_domainRouterDao.findById(invalidVmId)).thenReturn(null);
|
||||
|
||||
}
|
||||
|
||||
protected NetworkVO createNetwork() {
|
||||
ntwk = new NetworkVO();
|
||||
try {
|
||||
ntwk.setBroadcastUri(new URI("somevlan"));
|
||||
} catch (URISyntaxException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
ntwk = setId(ntwk, 1L);
|
||||
return ntwk;
|
||||
}
|
||||
|
||||
//TESTS FOR findInternalLbVms METHOD
|
||||
|
||||
@Test
|
||||
public void findInternalLbVmsForInvalidNetwork() {
|
||||
List<? extends VirtualRouter> vms = _lbVmMgr.findInternalLbVms(invalidNtwkId, new Ip(requestedIp));
|
||||
assertTrue("Non empty vm list was returned for invalid network id", vms.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findInternalLbVmsForValidNetwork() {
|
||||
List<? extends VirtualRouter> vms = _lbVmMgr.findInternalLbVms(validNtwkId, new Ip(requestedIp));
|
||||
assertTrue("Empty vm list was returned for valid network id", !vms.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
//TESTS FOR applyLoadBalancingRules METHOD
|
||||
@Test
|
||||
public void applyEmptyRulesSet() {
|
||||
boolean result = false;
|
||||
List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
|
||||
try {
|
||||
result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), new ArrayList<LoadBalancingRule>(), vms);
|
||||
} catch (ResourceUnavailableException e) {
|
||||
|
||||
} finally {
|
||||
assertTrue("Got failure when tried to apply empty list of rules", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Test (expected = CloudRuntimeException.class)
|
||||
public void applyWithEmptyVmsSet() {
|
||||
boolean result = false;
|
||||
List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
|
||||
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
|
||||
LoadBalancingRule rule = new LoadBalancingRule(null, null,
|
||||
null, null, null);
|
||||
|
||||
rules.add(rule);
|
||||
try {
|
||||
result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
|
||||
} catch (ResourceUnavailableException e) {
|
||||
} finally {
|
||||
assertFalse("Got success when tried to apply with the empty internal lb vm list", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Test (expected = ResourceUnavailableException.class)
|
||||
public void applyToVmInStartingState() throws ResourceUnavailableException {
|
||||
boolean result = false;
|
||||
List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
|
||||
vm.setState(State.Starting);
|
||||
vms.add(vm);
|
||||
|
||||
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
|
||||
LoadBalancingRule rule = new LoadBalancingRule(null, null,
|
||||
null, null, null);
|
||||
|
||||
rules.add(rule);
|
||||
try {
|
||||
result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
|
||||
} finally {
|
||||
assertFalse("Rules were applied to vm in Starting state", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void applyToVmInStoppedState() throws ResourceUnavailableException {
|
||||
boolean result = false;
|
||||
List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
|
||||
vm.setState(State.Stopped);
|
||||
vms.add(vm);
|
||||
|
||||
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
|
||||
LoadBalancingRule rule = new LoadBalancingRule(null, null,
|
||||
null, null, null);
|
||||
|
||||
rules.add(rule);
|
||||
try {
|
||||
result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
|
||||
} finally {
|
||||
assertTrue("Rules failed to apply to vm in Stopped state", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void applyToVmInStoppingState() throws ResourceUnavailableException {
|
||||
boolean result = false;
|
||||
List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
|
||||
vm.setState(State.Stopping);
|
||||
vms.add(vm);
|
||||
|
||||
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
|
||||
LoadBalancingRule rule = new LoadBalancingRule(null, null,
|
||||
null, null, null);
|
||||
|
||||
rules.add(rule);
|
||||
try {
|
||||
result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
|
||||
} finally {
|
||||
assertTrue("Rules failed to apply to vm in Stopping state", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void applyToVmInRunningState() throws ResourceUnavailableException {
|
||||
boolean result = false;
|
||||
List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
|
||||
vm.setState(State.Running);
|
||||
vms.add(vm);
|
||||
|
||||
List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
|
||||
ApplicationLoadBalancerRuleVO lb = new ApplicationLoadBalancerRuleVO(null, null, 22, 22, "roundrobin",
|
||||
1L, 1L, 1L, new Ip(requestedIp), 1L, Scheme.Internal);
|
||||
lb.setState(FirewallRule.State.Add);
|
||||
|
||||
LoadBalancingRule rule = new LoadBalancingRule(lb, null,
|
||||
null, null, new Ip(requestedIp));
|
||||
|
||||
rules.add(rule);
|
||||
|
||||
ntwk.getId();
|
||||
|
||||
try {
|
||||
result = _lbVmMgr.applyLoadBalancingRules(ntwk, rules, vms);
|
||||
} finally {
|
||||
assertTrue("Rules failed to apply to vm in Running state", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TESTS FOR destroyInternalLbVm METHOD
|
||||
@Test
|
||||
public void destroyNonExistingVM() throws ResourceUnavailableException, ConcurrentOperationException {
|
||||
boolean result = false;
|
||||
|
||||
try {
|
||||
result = _lbVmMgr.destroyInternalLbVm(invalidVmId, new AccountVO(), 1L);
|
||||
} finally {
|
||||
assertTrue("Failed to destroy non-existing vm", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyExistingVM() throws ResourceUnavailableException, ConcurrentOperationException {
|
||||
boolean result = false;
|
||||
|
||||
try {
|
||||
result = _lbVmMgr.destroyInternalLbVm(validVmId, new AccountVO(), 1L);
|
||||
} finally {
|
||||
assertTrue("Failed to destroy valid vm", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static ServiceOfferingVO setId(ServiceOfferingVO vo, long id) {
|
||||
ServiceOfferingVO voToReturn = vo;
|
||||
Class<?> c = voToReturn.getClass();
|
||||
try {
|
||||
Field f = c.getSuperclass().getDeclaredField("id");
|
||||
f.setAccessible(true);
|
||||
f.setLong(voToReturn, id);
|
||||
} catch (NoSuchFieldException ex) {
|
||||
return null;
|
||||
} catch (IllegalAccessException ex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return voToReturn;
|
||||
}
|
||||
|
||||
|
||||
private static NetworkVO setId(NetworkVO vo, long id) {
|
||||
NetworkVO voToReturn = vo;
|
||||
Class<?> c = voToReturn.getClass();
|
||||
try {
|
||||
Field f = c.getDeclaredField("id");
|
||||
f.setAccessible(true);
|
||||
f.setLong(voToReturn, id);
|
||||
} catch (NoSuchFieldException ex) {
|
||||
return null;
|
||||
} catch (IllegalAccessException ex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return voToReturn;
|
||||
}
|
||||
|
||||
private static DomainRouterVO setId(DomainRouterVO vo, long id) {
|
||||
DomainRouterVO voToReturn = vo;
|
||||
Class<?> c = voToReturn.getClass();
|
||||
try {
|
||||
Field f = c.getSuperclass().getDeclaredField("id");
|
||||
f.setAccessible(true);
|
||||
f.setLong(voToReturn, id);
|
||||
} catch (NoSuchFieldException ex) {
|
||||
return null;
|
||||
} catch (IllegalAccessException ex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return voToReturn;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
|
||||
license agreements. See the NOTICE file distributed with this work for additional
|
||||
information regarding copyright ownership. The ASF licenses this file to
|
||||
you under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of
|
||||
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
|
||||
by applicable law or agreed to in writing, software distributed under the
|
||||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
|
||||
OF ANY KIND, either express or implied. See the License for the specific
|
||||
language governing permissions and limitations under the License. -->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/tx
|
||||
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<context:annotation-config />
|
||||
|
||||
<!-- @DB support -->
|
||||
|
||||
<bean id="componentContext" class="com.cloud.utils.component.ComponentContext" />
|
||||
|
||||
<bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
|
||||
<bean id="actionEventInterceptor" class="com.cloud.event.ActionEventInterceptor" />
|
||||
<bean id="instantiatePostProcessor" class="com.cloud.utils.component.ComponentInstantiationPostProcessor">
|
||||
<property name="Interceptors">
|
||||
<list>
|
||||
<ref bean="transactionContextBuilder" />
|
||||
<ref bean="actionEventInterceptor" />
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="InternalLoadBalancerVMManager" class="org.apache.cloudstack.network.lb.InternalLoadBalancerVMManagerImpl">
|
||||
<property name="name" value="InternalLoadBalancerVMManager"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.apache.cloudstack.internallbvm.LbChildTestConfiguration" />
|
||||
|
||||
</beans>
|
||||
|
|
@ -3626,7 +3626,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
|||
}
|
||||
}
|
||||
} else {
|
||||
NicVO nicVO = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId());
|
||||
NicVO nicVO = _nicDao.findByNtwkIdAndInstanceId(network.getId(), vm.getId());
|
||||
if (nicVO != null) {
|
||||
nic = _networkModel.getNicProfile(vm, network.getId(), null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -919,7 +919,7 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
|
|||
boolean isUserVmsDefaultNetwork = false;
|
||||
boolean isDomRGuestOrPublicNetwork = false;
|
||||
if (vm != null) {
|
||||
Nic nic = _nicDao.findByInstanceIdAndNetworkId(networkId, vmId);
|
||||
Nic nic = _nicDao.findByNtwkIdAndInstanceId(networkId, vmId);
|
||||
if (vm.getType() == Type.User && nic != null && nic.isDefaultNic()) {
|
||||
isUserVmsDefaultNetwork = true;
|
||||
} else if (vm.getType() == Type.DomainRouter && ntwkOff != null && (ntwkOff.getTrafficType() == TrafficType.Public || ntwkOff.getTrafficType() == TrafficType.Guest)) {
|
||||
|
|
@ -1807,7 +1807,7 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
|
|||
if (broadcastUri != null) {
|
||||
nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(networkId, vm.getId(), broadcastUri);
|
||||
} else {
|
||||
nic = _nicDao.findByInstanceIdAndNetworkId(networkId, vm.getId());
|
||||
nic = _nicDao.findByNtwkIdAndInstanceId(networkId, vm.getId());
|
||||
}
|
||||
if (nic == null) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -32,9 +32,6 @@ import javax.persistence.Transient;
|
|||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Networks;
|
||||
import com.cloud.network.Network.GuestType;
|
||||
import com.cloud.network.Network.State;
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.Mode;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
|
|
|
|||
|
|
@ -3035,7 +3035,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
}
|
||||
|
||||
Network guestNetwork = _networkModel.getNetwork(guestNetworkId);
|
||||
Nic nic = _nicDao.findByInstanceIdAndNetworkId(guestNetwork.getId(), router.getId());
|
||||
Nic nic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), router.getId());
|
||||
NicProfile nicProfile = new NicProfile(nic, guestNetwork, nic.getBroadcastUri(), nic.getIsolationUri(),
|
||||
_networkModel.getNetworkRate(guestNetwork.getId(), router.getId()),
|
||||
_networkModel.isSecurityGroupSupportedInNetwork(guestNetwork),
|
||||
|
|
@ -3128,7 +3128,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
}
|
||||
|
||||
if (createVmData) {
|
||||
NicVO nic = _nicDao.findByInstanceIdAndNetworkId(guestNetworkId, vm.getId());
|
||||
NicVO nic = _nicDao.findByNtwkIdAndInstanceId(guestNetworkId, vm.getId());
|
||||
if (nic != null) {
|
||||
s_logger.debug("Creating user data entry for vm " + vm + " on domR " + router);
|
||||
createVmDataCommand(router, vm, nic, null, cmds);
|
||||
|
|
@ -3181,7 +3181,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
createDhcp = false;
|
||||
}
|
||||
if (createDhcp) {
|
||||
NicVO nic = _nicDao.findByInstanceIdAndNetworkId(guestNetworkId, vm.getId());
|
||||
NicVO nic = _nicDao.findByNtwkIdAndInstanceId(guestNetworkId, vm.getId());
|
||||
if (nic != null) {
|
||||
s_logger.debug("Creating dhcp entry for vm " + vm + " on domR " + router + ".");
|
||||
createDhcpEntryCommand(router, vm, nic, cmds);
|
||||
|
|
|
|||
|
|
@ -440,7 +440,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
defaultDns2 = guestNic.getDns2();
|
||||
}
|
||||
|
||||
Nic nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), router.getId());
|
||||
Nic nic = _nicDao.findByNtwkIdAndInstanceId(network.getId(), router.getId());
|
||||
String networkDomain = network.getNetworkDomain();
|
||||
String dhcpRange = getGuestDhcpRange(guestNic, network, _configMgr.getZone(network.getDataCenterId()));
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public interface NicDao extends GenericDao<NicVO, Long> {
|
|||
|
||||
List<NicVO> listByNetworkId(long networkId);
|
||||
|
||||
NicVO findByInstanceIdAndNetworkId(long networkId, long instanceId);
|
||||
NicVO findByNtwkIdAndInstanceId(long networkId, long instanceId);
|
||||
|
||||
NicVO findByInstanceIdAndNetworkIdIncludingRemoved(long networkId, long instanceId);
|
||||
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NicVO findByInstanceIdAndNetworkId(long networkId, long instanceId) {
|
||||
public NicVO findByNtwkIdAndInstanceId(long networkId, long instanceId) {
|
||||
SearchCriteria<NicVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("network", networkId);
|
||||
sc.setParameters("instance", instanceId);
|
||||
|
|
|
|||
|
|
@ -22,12 +22,10 @@ import javax.persistence.DiscriminatorValue;
|
|||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.cloud.network.rules.FirewallRuleVO;
|
||||
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
|
||||
import com.cloud.utils.net.Ip;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue