Search in sources :

Example 1 with OvsVpcPhysicalTopologyConfigCommand

use of com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand in project cloudstack by apache.

the class LibvirtComputingResourceTest method testOvsVpcPhysicalTopologyConfigCommandFailure.

@SuppressWarnings("unchecked")
@Test(expected = Exception.class)
public void testOvsVpcPhysicalTopologyConfigCommandFailure() {
    final Host[] hosts = null;
    final Tier[] tiers = null;
    final Vm[] vms = null;
    final String cidr = null;
    final OvsVpcPhysicalTopologyConfigCommand command = new OvsVpcPhysicalTopologyConfigCommand(hosts, tiers, vms, cidr);
    when(libvirtComputingResource.getOvsTunnelPath()).thenThrow(Exception.class);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getOvsTunnelPath();
}
Also used : OvsVpcPhysicalTopologyConfigCommand(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand) UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) Tier(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand.Tier) Vm(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand.Vm) Host(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand.Host) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with OvsVpcPhysicalTopologyConfigCommand

use of com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand in project cloudstack by apache.

the class OvsTunnelManagerImpl method handleVmStateChange.

private void handleVmStateChange(VMInstanceVO vm) {
    // get the VPC's impacted with the VM start
    List<Long> vpcIds = _ovsNetworkToplogyGuru.getVpcIdsVmIsPartOf(vm.getId());
    if (vpcIds == null || vpcIds.isEmpty()) {
        return;
    }
    for (Long vpcId : vpcIds) {
        VpcVO vpc = _vpcDao.findById(vpcId);
        // nothing to do if the VPC is not setup for distributed routing
        if (vpc == null || !vpc.usesDistributedRouter()) {
            return;
        }
        // get the list of hosts on which VPC spans (i.e hosts that need to be aware of VPC topology change update)
        List<Long> vpcSpannedHostIds = _ovsNetworkToplogyGuru.getVpcSpannedHosts(vpcId);
        String bridgeName = generateBridgeNameForVpc(vpcId);
        OvsVpcPhysicalTopologyConfigCommand topologyConfigCommand = prepareVpcTopologyUpdate(vpcId);
        topologyConfigCommand.setSequenceNumber(getNextTopologyUpdateSequenceNumber(vpcId));
        // send topology change update to VPC spanned hosts
        for (Long id : vpcSpannedHostIds) {
            if (!sendVpcTopologyChangeUpdate(topologyConfigCommand, id, bridgeName)) {
                s_logger.debug("Failed to send VPC topology change update to host : " + id + ". Moving on " + "with rest of the host update.");
            }
        }
    }
}
Also used : OvsVpcPhysicalTopologyConfigCommand(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand) VpcVO(com.cloud.network.vpc.VpcVO)

Example 3 with OvsVpcPhysicalTopologyConfigCommand

use of com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand in project cloudstack by apache.

the class OvsTunnelManagerImpl method prepareVpcTopologyUpdate.

