Search in sources :

Example 91 with NetworkVO

use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testTrash.

@Test
public void testTrash() {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getDataCenterId()).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);
    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 BrocadeVcsNetworkVlanMappingVO mapping = mock(BrocadeVcsNetworkVlanMappingVO.class);
    when(mapping.getVlanId()).thenReturn(14);
    when(vcsmapdao.findByNetworkId(anyLong())).thenReturn(mapping);
    final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
    when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
    final List<BrocadeVcsDeviceVO> devices = new ArrayList();
    devices.add(brocadeDevice);
    when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
    final DeleteNetworkAnswer answer = mock(DeleteNetworkAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    when(vcsdao.remove((long) anyInt())).thenReturn(true);
    final boolean result = guru.trash(network, offering);
    assertTrue(result == true);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DeleteNetworkAnswer(com.cloud.agent.api.DeleteNetworkAnswer) NetworkOffering(com.cloud.offering.NetworkOffering) BrocadeVcsNetworkVlanMappingVO(com.cloud.network.BrocadeVcsNetworkVlanMappingVO) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) Test(org.junit.Test)

Example 92 with NetworkVO

use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.

the class NiciraNvpElement method deleteNiciraNvpDevice.

@Override
public boolean deleteNiciraNvpDevice(DeleteNiciraNvpDeviceCmd cmd) {
    Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
    NiciraNvpDeviceVO niciraNvpDevice = niciraNvpDao.findById(niciraDeviceId);
    if (niciraNvpDevice == null) {
        throw new InvalidParameterValueException("Could not find a nicira device with id " + niciraDeviceId);
    }
    // Find the physical network we work for
    Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
    PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork != null) {
        // Lets see if there are networks that use us
        // Find the nicira networks on this physical network
        List<NetworkVO> networkList = networkDao.listByPhysicalNetwork(physicalNetworkId);
        if (networkList != null) {
            // Networks with broadcast type lswitch are ours
            for (NetworkVO network : networkList) {
                if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
                    if ((network.getState() != Network.State.Shutdown) && (network.getState() != Network.State.Destroy)) {
                        throw new CloudRuntimeException("This Nicira Nvp device can not be deleted as there are one or more logical networks provisioned by cloudstack.");
                    }
                }
            }
        }
    }
    HostVO niciraHost = hostDao.findById(niciraNvpDevice.getHostId());
    Long hostId = niciraHost.getId();
    niciraHost.setResourceState(ResourceState.Maintenance);
    hostDao.update(hostId, niciraHost);
    resourceMgr.deleteHost(hostId, false, false);
    niciraNvpDao.remove(niciraDeviceId);
    return true;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) HostVO(com.cloud.host.HostVO)

Example 93 with NetworkVO

use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.

the class ApplicationLoadBalancerTest method setUp.

