Search in sources :

Example 1 with OvsDestroyTunnelCommand

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

the class OvsTunnelManagerImpl method checkAndRemoveHostFromTunnelNetwork.

@Override
public void checkAndRemoveHostFromTunnelNetwork(Network nw, Host host) {
    if (nw.getVpcId() != null && isVpcEnabledForDistributedRouter(nw.getVpcId())) {
        List<Long> vmIds = _ovsNetworkToplogyGuru.getActiveVmsInVpcOnHost(nw.getVpcId(), host.getId());
        if (vmIds != null && !vmIds.isEmpty()) {
            return;
        }
        // there are not active VM's on this host belonging to any of the tiers in the VPC, so remove
        // the host from the tunnel mesh network and destroy the bridge
        List<? extends Network> vpcNetworks = _vpcMgr.getVpcNetworks(nw.getVpcId());
        try {
            for (Network network : vpcNetworks) {
                int key = getGreKey(nw);
                String bridgeName = generateBridgeName(nw, key);
                /* Then ask hosts have peer tunnel with me to destroy them */
                List<OvsTunnelNetworkVO> peers = _tunnelNetworkDao.listByToNetwork(host.getId(), nw.getId());
                for (OvsTunnelNetworkVO p : peers) {
                    // If the tunnel was not successfully created don't bother to remove it
                    if (p.getState().equals(OvsTunnel.State.Established.name())) {
                        Command cmd = new OvsDestroyTunnelCommand(p.getNetworkId(), bridgeName, p.getPortName());
                        s_logger.debug("Destroying tunnel to " + host.getId() + " from " + p.getFrom());
                        Answer ans = _agentMgr.send(p.getFrom(), cmd);
                        handleDestroyTunnelAnswer(ans, p.getFrom(), p.getTo(), p.getNetworkId());
                    }
                }
            }
            Command cmd = new OvsDestroyBridgeCommand(nw.getId(), generateBridgeNameForVpc(nw.getVpcId()), host.getId());
            s_logger.debug("Destroying bridge for network " + nw.getId() + " on host:" + host.getId());
            Answer ans = _agentMgr.send(host.getId(), cmd);
            handleDestroyBridgeAnswer(ans, host.getId(), nw.getId());
        } catch (Exception e) {
            s_logger.info("[ignored]" + "exception while removing host from networks: " + e.getLocalizedMessage());
        }
    } else {
        List<Long> vmIds = _ovsNetworkToplogyGuru.getActiveVmsInNetworkOnHost(nw.getId(), host.getId(), true);
        if (vmIds != null && !vmIds.isEmpty()) {
            return;
        }
        try {
            /* Now we are last one on host, destroy the bridge with all
                * the tunnels for this network  */
            int key = getGreKey(nw);
            String bridgeName = generateBridgeName(nw, key);
            Command cmd = new OvsDestroyBridgeCommand(nw.getId(), bridgeName, host.getId());
            s_logger.debug("Destroying bridge for network " + nw.getId() + " on host:" + host.getId());
            Answer ans = _agentMgr.send(host.getId(), cmd);
            handleDestroyBridgeAnswer(ans, host.getId(), nw.getId());
            /* Then ask hosts have peer tunnel with me to destroy them */
            List<OvsTunnelNetworkVO> peers = _tunnelNetworkDao.listByToNetwork(host.getId(), nw.getId());
            for (OvsTunnelNetworkVO p : peers) {
                // If the tunnel was not successfully created don't bother to remove it
                if (p.getState().equals(OvsTunnel.State.Established.name())) {
                    cmd = new OvsDestroyTunnelCommand(p.getNetworkId(), bridgeName, p.getPortName());
                    s_logger.debug("Destroying tunnel to " + host.getId() + " from " + p.getFrom());
                    ans = _agentMgr.send(p.getFrom(), cmd);
                    handleDestroyTunnelAnswer(ans, p.getFrom(), p.getTo(), p.getNetworkId());
                }
            }
        } catch (Exception e) {
            s_logger.warn("Destroy tunnel failed", e);
        }
    }
}
Also used : OvsTunnelNetworkVO(com.cloud.network.ovs.dao.OvsTunnelNetworkVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) EntityExistsException(javax.persistence.EntityExistsException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) Answer(com.cloud.agent.api.Answer) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer) OvsCreateTunnelCommand(com.cloud.agent.api.OvsCreateTunnelCommand) OvsSetupBridgeCommand(com.cloud.agent.api.OvsSetupBridgeCommand) OvsDestroyBridgeCommand(com.cloud.agent.api.OvsDestroyBridgeCommand) OvsDestroyTunnelCommand(com.cloud.agent.api.OvsDestroyTunnelCommand) OvsFetchInterfaceCommand(com.cloud.agent.api.OvsFetchInterfaceCommand) OvsVpcPhysicalTopologyConfigCommand(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand) Command(com.cloud.agent.api.Command) OvsVpcRoutingPolicyConfigCommand(com.cloud.agent.api.OvsVpcRoutingPolicyConfigCommand) Network(com.cloud.network.Network) OvsDestroyBridgeCommand(com.cloud.agent.api.OvsDestroyBridgeCommand) OvsDestroyTunnelCommand(com.cloud.agent.api.OvsDestroyTunnelCommand)

