Search in sources :

Example 66 with ReservationContext

use of com.cloud.vm.ReservationContext in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testImplement.

@Test
public void testImplement() throws InsufficientVirtualNetworkCapacityException, URISyntaxException {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VCS" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(true);
    mock(DeploymentPlan.class);
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getBroadcastUri()).thenReturn(new URI("vlan://14"));
    final DeployDestination dest = mock(DeployDestination.class);
    final DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    final HostVO brocadeHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
    when(brocadeHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
    when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
    List<BrocadeVcsDeviceVO> devices = new ArrayList();
    devices.add(brocadeDevice);
    when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    when(guestGuru.implement(network, offering, dest, res)).thenReturn(network);
    final CreateNetworkAnswer answer = mock(CreateNetworkAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    final Network implementednetwork = guru.implement(network, offering, dest, res);
    assertTrue(implementednetwork != null);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) ArrayList(java.util.ArrayList) URI(java.net.URI) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) ReservationContext(com.cloud.vm.ReservationContext) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) CreateNetworkAnswer(com.cloud.agent.api.CreateNetworkAnswer) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 67 with ReservationContext

use of com.cloud.vm.ReservationContext in project cloudstack by apache.

the class NiciraNvpGuestNetworkGuruTest method testShutdown.

@Test
public void testShutdown() throws InsufficientVirtualNetworkCapacityException, URISyntaxException {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT", "VXLAN" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
    mock(DeploymentPlan.class);
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
    when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(netdao.findById(NETWORK_ID)).thenReturn(network);
    final DeployDestination dest = mock(DeployDestination.class);
    final DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    final HostVO niciraHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(niciraHost);
    when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
    when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
    when(niciraHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    final DeleteLogicalSwitchAnswer answer = mock(DeleteLogicalSwitchAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    final NetworkProfile implementednetwork = mock(NetworkProfile.class);
    when(implementednetwork.getId()).thenReturn(NETWORK_ID);
    when(implementednetwork.getBroadcastUri()).thenReturn(new URI("lswitch:aaaa"));
    when(offering.isSpecifyVlan()).thenReturn(false);
    guru.shutdown(implementednetwork, offering);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
    verify(implementednetwork, times(1)).setBroadcastUri(null);
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) NetworkProfile(com.cloud.network.NetworkProfile) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DeleteLogicalSwitchAnswer(com.cloud.agent.api.DeleteLogicalSwitchAnswer) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 68 with ReservationContext

use of com.cloud.vm.ReservationContext in project cloudstack by apache.

the class VxlanGuestNetworkGuruTest method testImplementWithCidr.

@Test
public void testImplementWithCidr() throws InsufficientVirtualNetworkCapacityException {
    PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById(anyLong())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VXLAN" }));
    when(physnet.getId()).thenReturn(42L);
    NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(42L);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getGateway()).thenReturn("10.1.1.1");
    when(network.getCidr()).thenReturn("10.1.1.0/24");
    when(network.getPhysicalNetworkId()).thenReturn(42L);
    DeployDestination dest = mock(DeployDestination.class);
    DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
    // TODO(VXLAN): doesn't support VNI specified
    // when(confsvr.getConfigValue((String) any(), (String) any(), anyLong())).thenReturn("true");
    when(dcdao.allocateVnet(anyLong(), anyLong(), anyLong(), (String) any(), eq(true))).thenReturn("42");
    doNothing().when(guru).allocateVnetComplete((Network) any(), (NetworkVO) any(), anyLong(), anyLong(), (String) any(), eq("42"));
    Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    Network implementednetwork = guru.implement(network, offering, dest, res);
    assertTrue(implementednetwork != null);
    assertTrue(implementednetwork.getCidr().equals("10.1.1.0/24"));
    assertTrue(implementednetwork.getGateway().equals("10.1.1.1"));
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DataCenter(com.cloud.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 69 with ReservationContext

use of com.cloud.vm.ReservationContext in project cloudstack by apache.

the class VxlanGuestNetworkGuruTest method testShutdown.

@Test
public void testShutdown() throws InsufficientVirtualNetworkCapacityException, URISyntaxException {
    PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById(anyLong())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VXLAN" }));
    when(physnet.getId()).thenReturn(42L);
    NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(42L);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vxlan);
    when(network.getBroadcastUri()).thenReturn(new URI("vxlan:12345"));
    when(network.getPhysicalNetworkId()).thenReturn(42L);
    when(netdao.findById(42L)).thenReturn(network);
    DeployDestination dest = mock(DeployDestination.class);
    DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
    Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    NetworkProfile implementednetwork = mock(NetworkProfile.class);
    when(implementednetwork.getId()).thenReturn(42L);
    when(implementednetwork.getBroadcastUri()).thenReturn(new URI("vxlan:12345"));
    when(offering.isSpecifyVlan()).thenReturn(false);
    guru.shutdown(implementednetwork, offering);
    verify(implementednetwork, times(1)).setBroadcastUri(null);
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkProfile(com.cloud.network.NetworkProfile) DataCenter(com.cloud.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) DeployDestination(com.cloud.deploy.DeployDestination) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) URI(java.net.URI) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 70 with ReservationContext

use of com.cloud.vm.ReservationContext in project cloudstack by apache.

the class KubernetesClusterStartWorker method startKubernetesClusterNetwork.

private Network startKubernetesClusterNetwork(final DeployDestination destination) throws ManagementServerException {
    final ReservationContext context = new ReservationContextImpl(null, null, null, owner);
    Network network = networkDao.findById(kubernetesCluster.getNetworkId());
    if (network == null) {
        String msg = String.format("Network for Kubernetes cluster : %s not found", kubernetesCluster.getName());
        LOGGER.warn(msg);
        stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.CreateFailed);
        throw new ManagementServerException(msg);
    }
    try {
        networkMgr.startNetwork(network.getId(), destination, context);
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(String.format("Network : %s is started for the  Kubernetes cluster : %s", network.getName(), kubernetesCluster.getName()));
        }
    } catch (ConcurrentOperationException | ResourceUnavailableException | InsufficientCapacityException e) {
        String msg = String.format("Failed to start Kubernetes cluster : %s as unable to start associated network : %s", kubernetesCluster.getName(), network.getName());
        LOGGER.error(msg, e);
        stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.CreateFailed);
        throw new ManagementServerException(msg, e);
    }
    return network;
}
Also used : ManagementServerException(com.cloud.exception.ManagementServerException) Network(com.cloud.network.Network) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ReservationContext(com.cloud.vm.ReservationContext)

Aggregations

ReservationContext (com.cloud.vm.ReservationContext)72 Account (com.cloud.user.Account)45 ReservationContextImpl (com.cloud.vm.ReservationContextImpl)42 DeployDestination (com.cloud.deploy.DeployDestination)41 NetworkVO (com.cloud.network.dao.NetworkVO)41 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)38 Test (org.junit.Test)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)28 NetworkOffering (com.cloud.offering.NetworkOffering)27 Network (com.cloud.network.Network)24 Domain (com.cloud.domain.Domain)23 HostVO (com.cloud.host.HostVO)22 DataCenter (com.cloud.dc.DataCenter)21 URI (java.net.URI)19 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)17 NicProfile (com.cloud.vm.NicProfile)17 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)14 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)14 User (com.cloud.user.User)14 NicVO (com.cloud.vm.NicVO)14