Search in sources :

Example 6 with UserVmDao

use of com.cloud.vm.dao.UserVmDao in project cloudstack by apache.

the class InstanceIpModelTest method testCreateInstanceIp.

@Test
public void testCreateInstanceIp() throws IOException {
    ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class);
    ModelController controller = mock(ModelController.class);
    ApiConnector api = new ApiConnectorMock(null, 0);
    when(controller.getApiAccessor()).thenReturn(api);
    when(controller.getManager()).thenReturn(contrailMgr);
    // Create Virtual-Network (VN)
    NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(Network.State.Implemented);
    when(network.getGateway()).thenReturn("10.1.1.1");
    when(network.getCidr()).thenReturn("10.1.1.0/24");
    when(network.getPhysicalNetworkId()).thenReturn(42L);
    when(network.getDomainId()).thenReturn(10L);
    when(network.getAccountId()).thenReturn(42L);
    NetworkDao networkDao = mock(NetworkDao.class);
    when(networkDao.findById(anyLong())).thenReturn(network);
    when(controller.getNetworkDao()).thenReturn(networkDao);
    when(contrailMgr.getCanonicalName(network)).thenReturn("testnetwork");
    when(contrailMgr.getProjectId(network.getDomainId(), network.getAccountId())).thenReturn("testProjectId");
    VirtualNetworkModel vnModel = new VirtualNetworkModel(network, UUID.randomUUID().toString(), "test", TrafficType.Guest);
    vnModel.build(controller, network);
    try {
        vnModel.update(controller);
    } catch (Exception ex) {
        fail("virtual-network update failed ");
    }
    // Create Virtual-Machine (VM)
    VMInstanceVO vm = mock(VMInstanceVO.class);
    when(vm.getInstanceName()).thenReturn("testVM1");
    when(vm.getState()).thenReturn(VirtualMachine.State.Running);
    when(vm.getDomainId()).thenReturn(10L);
    when(vm.getAccountId()).thenReturn(42L);
    UserVmDao VmDao = mock(UserVmDao.class);
    when(VmDao.findById(anyLong())).thenReturn(null);
    when(controller.getVmDao()).thenReturn(VmDao);
    VirtualMachineModel vmModel = new VirtualMachineModel(vm, UUID.randomUUID().toString());
    vmModel.build(controller, vm);
    try {
        vmModel.update(controller);
    } catch (Exception ex) {
        fail("virtual-machine update failed ");
    }
    // Create Virtual=Machine-Interface (VMInterface)
    NicVO nic = mock(NicVO.class);
    when(nic.getIPv4Address()).thenReturn("10.1.1.2");
    when(nic.getMacAddress()).thenReturn("00:01:02:03:04:05");
    when(nic.getDeviceId()).thenReturn(100);
    when(nic.getState()).thenReturn(NicVO.State.Allocated);
    when(nic.getNetworkId()).thenReturn(10L);
    when(contrailMgr.getVifNameByVmName(anyString(), anyInt())).thenReturn("testVM1-100");
    VMInterfaceModel vmiModel = new VMInterfaceModel(UUID.randomUUID().toString());
    vmiModel.addToVirtualMachine(vmModel);
    vmiModel.addToVirtualNetwork(vnModel);
    try {
        vmiModel.build(controller, vm, nic);
        vmiModel.setActive();
    } catch (Exception ex) {
        fail("vm-interface build failed ");
    }
    try {
        vmiModel.update(controller);
    } catch (Exception ex) {
        fail("vm-interface update failed ");
    }
    InstanceIpModel ipModel = new InstanceIpModel(vm.getInstanceName(), nic.getDeviceId());
    ipModel.addToVMInterface(vmiModel);
    ipModel.setAddress(nic.getIPv4Address());
    try {
        ipModel.update(controller);
    } catch (Exception ex) {
        fail("ipInstance update failed ");
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) ApiConnector(net.juniper.contrail.api.ApiConnector) VMInstanceVO(com.cloud.vm.VMInstanceVO) IOException(java.io.IOException) ContrailManagerImpl(org.apache.cloudstack.network.contrail.management.ContrailManagerImpl) NetworkDao(com.cloud.network.dao.NetworkDao) UserVmDao(com.cloud.vm.dao.UserVmDao) ApiConnectorMock(net.juniper.contrail.api.ApiConnectorMock) NicVO(com.cloud.vm.NicVO) Test(org.junit.Test)

