use of com.cloud.deploy.DeployDestination in project cloudstack by apache.
the class RouterDeploymentDefinition method findOrDeployVirtualRouter.
@DB
protected void findOrDeployVirtualRouter() throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (!isRouterDeployed()) {
try {
lock();
// reset router list that got populated during isRouterDeployed()
routers.clear();
checkPreconditions();
// dest has pod=null, for Basic Zone findOrDeployVRs for all Pods
final List<DeployDestination> destinations = findDestinations();
for (final DeployDestination destination : destinations) {
dest = destination;
generateDeploymentPlan();
executeDeployment();
}
} finally {
unlock();
}
}
}
use of com.cloud.deploy.DeployDestination in project cloudstack by apache.
the class BrocadeVcsGuestNetworkGuruTest method testImplementFail.
@Test
public void testImplementFail() 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(false);
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);
final List<BrocadeVcsDeviceVO> devices = mock(List.class);
when(devices.isEmpty()).thenReturn(true);
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(0)).easySend(eq(NETWORK_ID), (Command) any());
}
use of com.cloud.deploy.DeployDestination 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());
}
use of com.cloud.deploy.DeployDestination in project cloudstack by apache.
the class BrocadeVcsGuestNetworkGuruTest method testReserveFail.
@Test
public void testReserveFail() throws InsufficientVirtualNetworkCapacityException, URISyntaxException, InsufficientAddressCapacityException {
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"));
when(network.getDataCenterId()).thenReturn(NETWORK_ID);
final NicProfile nic = mock(NicProfile.class);
when(nic.getMacAddress()).thenReturn("macaddress");
when(nic.getReservationStrategy()).thenReturn(ReservationStrategy.Start);
final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
final DeployDestination dest = mock(DeployDestination.class);
final DataCenterVO dc = mock(DataCenterVO.class);
when(dest.getDataCenter()).thenReturn(dc);
when(dcdao.findById((long) anyInt())).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);
final List<BrocadeVcsDeviceVO> devices = mock(List.class);
when(devices.isEmpty()).thenReturn(true);
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);
final AssociateMacToNetworkAnswer answer = mock(AssociateMacToNetworkAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
guru.reserve(nic, network, vmProfile, dest, res);
verify(agentmgr, times(0)).easySend(eq(NETWORK_ID), (Command) any());
}
use of com.cloud.deploy.DeployDestination in project cloudstack by apache.
the class RouterDeploymentDefinitionTest method testFindDestinations.
@Test
public void testFindDestinations() {
// Prepare
when(mockDataCenter.getNetworkType()).thenReturn(NetworkType.Basic);
when(mockDestination.getPod()).thenReturn(null);
// Stub local method listByDataCenterIdVMTypeAndStates
mockPods.add(mockHostPodVO1);
mockPods.add(mockHostPodVO2);
mockPods.add(mockHostPodVO3);
final RouterDeploymentDefinition deployment = spy(this.deployment);
doReturn(mockPods).when(deployment).listByDataCenterIdVMTypeAndStates(DATA_CENTER_ID, VirtualMachine.Type.User, VirtualMachine.State.Starting, VirtualMachine.State.Running);
// Leave this one empty to force adding add destination for this pod
final List<DomainRouterVO> virtualRouters1 = new ArrayList<>();
when(mockRouterDao.listByPodIdAndStates(POD_ID1, VirtualMachine.State.Starting, VirtualMachine.State.Running)).thenReturn(virtualRouters1);
// This list is not empty, so it will not add any for this pod, and continue with next pod
final List<DomainRouterVO> virtualRouters2 = new ArrayList<>();
final DomainRouterVO domainRouterVO1 = mock(DomainRouterVO.class);
virtualRouters2.add(domainRouterVO1);
when(mockRouterDao.listByPodIdAndStates(POD_ID2, VirtualMachine.State.Starting, VirtualMachine.State.Running)).thenReturn(virtualRouters2);
// Leave this last one empty to check we finally added more than one afterwards
final List<DomainRouterVO> virtualRouters3 = new ArrayList<>();
when(mockRouterDao.listByPodIdAndStates(POD_ID3, VirtualMachine.State.Starting, VirtualMachine.State.Running)).thenReturn(virtualRouters3);
// Execute
final List<DeployDestination> destinations = deployment.findDestinations();
// Assert that 2 were added (for the 1st and 3rd
assertEquals("", 2, destinations.size());
assertEquals("", mockDataCenter, destinations.get(0).getDataCenter());
assertEquals("", mockHostPodVO1, destinations.get(0).getPod());
assertEquals("", mockDataCenter, destinations.get(1).getDataCenter());
assertEquals("", mockHostPodVO3, destinations.get(1).getPod());
}
Aggregations