Search in sources :

Example 51 with ReservationContext

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

the class ElasticLoadBalancerManagerImplTest method testFinalizeStartWhenCmdsAnswerIsNotNullButAnswerResultIsFalse.

@Test
public void testFinalizeStartWhenCmdsAnswerIsNotNullButAnswerResultIsFalse() throws Exception {
    CheckSshAnswer answerMock = mock(CheckSshAnswer.class);
    when(answerMock.getResult()).thenReturn(false);
    VirtualMachineProfile profileMock = mock(VirtualMachineProfile.class);
    long hostId = 1L;
    Commands cmds = mock(Commands.class);
    when(cmds.getAnswer("checkSsh")).thenReturn(answerMock);
    ReservationContext context = mock(ReservationContext.class);
    boolean expected = false;
    boolean actual = elasticLoadBalancerManagerImpl.finalizeStart(profileMock, hostId, cmds, context);
    assertEquals(expected, actual);
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) Commands(com.cloud.agent.manager.Commands) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 52 with ReservationContext

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

the class CiscoVnmcElementTest method shutdownTest.

@Test
public void shutdownTest() throws ConcurrentOperationException, ResourceUnavailableException {
    URI uri = URI.create("vlan://123");
    Network network = mock(Network.class);
    when(network.getId()).thenReturn(1L);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
    when(network.getDataCenterId()).thenReturn(1L);
    when(network.getBroadcastUri()).thenReturn(uri);
    ReservationContext context = mock(ReservationContext.class);
    when(_networkAsa1000vMapDao.findByNetworkId(network.getId())).thenReturn(mock(NetworkAsa1000vMapVO.class));
    List<CiscoVnmcControllerVO> devices = new ArrayList<CiscoVnmcControllerVO>();
    devices.add(mock(CiscoVnmcControllerVO.class));
    when(_ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(devices);
    HostVO hostVO = mock(HostVO.class);
    when(hostVO.getId()).thenReturn(1L);
    when(_hostDao.findById(anyLong())).thenReturn(hostVO);
    Answer answer = mock(Answer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentMgr.easySend(anyLong(), any(CleanupLogicalEdgeFirewallCommand.class))).thenReturn(answer);
    assertTrue(_element.shutdown(network, context, true));
}
Also used : Answer(com.cloud.agent.api.Answer) CleanupLogicalEdgeFirewallCommand(com.cloud.agent.api.CleanupLogicalEdgeFirewallCommand) Network(com.cloud.network.Network) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO) ArrayList(java.util.ArrayList) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 53 with ReservationContext

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

the class VpcManagerImpl method shutdownVpc.

@Override
public boolean shutdownVpc(final long vpcId) throws ConcurrentOperationException, ResourceUnavailableException {
    final CallContext ctx = CallContext.current();
    final Account caller = ctx.getCallingAccount();
    // check if vpc exists
    final Vpc vpc = _vpcDao.findById(vpcId);
    if (vpc == null) {
        throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId);
    }
    // permission check
    _accountMgr.checkAccess(caller, null, false, vpc);
    // shutdown provider
    s_logger.debug("Shutting down vpc " + vpc);
    // TODO - shutdown all vpc resources here (ACLs, gateways, etc)
    boolean success = true;
    final List<Provider> providersToImplement = getVpcProviders(vpc.getId());
    final ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(ctx.getCallingUserId()), caller);
    for (final VpcProvider element : getVpcElements()) {
        if (providersToImplement.contains(element.getProvider())) {
            if (element.shutdownVpc(vpc, context)) {
                s_logger.debug("Vpc " + vpc + " has been shutdown succesfully");
            } else {
                s_logger.warn("Vpc " + vpc + " failed to shutdown");
                success = false;
            }
        }
    }
    return success;
}
Also used : VpcProvider(com.cloud.network.element.VpcProvider) Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CallContext(org.apache.cloudstack.context.CallContext) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.network.Network.Provider) ReservationContext(com.cloud.vm.ReservationContext)

Example 54 with ReservationContext

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

the class NiciraNvpElementTest method implementSharedNetworkUuidVlanIdTest.

