Search in sources :

Example 1 with LoadBalancerVMMapDao

use of com.cloud.network.dao.LoadBalancerVMMapDao in project cosmic by MissionCriticalCloud.

the class AssignLoadBalancerTest method testNicIsNotInNw.

@Test(expected = InvalidParameterValueException.class)
public void testNicIsNotInNw() throws ResourceAllocationException, ResourceUnavailableException, InsufficientCapacityException {
    final Map<Long, List<String>> vmIdIpMap = new HashMap<>();
    final List<String> secIp = new ArrayList<>();
    secIp.add("10.1.1.175");
    vmIdIpMap.put(1L, secIp);
    final List<Long> vmIds = new ArrayList<>();
    vmIds.add(2L);
    final LoadBalancerDao lbDao = Mockito.mock(LoadBalancerDao.class);
    final LoadBalancerVMMapDao lb2VmMapDao = Mockito.mock(LoadBalancerVMMapDao.class);
    final UserVmDao userVmDao = Mockito.mock(UserVmDao.class);
    _lbMgr._lbDao = lbDao;
    _lbMgr._lb2VmMapDao = lb2VmMapDao;
    _lbMgr._vmDao = userVmDao;
    _lbvmMapList = new ArrayList<>();
    _lbMgr._rulesMgr = _rulesMgr;
    _lbMgr._networkModel = _networkModel;
    when(lbDao.findById(anyLong())).thenReturn(Mockito.mock(LoadBalancerVO.class));
    when(userVmDao.findById(anyLong())).thenReturn(Mockito.mock(UserVmVO.class));
    when(lb2VmMapDao.listByLoadBalancerId(anyLong(), anyBoolean())).thenReturn(_lbvmMapList);
    _lbMgr.assignToLoadBalancer(1L, null, vmIdIpMap);
}
Also used : LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) UserVmVO(com.cloud.vm.UserVmVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.anyLong(org.mockito.Matchers.anyLong) LoadBalancerVMMapDao(com.cloud.network.dao.LoadBalancerVMMapDao) ArrayList(java.util.ArrayList) List(java.util.List) UserVmDao(com.cloud.vm.dao.UserVmDao) Test(org.junit.Test)

Example 2 with LoadBalancerVMMapDao

use of com.cloud.network.dao.LoadBalancerVMMapDao in project cosmic by MissionCriticalCloud.

the class AssignLoadBalancerTest method tesSecIpNotSetToVm.

@Test(expected = InvalidParameterValueException.class)
public void tesSecIpNotSetToVm() throws ResourceAllocationException, ResourceUnavailableException, InsufficientCapacityException {
    final AssignToLoadBalancerRuleCmd assignLbRuleCmd = Mockito.mock(AssignToLoadBalancerRuleCmd.class);
    final Map<Long, List<String>> vmIdIpMap = new HashMap<>();
    final List<String> secIp = new ArrayList<>();
    secIp.add("10.1.1.175");
    vmIdIpMap.put(1L, secIp);
    final List<Long> vmIds = new ArrayList<>();
    vmIds.add(2L);
    final LoadBalancerVO lbVO = new LoadBalancerVO("1", "L1", "Lbrule", 1, 22, 22, "rb", 204, 0, 0, "tcp", 60000, 60000);
    final LoadBalancerDao lbDao = Mockito.mock(LoadBalancerDao.class);
    final LoadBalancerVMMapDao lb2VmMapDao = Mockito.mock(LoadBalancerVMMapDao.class);
    final UserVmDao userVmDao = Mockito.mock(UserVmDao.class);
    final NicSecondaryIpDao nicSecIpDao = Mockito.mock(NicSecondaryIpDao.class);
    _lbMgr._lbDao = lbDao;
    _lbMgr._lb2VmMapDao = lb2VmMapDao;
    _lbMgr._vmDao = userVmDao;
    _lbMgr._nicSecondaryIpDao = nicSecIpDao;
    _lbvmMapList = new ArrayList<>();
    _lbMgr._rulesMgr = _rulesMgr;
    _lbMgr._networkModel = _networkModel;
    when(lbDao.findById(anyLong())).thenReturn(lbVO);
    when(userVmDao.findById(anyLong())).thenReturn(Mockito.mock(UserVmVO.class));
    when(lb2VmMapDao.listByLoadBalancerId(anyLong(), anyBoolean())).thenReturn(_lbvmMapList);
    when(nicSecIpDao.findByIp4AddressAndNicId(anyString(), anyLong())).thenReturn(null);
    _lbMgr.assignToLoadBalancer(1L, null, vmIdIpMap);
}
Also used : LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) UserVmVO(com.cloud.vm.UserVmVO) NicSecondaryIpDao(com.cloud.vm.dao.NicSecondaryIpDao) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) Matchers.anyString(org.mockito.Matchers.anyString) AssignToLoadBalancerRuleCmd(com.cloud.api.command.user.loadbalancer.AssignToLoadBalancerRuleCmd) Matchers.anyLong(org.mockito.Matchers.anyLong) LoadBalancerVMMapDao(com.cloud.network.dao.LoadBalancerVMMapDao) ArrayList(java.util.ArrayList) List(java.util.List) UserVmDao(com.cloud.vm.dao.UserVmDao) Test(org.junit.Test)