OvsVpcPhysicalTopologyConfigCommand prepareVpcTopologyUpdate(long vpcId) {
    VpcVO vpc = _vpcDao.findById(vpcId);
    assert (vpc != null) : "invalid vpc id";
    List<? extends Network> vpcNetworks = _vpcMgr.getVpcNetworks(vpcId);
    List<Long> hostIds = _ovsNetworkToplogyGuru.getVpcSpannedHosts(vpcId);
    List<Long> vmIds = _ovsNetworkToplogyGuru.getAllActiveVmsInVpc(vpcId);
    List<OvsVpcPhysicalTopologyConfigCommand.Host> hosts = new ArrayList<>();
    List<OvsVpcPhysicalTopologyConfigCommand.Tier> tiers = new ArrayList<>();
    List<OvsVpcPhysicalTopologyConfigCommand.Vm> vms = new ArrayList<>();
    for (Long hostId : hostIds) {
        HostVO hostDetails = _hostDao.findById(hostId);
        String remoteIp = null;
        for (Network network : vpcNetworks) {
            try {
                remoteIp = getGreEndpointIP(hostDetails, network);
            } catch (Exception e) {
                s_logger.info("[ignored]" + "error getting GRE endpoint: " + e.getLocalizedMessage());
            }
        }
        OvsVpcPhysicalTopologyConfigCommand.Host host = new OvsVpcPhysicalTopologyConfigCommand.Host(hostId, remoteIp);
        hosts.add(host);
    }
    for (Network network : vpcNetworks) {
        String key = network.getBroadcastUri().getAuthority();
        long gre_key;
        if (key.contains(".")) {
            String[] parts = key.split("\\.");
            gre_key = Long.parseLong(parts[1]);
        } else {
            try {
                gre_key = Long.parseLong(BroadcastDomainType.getValue(key));
            } catch (Exception e) {
                return null;
            }
        }
        NicVO nic = _nicDao.findByIp4AddressAndNetworkId(network.getGateway(), network.getId());
        OvsVpcPhysicalTopologyConfigCommand.Tier tier = new OvsVpcPhysicalTopologyConfigCommand.Tier(gre_key, network.getUuid(), network.getGateway(), nic.getMacAddress(), network.getCidr());
        tiers.add(tier);
    }
    for (long vmId : vmIds) {
        VirtualMachine vmInstance = _vmInstanceDao.findById(vmId);
        List<OvsVpcPhysicalTopologyConfigCommand.Nic> vmNics = new ArrayList<OvsVpcPhysicalTopologyConfigCommand.Nic>();
        for (Nic vmNic : _nicDao.listByVmId(vmId)) {
            Network network = _networkDao.findById(vmNic.getNetworkId());
            if (network.getTrafficType() == TrafficType.Guest) {
                OvsVpcPhysicalTopologyConfigCommand.Nic nic = new OvsVpcPhysicalTopologyConfigCommand.Nic(vmNic.getIPv4Address(), vmNic.getMacAddress(), network.getUuid());
                vmNics.add(nic);
            }
        }
        OvsVpcPhysicalTopologyConfigCommand.Vm vm = new OvsVpcPhysicalTopologyConfigCommand.Vm(vmInstance.getHostId(), vmNics.toArray(new OvsVpcPhysicalTopologyConfigCommand.Nic[vmNics.size()]));
        vms.add(vm);
    }
    return new OvsVpcPhysicalTopologyConfigCommand(hosts.toArray(new OvsVpcPhysicalTopologyConfigCommand.Host[hosts.size()]), tiers.toArray(new OvsVpcPhysicalTopologyConfigCommand.Tier[tiers.size()]), vms.toArray(new OvsVpcPhysicalTopologyConfigCommand.Vm[vms.size()]), vpc.getCidr());
}
Also used : ArrayList(java.util.ArrayList) Network(com.cloud.network.Network) NicVO(com.cloud.vm.NicVO) OvsVpcPhysicalTopologyConfigCommand(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand) Nic(com.cloud.vm.Nic) Host(com.cloud.host.Host) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) EntityExistsException(javax.persistence.EntityExistsException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VpcVO(com.cloud.network.vpc.VpcVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 4 with OvsVpcPhysicalTopologyConfigCommand

use of com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand in project cloudstack by apache.

the class NotAValidCommand method testOvsVpcPhysicalTopologyConfigCommand.

@Test
public void testOvsVpcPhysicalTopologyConfigCommand() {
    final String bridge = "gre";
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsVpcPhysicalTopologyConfigCommand.Host[] hosts = new OvsVpcPhysicalTopologyConfigCommand.Host[0];
    final OvsVpcPhysicalTopologyConfigCommand.Tier[] tiers = new OvsVpcPhysicalTopologyConfigCommand.Tier[0];
    final OvsVpcPhysicalTopologyConfigCommand.Vm[] vms = new OvsVpcPhysicalTopologyConfigCommand.Vm[0];
    final OvsVpcPhysicalTopologyConfigCommand physicalTopology = new OvsVpcPhysicalTopologyConfigCommand(hosts, tiers, vms, "10.0.0.1/24");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.findOrCreateTunnelNetwork(conn, physicalTopology.getBridgeName())).thenReturn(network);
        when(network.getBridge(conn)).thenReturn(bridge);
        when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "configure_ovs_bridge_for_network_topology", "bridge", bridge, "config", physicalTopology.getVpcConfigInJson(), "host-id", ((Long) physicalTopology.getHostId()).toString(), "seq-no", Long.toString(1))).thenReturn("SUCCESS");
    } catch (final BadServerResponse e) {
        fail(e.getMessage());
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(physicalTopology, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : OvsVpcPhysicalTopologyConfigCommand(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Host(com.xensource.xenapi.Host) RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with OvsVpcPhysicalTopologyConfigCommand

use of com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand in project cloudstack by apache.

the class LibvirtComputingResourceTest method testOvsVpcPhysicalTopologyConfigCommand.

@Test
public void testOvsVpcPhysicalTopologyConfigCommand() {
    final Host[] hosts = null;
    final Tier[] tiers = null;
    final Vm[] vms = null;
    final String cidr = null;
    final OvsVpcPhysicalTopologyConfigCommand command = new OvsVpcPhysicalTopologyConfigCommand(hosts, tiers, vms, cidr);
    when(libvirtComputingResource.getOvsTunnelPath()).thenReturn("/path");
    when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getOvsTunnelPath();
    verify(libvirtComputingResource, times(1)).getTimeout();
}
Also used : OvsVpcPhysicalTopologyConfigCommand(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand) UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) Tier(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand.Tier) Vm(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand.Vm) Host(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand.Host) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

OvsVpcPhysicalTopologyConfigCommand (com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand)5 Answer (com.cloud.agent.api.Answer)3 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)2 Host (com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand.Host)2 Tier (com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand.Tier)2 Vm (com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand.Vm)2 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)2 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)2 VpcVO (com.cloud.network.vpc.VpcVO)2 RebootAnswer (com.cloud.agent.api.RebootAnswer)1 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 Host (com.cloud.host.Host)1 HostVO (com.cloud.host.HostVO)1 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)1 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)1