Search in sources :

Example 1 with ContrailManagerImpl

use of org.apache.cloudstack.network.contrail.management.ContrailManagerImpl in project cloudstack by apache.

the class VirtualMachineModelTest method testCreateVirtualMachine.

@Test
public void testCreateVirtualMachine() throws IOException {
    String uuid = UUID.randomUUID().toString();
    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.Allocated);
    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);
    when(contrailMgr.getCanonicalName(network)).thenReturn("testnetwork");
    when(contrailMgr.getProjectId(network.getDomainId(), network.getAccountId())).thenReturn("testProjectId");
    // Create Virtual-Machine (VM)
    VMInstanceVO vm = mock(VMInstanceVO.class);
    when(vm.getInstanceName()).thenReturn("testVM1");
    when(vm.getState()).thenReturn(VirtualMachine.State.Starting);
    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);
    assertEquals(vmModel.getInstanceName(), "testVM1");
    assertEquals(vmModel.getUuid(), uuid);
    vmModel.build(controller, vm);
    try {
        vmModel.update(controller);
    } catch (Exception ex) {
        fail("virtual-network update failed ");
    }
    //verify
    assertTrue(vmModel.verify(controller));
}
Also used : ContrailManagerImpl(org.apache.cloudstack.network.contrail.management.ContrailManagerImpl) NetworkVO(com.cloud.network.dao.NetworkVO) ApiConnector(net.juniper.contrail.api.ApiConnector) VMInstanceVO(com.cloud.vm.VMInstanceVO) UserVmDao(com.cloud.vm.dao.UserVmDao) ApiConnectorMock(net.juniper.contrail.api.ApiConnectorMock) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with ContrailManagerImpl

use of org.apache.cloudstack.network.contrail.management.ContrailManagerImpl in project cloudstack by apache.

the class VirtualNetworkModelTest method testCreateVirtualNetwork.

@Test
public void testCreateVirtualNetwork() throws IOException {
    String uuid = UUID.randomUUID().toString();
    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(State.Allocated);
    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);
    when(contrailMgr.getCanonicalName(network)).thenReturn("testnetwork");
    when(contrailMgr.getProjectId(network.getDomainId(), network.getAccountId())).thenReturn("testProjectId");
    VirtualNetworkModel vnModel = new VirtualNetworkModel(network, uuid, "testnetwork", TrafficType.Guest);
    assertEquals(vnModel.getName(), "testnetwork");
    assertEquals(vnModel.getUuid(), uuid);
    vnModel.build(controller, network);
    try {
        vnModel.update(controller);
    } catch (Exception ex) {
        fail("virtual-network update failed ");
    }
    assertTrue(vnModel.verify(controller));
}
Also used : ContrailManagerImpl(org.apache.cloudstack.network.contrail.management.ContrailManagerImpl) NetworkVO(com.cloud.network.dao.NetworkVO) ApiConnector(net.juniper.contrail.api.ApiConnector) ApiConnectorMock(net.juniper.contrail.api.ApiConnectorMock) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with ContrailManagerImpl

use of org.apache.cloudstack.network.contrail.management.ContrailManagerImpl in project cloudstack by apache.

the class VirtualNetworkModelTest method setUp.