Example 7 with UserVmDao

use of com.cloud.vm.dao.UserVmDao in project cloudstack by apache.

the class VMInterfaceModelTest method testCreateVMInterface.

@Test
public void testCreateVMInterface() throws IOException {
    String uuid;
    ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class);
    ModelController controller = mock(ModelController.class);
    ApiConnector api = new ApiConnectorMock(null, 0);
    when(controller.getManager()).thenReturn(contrailMgr);
    when(controller.getApiAccessor()).thenReturn(api);
    // Create Virtual-Network (VN)
    NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(Network.State.Implemented);
    when(network.getGateway()).thenReturn("10.1.1.1");
    when(network.getCidr()).thenReturn("10.1.1.0/24");
    when(network.getPhysicalNetworkId()).thenReturn(42L);
    when(network.getDomainId()).thenReturn(10L);
    when(network.getAccountId()).thenReturn(42L);
    NetworkDao networkDao = mock(NetworkDao.class);
    when(networkDao.findById(anyLong())).thenReturn(network);
    when(controller.getNetworkDao()).thenReturn(networkDao);
    when(contrailMgr.getCanonicalName(network)).thenReturn("testnetwork");
    when(contrailMgr.getProjectId(network.getDomainId(), network.getAccountId())).thenReturn("testProjectId");
    VirtualNetworkModel vnModel = new VirtualNetworkModel(network, UUID.randomUUID().toString(), "test", TrafficType.Guest);
    vnModel.build(controller, network);
    try {
        vnModel.update(controller);
    } catch (Exception ex) {
        fail("virtual-network update failed ");
    }
    // Create Virtual-Machine (VM)
    VMInstanceVO vm = mock(VMInstanceVO.class);
    when(vm.getInstanceName()).thenReturn("testVM1");
    when(vm.getState()).thenReturn(VirtualMachine.State.Running);
    when(vm.getDomainId()).thenReturn(10L);
    when(vm.getAccountId()).thenReturn(42L);
    UserVmDao VmDao = mock(UserVmDao.class);
    when(VmDao.findById(anyLong())).thenReturn(null);
    when(controller.getVmDao()).thenReturn(VmDao);
    VirtualMachineModel vmModel = new VirtualMachineModel(vm, UUID.randomUUID().toString());
    vmModel.build(controller, vm);
    try {
        vmModel.update(controller);
    } catch (Exception ex) {
        fail("virtual-machine update failed ");
    }
    // Create Virtual=Machine-Interface (VMInterface)
    NicVO nic = mock(NicVO.class);
    when(nic.getIPv4Address()).thenReturn("10.1.1.2");
    when(nic.getMacAddress()).thenReturn("00:01:02:03:04:05");
    when(nic.getDeviceId()).thenReturn(100);
    when(nic.getState()).thenReturn(NicVO.State.Allocated);
    when(nic.getNetworkId()).thenReturn(10L);
    when(contrailMgr.getVifNameByVmName(anyString(), anyInt())).thenReturn("testVM1-100");
    uuid = UUID.randomUUID().toString();
    VMInterfaceModel vmiModel = new VMInterfaceModel(uuid);
    assertEquals(uuid, vmiModel.getUuid());
    vmiModel.addToVirtualMachine(vmModel);
    vmiModel.addToVirtualNetwork(vnModel);
    try {
        vmiModel.build(controller, vm, nic);
        vmiModel.setActive();
    } catch (Exception ex) {
        fail("vm-interface build failed ");
    }
    try {
        vmiModel.update(controller);
    } catch (Exception ex) {
        fail("vm-interface update failed ");
    }
    // Verify virtual-machine-interface creation.
    try {
        VirtualMachineInterface vmi = (VirtualMachineInterface) api.findById(VirtualMachineInterface.class, vmiModel.getUuid());
        assertNotNull(vmi);
    } catch (Exception ex) {
        fail("vm-interface verify failed ");
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) ApiConnector(net.juniper.contrail.api.ApiConnector) VMInstanceVO(com.cloud.vm.VMInstanceVO) Matchers.anyString(org.mockito.Matchers.anyString) IOException(java.io.IOException) ContrailManagerImpl(org.apache.cloudstack.network.contrail.management.ContrailManagerImpl) NetworkDao(com.cloud.network.dao.NetworkDao) VirtualMachineInterface(net.juniper.contrail.api.types.VirtualMachineInterface) UserVmDao(com.cloud.vm.dao.UserVmDao) ApiConnectorMock(net.juniper.contrail.api.ApiConnectorMock) NicVO(com.cloud.vm.NicVO) Test(org.junit.Test)