Example 3 with LoadBalancerVMMapDao

use of com.cloud.network.dao.LoadBalancerVMMapDao in project cloudstack by apache.

the class AssignLoadBalancerTest method testNicIsNotInNw.

@Test(expected = InvalidParameterValueException.class)
public void testNicIsNotInNw() throws ResourceAllocationException, ResourceUnavailableException, InsufficientCapacityException {
    Map<Long, List<String>> vmIdIpMap = new HashMap<Long, List<String>>();
    List<String> secIp = new ArrayList<String>();
    secIp.add("10.1.1.175");
    vmIdIpMap.put(1L, secIp);
    List<Long> vmIds = new ArrayList<Long>();
    vmIds.add(2L);
    LoadBalancerDao lbDao = Mockito.mock(LoadBalancerDao.class);
    LoadBalancerVMMapDao lb2VmMapDao = Mockito.mock(LoadBalancerVMMapDao.class);
    UserVmDao userVmDao = Mockito.mock(UserVmDao.class);
    _lbMgr._lbDao = lbDao;
    _lbMgr._lb2VmMapDao = lb2VmMapDao;
    _lbMgr._vmDao = userVmDao;
    _lbvmMapList = new ArrayList<>();
    _lbMgr._rulesMgr = _rulesMgr;
    _lbMgr._networkModel = _networkModel;
    when(lbDao.findById(anyLong())).thenReturn(Mockito.mock(LoadBalancerVO.class));
    when(userVmDao.findById(anyLong())).thenReturn(Mockito.mock(UserVmVO.class));
    when(lb2VmMapDao.listByLoadBalancerId(anyLong(), anyBoolean())).thenReturn(_lbvmMapList);
    _lbMgr.assignToLoadBalancer(1L, null, vmIdIpMap);
}
Also used : LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) UserVmVO(com.cloud.vm.UserVmVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.anyLong(org.mockito.Matchers.anyLong) LoadBalancerVMMapDao(com.cloud.network.dao.LoadBalancerVMMapDao) ArrayList(java.util.ArrayList) List(java.util.List) UserVmDao(com.cloud.vm.dao.UserVmDao) Test(org.junit.Test)

Example 4 with LoadBalancerVMMapDao

use of com.cloud.network.dao.LoadBalancerVMMapDao in project cloudstack by apache.

the class AssignLoadBalancerTest method tesSecIpNotSetToVm.

@Test(expected = InvalidParameterValueException.class)
public void tesSecIpNotSetToVm() throws ResourceAllocationException, ResourceUnavailableException, InsufficientCapacityException {
    AssignToLoadBalancerRuleCmd assignLbRuleCmd = Mockito.mock(AssignToLoadBalancerRuleCmd.class);
    Map<Long, List<String>> vmIdIpMap = new HashMap<Long, List<String>>();
    List<String> secIp = new ArrayList<String>();
    secIp.add("10.1.1.175");
    vmIdIpMap.put(1L, secIp);
    List<Long> vmIds = new ArrayList<Long>();
    vmIds.add(2L);
    LoadBalancerVO lbVO = new LoadBalancerVO("1", "L1", "Lbrule", 1, 22, 22, "rb", 204, 0, 0, "tcp");
    LoadBalancerDao lbDao = Mockito.mock(LoadBalancerDao.class);
    LoadBalancerVMMapDao lb2VmMapDao = Mockito.mock(LoadBalancerVMMapDao.class);
    UserVmDao userVmDao = Mockito.mock(UserVmDao.class);
    NicSecondaryIpDao nicSecIpDao = Mockito.mock(NicSecondaryIpDao.class);
    _lbMgr._lbDao = lbDao;
    _lbMgr._lb2VmMapDao = lb2VmMapDao;
    _lbMgr._vmDao = userVmDao;
    _lbMgr._nicSecondaryIpDao = nicSecIpDao;
    _lbvmMapList = new ArrayList<>();
    _lbMgr._rulesMgr = _rulesMgr;
    _lbMgr._networkModel = _networkModel;
    when(lbDao.findById(anyLong())).thenReturn(lbVO);
    when(userVmDao.findById(anyLong())).thenReturn(Mockito.mock(UserVmVO.class));
    when(lb2VmMapDao.listByLoadBalancerId(anyLong(), anyBoolean())).thenReturn(_lbvmMapList);
    when(nicSecIpDao.findByIp4AddressAndNicId(anyString(), anyLong())).thenReturn(null);
    _lbMgr.assignToLoadBalancer(1L, null, vmIdIpMap);
}
Also used : LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) UserVmVO(com.cloud.vm.UserVmVO) NicSecondaryIpDao(com.cloud.vm.dao.NicSecondaryIpDao) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) Matchers.anyString(org.mockito.Matchers.anyString) AssignToLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.loadbalancer.AssignToLoadBalancerRuleCmd) Matchers.anyLong(org.mockito.Matchers.anyLong) LoadBalancerVMMapDao(com.cloud.network.dao.LoadBalancerVMMapDao) ArrayList(java.util.ArrayList) List(java.util.List) UserVmDao(com.cloud.vm.dao.UserVmDao) Test(org.junit.Test)