Example 2 with OvsDestroyTunnelCommand

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

the class LibvirtComputingResourceTest method testOvsDestroyTunnelCommandFailure1.

@Test
public void testOvsDestroyTunnelCommandFailure1() {
    final String networkName = "Test";
    final Long networkId = 1l;
    final String inPortName = "eth";
    final OvsDestroyTunnelCommand command = new OvsDestroyTunnelCommand(networkId, networkName, inPortName);
    when(libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(false);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
}
Also used : 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) OvsDestroyTunnelCommand(com.cloud.agent.api.OvsDestroyTunnelCommand) Test(org.junit.Test)

Example 3 with OvsDestroyTunnelCommand

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

the class NotAValidCommand method testOvsDestroyTunnelCommandFailed.

@Test
public void testOvsDestroyTunnelCommandFailed() {
    final String bridge = "tunnel";
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsDestroyTunnelCommand destroyTunnel = new OvsDestroyTunnelCommand(1l, "net01", "port11");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.findOrCreateTunnelNetwork(conn, destroyTunnel.getBridgeName())).thenReturn(network);
        when(network.getBridge(conn)).thenReturn(bridge);
        when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "destroy_tunnel", "bridge", bridge, "in_port", destroyTunnel.getInPortName())).thenReturn("FAILED");
    } 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(destroyTunnel, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : 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) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) OvsDestroyTunnelCommand(com.cloud.agent.api.OvsDestroyTunnelCommand) Test(org.junit.Test)

Example 4 with OvsDestroyTunnelCommand

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

the class NotAValidCommand method testOvsDestroyTunnelCommandSuccess.

@Test
public void testOvsDestroyTunnelCommandSuccess() {
    final String bridge = "tunnel";
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsDestroyTunnelCommand destroyTunnel = new OvsDestroyTunnelCommand(1l, "net01", "port11");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.findOrCreateTunnelNetwork(conn, destroyTunnel.getBridgeName())).thenReturn(network);
        when(network.getBridge(conn)).thenReturn(bridge);
        when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "destroy_tunnel", "bridge", bridge, "in_port", destroyTunnel.getInPortName())).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(destroyTunnel, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : 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) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) OvsDestroyTunnelCommand(com.cloud.agent.api.OvsDestroyTunnelCommand) Test(org.junit.Test)

Example 5 with OvsDestroyTunnelCommand

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

the class LibvirtComputingResourceTest method testOvsDestroyTunnelCommand.

@Test
public void testOvsDestroyTunnelCommand() {
    final String networkName = "Test";
    final Long networkId = 1l;
    final String inPortName = "eth";
    final OvsDestroyTunnelCommand command = new OvsDestroyTunnelCommand(networkId, networkName, inPortName);
    when(libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(true);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
}
Also used : 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) OvsDestroyTunnelCommand(com.cloud.agent.api.OvsDestroyTunnelCommand) Test(org.junit.Test)

Aggregations

Answer (com.cloud.agent.api.Answer)6 OvsDestroyTunnelCommand (com.cloud.agent.api.OvsDestroyTunnelCommand)6 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)5 Test (org.junit.Test)5 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)3 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)3 RebootAnswer (com.cloud.agent.api.RebootAnswer)2 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)2 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)2 Connection (com.xensource.xenapi.Connection)2 Network (com.xensource.xenapi.Network)2 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)2 XenAPIException (com.xensource.xenapi.Types.XenAPIException)2 XmlRpcException (org.apache.xmlrpc.XmlRpcException)2 Command (com.cloud.agent.api.Command)1 OvsCreateTunnelAnswer (com.cloud.agent.api.OvsCreateTunnelAnswer)1 OvsCreateTunnelCommand (com.cloud.agent.api.OvsCreateTunnelCommand)1 OvsDestroyBridgeCommand (com.cloud.agent.api.OvsDestroyBridgeCommand)1 OvsFetchInterfaceAnswer (com.cloud.agent.api.OvsFetchInterfaceAnswer)1 OvsFetchInterfaceCommand (com.cloud.agent.api.OvsFetchInterfaceCommand)1