Example 8 with UserVmDao

use of com.cloud.vm.dao.UserVmDao in project cloudstack by apache.

the class AssignLoadBalancerTest method testVmIdAlreadyExist.

@Test(expected = InvalidParameterValueException.class)
public void testVmIdAlreadyExist() 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);
    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(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) LoadBalancerVMMapVO(com.cloud.network.dao.LoadBalancerVMMapVO) UserVmDao(com.cloud.vm.dao.UserVmDao) Test(org.junit.Test)

Example 9 with UserVmDao

use of com.cloud.vm.dao.UserVmDao in project cloudstack by apache.

the class SshKeyToRouterRules method accept.

@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
    _router = router;
    UserVmDao userVmDao = visitor.getVirtualNetworkApplianceFactory().getUserVmDao();
    _userVM = userVmDao.findById(_profile.getVirtualMachine().getId());
    userVmDao.loadDetails(_userVM);
    NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao();
    _nicVo = nicDao.findById(_nic.getId());
    // for basic zone, send vm data/password information only to the router in the same pod
    VMTemplateDao templateDao = visitor.getVirtualNetworkApplianceFactory().getTemplateDao();
    _template = templateDao.findByIdIncludingRemoved(_profile.getTemplateId());
    return visitor.visit(this);
}
Also used : NicDao(com.cloud.vm.dao.NicDao) VMTemplateDao(com.cloud.storage.dao.VMTemplateDao) UserVmDao(com.cloud.vm.dao.UserVmDao)

Example 10 with UserVmDao

use of com.cloud.vm.dao.UserVmDao in project cloudstack by apache.

the class UserdataPwdRules method accept.

@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
    _router = router;
    UserVmDao userVmDao = visitor.getVirtualNetworkApplianceFactory().getUserVmDao();
    _userVM = userVmDao.findById(_profile.getId());
    userVmDao.loadDetails(_userVM);
    //for basic zone, send vm data/password information only to the router in the same pod
    NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao();
    _nicVo = nicDao.findById(_nic.getId());
    return visitor.visit(this);
}
Also used : NicDao(com.cloud.vm.dao.NicDao) UserVmDao(com.cloud.vm.dao.UserVmDao)

Aggregations

UserVmDao (com.cloud.vm.dao.UserVmDao)12 NicDao (com.cloud.vm.dao.NicDao)6 Test (org.junit.Test)6 UserVmVO (com.cloud.vm.UserVmVO)4 ArrayList (java.util.ArrayList)4 Matchers.anyString (org.mockito.Matchers.anyString)4 LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)3 LoadBalancerVMMapDao (com.cloud.network.dao.LoadBalancerVMMapDao)3 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)3 NetworkVO (com.cloud.network.dao.NetworkVO)3 NicVO (com.cloud.vm.NicVO)3 VMInstanceVO (com.cloud.vm.VMInstanceVO)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ApiConnector (net.juniper.contrail.api.ApiConnector)3 ApiConnectorMock (net.juniper.contrail.api.ApiConnectorMock)3 ContrailManagerImpl (org.apache.cloudstack.network.contrail.management.ContrailManagerImpl)3 Matchers.anyLong (org.mockito.Matchers.anyLong)3 NetworkDao (com.cloud.network.dao.NetworkDao)2