Example 5 with LoadBalancerVMMapDao

use of com.cloud.network.dao.LoadBalancerVMMapDao in project cosmic by MissionCriticalCloud.

the class AssignLoadBalancerTest method testVmIdAlreadyExist.

@Test(expected = InvalidParameterValueException.class)
public void testVmIdAlreadyExist() throws ResourceAllocationException, ResourceUnavailableException, InsufficientCapacityException {
    final AssignToLoadBalancerRuleCmd assignLbRuleCmd = Mockito.mock(AssignToLoadBalancerRuleCmd.class);
    final Map<Long, List<String>> vmIdIpMap = new HashMap<>();
    final List<String> secIp = new ArrayList<>();
    secIp.add("10.1.1.175");
    vmIdIpMap.put(1L, secIp);
    final List<Long> vmIds = new ArrayList<>();
    vmIds.add(2L);
    final LoadBalancerVO lbVO = new LoadBalancerVO("1", "L1", "Lbrule", 1, 22, 22, "rb", 204, 0, 0, "tcp", 60000, 60000);
    final LoadBalancerDao lbDao = Mockito.mock(LoadBalancerDao.class);
    final LoadBalancerVMMapDao lb2VmMapDao = Mockito.mock(LoadBalancerVMMapDao.class);
    final UserVmDao userVmDao = Mockito.mock(UserVmDao.class);
    final NicSecondaryIpDao nicSecIpDao = Mockito.mock(NicSecondaryIpDao.class);
    final LoadBalancerVMMapVO lbVmMapVO = new LoadBalancerVMMapVO(1L, 1L, "10.1.1.175", false);
    _lbMgr._lbDao = lbDao;
    _lbMgr._lb2VmMapDao = lb2VmMapDao;
    _lbMgr._vmDao = userVmDao;
    _lbMgr._nicSecondaryIpDao = nicSecIpDao;
    _lbvmMapList = new ArrayList<>();
    _lbvmMapList.add(lbVmMapVO);
    _lbMgr._rulesMgr = _rulesMgr;
    _lbMgr._networkModel = _networkModel;
    when(lbDao.findById(anyLong())).thenReturn(lbVO);
    when(userVmDao.findById(anyLong())).thenReturn(Mockito.mock(UserVmVO.class));
    when(lb2VmMapDao.listByLoadBalancerId(anyLong(), anyBoolean())).thenReturn(_lbvmMapList);
    when(nicSecIpDao.findByIp4AddressAndNicId(anyString(), anyLong())).thenReturn(null);
    _lbMgr.assignToLoadBalancer(1L, null, vmIdIpMap);
}
Also used : LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) UserVmVO(com.cloud.vm.UserVmVO) NicSecondaryIpDao(com.cloud.vm.dao.NicSecondaryIpDao) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) Matchers.anyString(org.mockito.Matchers.anyString) AssignToLoadBalancerRuleCmd(com.cloud.api.command.user.loadbalancer.AssignToLoadBalancerRuleCmd) Matchers.anyLong(org.mockito.Matchers.anyLong) LoadBalancerVMMapDao(com.cloud.network.dao.LoadBalancerVMMapDao) ArrayList(java.util.ArrayList) List(java.util.List) LoadBalancerVMMapVO(com.cloud.network.dao.LoadBalancerVMMapVO) UserVmDao(com.cloud.vm.dao.UserVmDao) Test(org.junit.Test)

Aggregations

LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)6 LoadBalancerVMMapDao (com.cloud.network.dao.LoadBalancerVMMapDao)6 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)6 UserVmVO (com.cloud.vm.UserVmVO)6 UserVmDao (com.cloud.vm.dao.UserVmDao)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Test (org.junit.Test)6 Matchers.anyLong (org.mockito.Matchers.anyLong)6 Matchers.anyString (org.mockito.Matchers.anyString)6 NicSecondaryIpDao (com.cloud.vm.dao.NicSecondaryIpDao)4 AssignToLoadBalancerRuleCmd (com.cloud.api.command.user.loadbalancer.AssignToLoadBalancerRuleCmd)2 LoadBalancerVMMapVO (com.cloud.network.dao.LoadBalancerVMMapVO)2 AssignToLoadBalancerRuleCmd (org.apache.cloudstack.api.command.user.loadbalancer.AssignToLoadBalancerRuleCmd)2