@Test
public void implementSharedNetworkUuidVlanIdTest() throws URISyntaxException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    // SHARED NETWORKS CASE 1: LOGICAL ROUTER'S UUID AS VLAN ID
    final Network network = mock(Network.class);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
    when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getGuestType()).thenReturn(GuestType.Shared);
    when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
    when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    when(device.getHostId()).thenReturn(NICIRA_NVP_HOST_ID);
    HostVO niciraNvpHost = mock(HostVO.class);
    when(niciraNvpHost.getId()).thenReturn(NICIRA_NVP_HOST_ID);
    when(hostDao.findById(NICIRA_NVP_HOST_ID)).thenReturn(niciraNvpHost);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Shared);
    final DeployDestination dest = mock(DeployDestination.class);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
    // SHARED NETWORKS CASE 1
    when(niciraNvpRouterMappingDao.existsMappingForNetworkId(NETWORK_ID)).thenReturn(true);
    when(network.getCidr()).thenReturn(NETWORK_CIDR);
    when(network.getGateway()).thenReturn(NETWORK_GATEWAY);
    NiciraNvpRouterMappingVO mapping = mock(NiciraNvpRouterMappingVO.class);
    when(mapping.getLogicalRouterUuid()).thenReturn("xxxx-xxxx-xxxx");
    when(niciraNvpRouterMappingDao.findByNetworkId(NETWORK_ID)).thenReturn(mapping);
    final ConfigureSharedNetworkUuidAnswer answer = mock(ConfigureSharedNetworkUuidAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentManager.easySend(eq(NICIRA_NVP_HOST_ID), (Command) any())).thenReturn(answer);
    assertTrue(element.implement(network, offering, dest, context));
}
Also used : Account(com.cloud.user.Account) ConfigureSharedNetworkUuidAnswer(com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer) NetworkOffering(com.cloud.offering.NetworkOffering) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) Domain(com.cloud.domain.Domain) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 55 with ReservationContext

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

the class NiciraNvpElementTest method implementIsolatedNetworkTest.

@Test
public void implementIsolatedNetworkTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, URISyntaxException {
    final Network network = mock(Network.class);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
    when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getGuestType()).thenReturn(GuestType.Isolated);
    when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
    when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    when(device.getHostId()).thenReturn(NICIRA_NVP_HOST_ID);
    HostVO niciraNvpHost = mock(HostVO.class);
    when(niciraNvpHost.getId()).thenReturn(NICIRA_NVP_HOST_ID);
    when(hostDao.findById(NICIRA_NVP_HOST_ID)).thenReturn(niciraNvpHost);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    final DeployDestination dest = mock(DeployDestination.class);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
    // ISOLATED NETWORK
    when(networkModel.isProviderSupportServiceInNetwork(NETWORK_ID, Service.SourceNat, Provider.NiciraNvp)).thenReturn(true);
    PublicIp sourceNatIp = mock(PublicIp.class);
    Ip ip = mock(Ip.class);
    when(ip.addr()).thenReturn("10.0.0.0");
    when(sourceNatIp.getAddress()).thenReturn(ip);
    when(sourceNatIp.getVlanNetmask()).thenReturn("255.255.255.0");
    when(sourceNatIp.getVlanTag()).thenReturn("111");
    when(ipAddressManager.assignSourceNatIpAddressToGuestNetwork(acc, network)).thenReturn(sourceNatIp);
    when(network.getGateway()).thenReturn(NETWORK_GATEWAY);
    when(network.getCidr()).thenReturn(NETWORK_CIDR);
    final CreateLogicalRouterAnswer answer = mock(CreateLogicalRouterAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentManager.easySend(eq(NICIRA_NVP_HOST_ID), (Command) any())).thenReturn(answer);
    assertTrue(element.implement(network, offering, dest, context));
}
Also used : Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) PublicIp(com.cloud.network.addr.PublicIp) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) Domain(com.cloud.domain.Domain) CreateLogicalRouterAnswer(com.cloud.agent.api.CreateLogicalRouterAnswer) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

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