@Override
@Before
public void setUp() throws IOException {
    //Network UUIDs
    String uuid = UUID.randomUUID().toString();
    String uuid1 = UUID.randomUUID().toString();
    String uuid2 = UUID.randomUUID().toString();
    String uuid3 = UUID.randomUUID().toString();
    //ContrailManager
    ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class);
    controller = mock(ModelController.class);
    VlanDao vlanDao = mock(VlanDao.class);
    ApiConnector api = mock(ApiConnectorMock.class);
    //Mock classes/methods
    when(controller.getManager()).thenReturn(contrailMgr);
    when(controller.getApiAccessor()).thenReturn(api);
    when(controller.getVlanDao()).thenReturn(vlanDao);
    //Policy References used by vnModel1
    List<ObjectReference<VirtualNetworkPolicyType>> policyRefs1 = new ArrayList<ObjectReference<VirtualNetworkPolicyType>>();
    ObjectReference<VirtualNetworkPolicyType> objectReference1 = new ObjectReference<VirtualNetworkPolicyType>();
    policyRefs1.add(objectReference1);
    //Policy References used by vnModel2
    List<ObjectReference<VirtualNetworkPolicyType>> policyRefs2 = new ArrayList<ObjectReference<VirtualNetworkPolicyType>>();
    ObjectReference<VirtualNetworkPolicyType> objectReference2 = new ObjectReference<VirtualNetworkPolicyType>();
    policyRefs2.add(objectReference2);
    //Policy References used by vnModel3
    List<ObjectReference<VirtualNetworkPolicyType>> policyRefs3 = new ArrayList<ObjectReference<VirtualNetworkPolicyType>>();
    ObjectReference<VirtualNetworkPolicyType> objectReference3 = new ObjectReference<VirtualNetworkPolicyType>();
    objectReference3.setReference(Arrays.asList(""), null, null, UUID.randomUUID().toString());
    policyRefs3.add(objectReference3);
    //Network to be compared with
    VirtualNetwork vn = mock(VirtualNetwork.class);
    when(api.findById(VirtualNetwork.class, uuid)).thenReturn(vn);
    //Network to be compared with
    VirtualNetwork vn1 = mock(VirtualNetwork.class);
    when(api.findById(VirtualNetwork.class, uuid1)).thenReturn(vn1);
    when(vn1.getNetworkPolicy()).thenReturn(policyRefs1);
    //Network to be compared to
    VirtualNetwork vn2 = mock(VirtualNetwork.class);
    when(api.findById(VirtualNetwork.class, uuid2)).thenReturn(vn2);
    when(vn2.getNetworkPolicy()).thenReturn(policyRefs2);
    //Network to be compared to
    VirtualNetwork vn3 = mock(VirtualNetwork.class);
    when(api.findById(VirtualNetwork.class, uuid3)).thenReturn(vn3);
    when(vn3.getNetworkPolicy()).thenReturn(policyRefs3);
    //Virtual-Network 1
    NetworkVO network1 = mock(NetworkVO.class);
    when(network1.getName()).thenReturn("testnetwork");
    when(network1.getState()).thenReturn(State.Allocated);
    when(network1.getGateway()).thenReturn("10.1.1.1");
    when(network1.getCidr()).thenReturn("10.1.1.0/24");
    when(network1.getPhysicalNetworkId()).thenReturn(42L);
    when(network1.getDomainId()).thenReturn(10L);
    when(network1.getAccountId()).thenReturn(42L);
    //Virtual-Network 2
    NetworkVO network2 = mock(NetworkVO.class);
    when(network2.getName()).thenReturn("Testnetwork");
    when(network2.getState()).thenReturn(State.Allocated);
    when(network2.getGateway()).thenReturn("10.1.1.1");
    when(network2.getCidr()).thenReturn("10.1.1.0/24");
    when(network2.getPhysicalNetworkId()).thenReturn(42L);
    when(network2.getDomainId()).thenReturn(10L);
    when(network2.getAccountId()).thenReturn(42L);
    //Virtual-Network 3
    NetworkVO network3 = mock(NetworkVO.class);
    when(network3.getName()).thenReturn("Testnetwork");
    when(network3.getState()).thenReturn(State.Allocated);
    when(network3.getGateway()).thenReturn("10.1.1.1");
    when(network3.getCidr()).thenReturn("10.1.1.0/24");
    when(network3.getPhysicalNetworkId()).thenReturn(42L);
    when(network3.getDomainId()).thenReturn(10L);
    when(network3.getAccountId()).thenReturn(42L);
    when(contrailMgr.getCanonicalName(network1)).thenReturn("testnetwork");
    when(contrailMgr.getProjectId(network1.getDomainId(), network1.getAccountId())).thenReturn("testProjectId");
    vnModel = new VirtualNetworkModel(network1, uuid, "testnetwork", TrafficType.Guest);
    vnModel1 = new VirtualNetworkModel(network1, uuid1, "testnetwork", TrafficType.Guest);
    vnModel2 = new VirtualNetworkModel(network2, uuid2, "testnetwork", TrafficType.Guest);
    vnModel3 = new VirtualNetworkModel(network3, uuid3, "testnetwork", TrafficType.Guest);
}
Also used : VirtualNetworkPolicyType(net.juniper.contrail.api.types.VirtualNetworkPolicyType) VlanDao(com.cloud.dc.dao.VlanDao) NetworkVO(com.cloud.network.dao.NetworkVO) ApiConnector(net.juniper.contrail.api.ApiConnector) ArrayList(java.util.ArrayList) VirtualNetwork(net.juniper.contrail.api.types.VirtualNetwork) ContrailManagerImpl(org.apache.cloudstack.network.contrail.management.ContrailManagerImpl) ObjectReference(net.juniper.contrail.api.ObjectReference) Before(org.junit.Before)

Example 4 with ContrailManagerImpl

use of org.apache.cloudstack.network.contrail.management.ContrailManagerImpl 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 5 with ContrailManagerImpl

use of org.apache.cloudstack.network.contrail.management.ContrailManagerImpl 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)

Aggregations

NetworkVO (com.cloud.network.dao.NetworkVO)5 ApiConnector (net.juniper.contrail.api.ApiConnector)5 ContrailManagerImpl (org.apache.cloudstack.network.contrail.management.ContrailManagerImpl)5 IOException (java.io.IOException)4 ApiConnectorMock (net.juniper.contrail.api.ApiConnectorMock)4 Test (org.junit.Test)4 VMInstanceVO (com.cloud.vm.VMInstanceVO)3 UserVmDao (com.cloud.vm.dao.UserVmDao)3 NetworkDao (com.cloud.network.dao.NetworkDao)2 NicVO (com.cloud.vm.NicVO)2 VlanDao (com.cloud.dc.dao.VlanDao)1 ArrayList (java.util.ArrayList)1 ObjectReference (net.juniper.contrail.api.ObjectReference)1 VirtualMachineInterface (net.juniper.contrail.api.types.VirtualMachineInterface)1 VirtualNetwork (net.juniper.contrail.api.types.VirtualNetwork)1 VirtualNetworkPolicyType (net.juniper.contrail.api.types.VirtualNetworkPolicyType)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1