@Override
@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    //mockito for .getApplicationLoadBalancer tests
    Mockito.when(_lbDao.findById(1L)).thenReturn(new ApplicationLoadBalancerRuleVO());
    Mockito.when(_lbDao.findById(2L)).thenReturn(null);
    //mockito for .deleteApplicationLoadBalancer tests
    Mockito.when(_lbService.deleteLoadBalancerRule(existingLbId, true)).thenReturn(true);
    Mockito.when(_lbService.deleteLoadBalancerRule(nonExistingLbId, true)).thenReturn(false);
    //mockito for .createApplicationLoadBalancer tests
    NetworkVO guestNetwork = new NetworkVO(TrafficType.Guest, null, null, 1, null, 1, 1L, false);
    setId(guestNetwork, validGuestNetworkId);
    guestNetwork.setCidr("10.1.1.1/24");
    NetworkVO publicNetwork = new NetworkVO(TrafficType.Public, null, null, 1, null, 1, 1L, false);
    Mockito.when(_ntwkModel.getNetwork(validGuestNetworkId)).thenReturn(guestNetwork);
    Mockito.when(_ntwkModel.getNetwork(invalidGuestNetworkId)).thenReturn(null);
    Mockito.when(_ntwkModel.getNetwork(validPublicNetworkId)).thenReturn(publicNetwork);
    Mockito.when(_accountMgr.getAccount(validAccountId)).thenReturn(new AccountVO());
    Mockito.when(_accountMgr.getAccount(invalidAccountId)).thenReturn(null);
    Mockito.when(_ntwkModel.areServicesSupportedInNetwork(validGuestNetworkId, Service.Lb)).thenReturn(true);
    Mockito.when(_ntwkModel.areServicesSupportedInNetwork(invalidGuestNetworkId, Service.Lb)).thenReturn(false);
    ApplicationLoadBalancerRuleVO lbRule = new ApplicationLoadBalancerRuleVO("new", "new", 22, 22, "roundrobin", validGuestNetworkId, validAccountId, 1L, new Ip(validRequestedIp), validGuestNetworkId, Scheme.Internal);
    Mockito.when(_lbDao.persist(Matchers.any(ApplicationLoadBalancerRuleVO.class))).thenReturn(lbRule);
    Mockito.when(_lbMgr.validateLbRule(Matchers.any(LoadBalancingRule.class))).thenReturn(true);
    Mockito.when(_firewallDao.setStateToAdd(Matchers.any(FirewallRuleVO.class))).thenReturn(true);
    Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1));
    Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
    CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
    Mockito.when(_ntwkModel.areServicesSupportedInNetwork(Matchers.anyLong(), Matchers.any(Network.Service.class))).thenReturn(true);
    Map<Network.Capability, String> caps = new HashMap<Network.Capability, String>();
    caps.put(Capability.SupportedProtocols, NetUtils.TCP_PROTO);
    Mockito.when(_ntwkModel.getNetworkServiceCapabilities(Matchers.anyLong(), Matchers.any(Network.Service.class))).thenReturn(caps);
    Mockito.when(_lbDao.countBySourceIp(new Ip(validRequestedIp), validGuestNetworkId)).thenReturn(1L);
}
Also used : ApplicationLoadBalancerRuleVO(org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO) NetworkVO(com.cloud.network.dao.NetworkVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) Ip(com.cloud.utils.net.Ip) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) LoadBalancingRulesService(com.cloud.network.lb.LoadBalancingRulesService) AccountVO(com.cloud.user.AccountVO) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) UserVO(com.cloud.user.UserVO) Network(com.cloud.network.Network) Before(org.junit.Before)

Example 94 with NetworkVO

use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.

the class NetworkACLManagerTest method driveTestApplyNetworkACL.

@SuppressWarnings("unchecked")
public void driveTestApplyNetworkACL(final boolean result, final boolean applyNetworkACLs, final boolean applyACLToPrivateGw) throws Exception {
    // In order to test ONLY our scope method, we mock the others
    final NetworkACLManager aclManager = Mockito.spy(_aclMgr);
    // Prepare
    // Reset mocked objects to reuse
    Mockito.reset(_networkACLItemDao);
    // Make sure it is handled
    final long aclId = 1L;
    final NetworkVO network = Mockito.mock(NetworkVO.class);
    final List<NetworkVO> networks = new ArrayList<NetworkVO>();
    networks.add(network);
    Mockito.when(_networkDao.listByAclId(Matchers.anyLong())).thenReturn(networks);
    Mockito.when(_networkDao.findById(Matchers.anyLong())).thenReturn(network);
    Mockito.when(_networkModel.isProviderSupportServiceInNetwork(Matchers.anyLong(), Matchers.any(Network.Service.class), Matchers.any(Network.Provider.class))).thenReturn(true);
    Mockito.when(_networkAclElements.get(0).applyNetworkACLs(Matchers.any(Network.class), Matchers.anyList())).thenReturn(applyNetworkACLs);
    // Make sure it applies ACL to private gateway
    final List<VpcGatewayVO> vpcGateways = new ArrayList<VpcGatewayVO>();
    final VpcGatewayVO vpcGateway = Mockito.mock(VpcGatewayVO.class);
    final PrivateGateway privateGateway = Mockito.mock(PrivateGateway.class);
    Mockito.when(_vpcSvc.getVpcPrivateGateway(Mockito.anyLong())).thenReturn(privateGateway);
    vpcGateways.add(vpcGateway);
    Mockito.when(_vpcGatewayDao.listByAclIdAndType(aclId, VpcGateway.Type.Private)).thenReturn(vpcGateways);
    // Create 4 rules to test all 4 scenarios: only revoke should
    // be deleted, only add should update
    final List<NetworkACLItemVO> rules = new ArrayList<NetworkACLItemVO>();
    final NetworkACLItemVO ruleActive = Mockito.mock(NetworkACLItemVO.class);
    final NetworkACLItemVO ruleStaged = Mockito.mock(NetworkACLItemVO.class);
    final NetworkACLItemVO rule2Revoke = Mockito.mock(NetworkACLItemVO.class);
    final NetworkACLItemVO rule2Add = Mockito.mock(NetworkACLItemVO.class);
    Mockito.when(ruleActive.getState()).thenReturn(NetworkACLItem.State.Active);
    Mockito.when(ruleStaged.getState()).thenReturn(NetworkACLItem.State.Staged);
    Mockito.when(rule2Add.getState()).thenReturn(NetworkACLItem.State.Add);
    Mockito.when(rule2Revoke.getState()).thenReturn(NetworkACLItem.State.Revoke);
    rules.add(ruleActive);
    rules.add(ruleStaged);
    rules.add(rule2Add);
    rules.add(rule2Revoke);
    final long revokeId = 8;
    Mockito.when(rule2Revoke.getId()).thenReturn(revokeId);
    final long addId = 9;
    Mockito.when(rule2Add.getId()).thenReturn(addId);
    Mockito.when(_networkACLItemDao.findById(addId)).thenReturn(rule2Add);
    Mockito.when(_networkACLItemDao.listByACL(aclId)).thenReturn(rules);
    // Mock methods to avoid
    Mockito.doReturn(applyACLToPrivateGw).when(aclManager).applyACLToPrivateGw(privateGateway);
    // Execute
    assertEquals("Result was not congruent with applyNetworkACLs and applyACLToPrivateGw", result, aclManager.applyNetworkACL(aclId));
    // Assert if conditions met, network ACL was applied
    final int timesProcessingDone = applyNetworkACLs && applyACLToPrivateGw ? 1 : 0;
    Mockito.verify(_networkACLItemDao, Mockito.times(timesProcessingDone)).remove(revokeId);
    Mockito.verify(rule2Add, Mockito.times(timesProcessingDone)).setState(NetworkACLItem.State.Active);
    Mockito.verify(_networkACLItemDao, Mockito.times(timesProcessingDone)).update(addId, rule2Add);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) VpcGatewayVO(com.cloud.network.vpc.VpcGatewayVO) ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) VpcService(com.cloud.network.vpc.VpcService) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) NetworkACLManager(com.cloud.network.vpc.NetworkACLManager) NetworkACLServiceProvider(com.cloud.network.element.NetworkACLServiceProvider) PrivateGateway(com.cloud.network.vpc.PrivateGateway) Network(com.cloud.network.Network)

Example 95 with NetworkVO

use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.

the class PaloAltoExternalFirewallElement method listNetworks.

@Override
public List<? extends Network> listNetworks(ListPaloAltoFirewallNetworksCmd cmd) {
    Long fwDeviceId = cmd.getFirewallDeviceId();
    List<NetworkVO> networks = new ArrayList<NetworkVO>();
    ExternalFirewallDeviceVO fwDeviceVo = _fwDevicesDao.findById(fwDeviceId);
    if (fwDeviceVo == null || !fwDeviceVo.getDeviceName().equalsIgnoreCase(NetworkDevice.PaloAltoFirewall.getName())) {
        throw new InvalidParameterValueException("Could not find Palo Alto firewall device with ID " + fwDeviceId);
    }
    List<NetworkExternalFirewallVO> networkFirewallMaps = _networkFirewallDao.listByFirewallDeviceId(fwDeviceId);
    if (networkFirewallMaps != null && !networkFirewallMaps.isEmpty()) {
        for (NetworkExternalFirewallVO networkFirewallMap : networkFirewallMaps) {
            NetworkVO network = _networkDao.findById(networkFirewallMap.getNetworkId());
            networks.add(network);
        }
    }
    return networks;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) ExternalFirewallDeviceVO(com.cloud.network.dao.ExternalFirewallDeviceVO) NetworkExternalFirewallVO(com.cloud.network.dao.NetworkExternalFirewallVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList)

Aggregations

NetworkVO (com.cloud.network.dao.NetworkVO)230 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)108 ArrayList (java.util.ArrayList)79 Test (org.junit.Test)56 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)55 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)49 Account (com.cloud.user.Account)44 Network (com.cloud.network.Network)39 DataCenterVO (com.cloud.dc.DataCenterVO)35 DataCenter (com.cloud.dc.DataCenter)34 NicVO (com.cloud.vm.NicVO)33 NicProfile (com.cloud.vm.NicProfile)27 HostVO (com.cloud.host.HostVO)24 NetworkOffering (com.cloud.offering.NetworkOffering)24 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)22 ReservationContext (com.cloud.vm.ReservationContext)22 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)20 DeployDestination (com.cloud.deploy.DeployDestination)19 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)19 NetworkGuru (com.cloud.network.guru.NetworkGuru)19