Search in sources :

Example 1 with OvsDestroyBridgeCommand

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

the class NotAValidCommand method testOvsDestroyBridgeCommand.

@Test
public void testOvsDestroyBridgeCommand() {
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsDestroyBridgeCommand destroyBridge = new OvsDestroyBridgeCommand(1l, "bridge", 1l);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    when(citrixResourceBase.findOrCreateTunnelNetwork(conn, destroyBridge.getBridgeName())).thenReturn(network);
    final Answer answer = wrapper.execute(destroyBridge, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    try {
        verify(citrixResourceBase, times(1)).cleanUpTmpDomVif(conn, network);
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    verify(citrixResourceBase, times(1)).destroyTunnelNetwork(conn, network, destroyBridge.getHostId());
    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) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsDestroyBridgeCommand(com.cloud.agent.api.OvsDestroyBridgeCommand) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test)

Example 2 with OvsDestroyBridgeCommand

use of com.cloud.agent.api.OvsDestroyBridgeCommand 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 3 with OvsDestroyBridgeCommand

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

the class LibvirtComputingResourceTest method testOvsDestroyBridgeCommand.

@Test
public void testOvsDestroyBridgeCommand() {
    final String name = "Test";
    final Long hostId = 1l;
    final Long networkId = 1l;
    final OvsDestroyBridgeCommand command = new OvsDestroyBridgeCommand(networkId, name, hostId);
    when(libvirtComputingResource.destroyTunnelNetwork(command.getBridgeName())).thenReturn(true);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(libvirtComputingResource, times(1)).destroyTunnelNetwork(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) OvsDestroyBridgeCommand(com.cloud.agent.api.OvsDestroyBridgeCommand) Test(org.junit.Test)

Example 4 with OvsDestroyBridgeCommand

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

the class LibvirtComputingResourceTest method testOvsDestroyBridgeCommandFailure.

@Test
public void testOvsDestroyBridgeCommandFailure() {
    final String name = "Test";
    final Long hostId = 1l;
    final Long networkId = 1l;
    final OvsDestroyBridgeCommand command = new OvsDestroyBridgeCommand(networkId, name, hostId);
    when(libvirtComputingResource.destroyTunnelNetwork(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)).destroyTunnelNetwork(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) OvsDestroyBridgeCommand(com.cloud.agent.api.OvsDestroyBridgeCommand) Test(org.junit.Test)

Aggregations

Answer (com.cloud.agent.api.Answer)4 OvsDestroyBridgeCommand (com.cloud.agent.api.OvsDestroyBridgeCommand)4 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)3 Test (org.junit.Test)3 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)2 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)2 Command (com.cloud.agent.api.Command)1 OvsCreateTunnelAnswer (com.cloud.agent.api.OvsCreateTunnelAnswer)1 OvsCreateTunnelCommand (com.cloud.agent.api.OvsCreateTunnelCommand)1 OvsDestroyTunnelCommand (com.cloud.agent.api.OvsDestroyTunnelCommand)1 OvsFetchInterfaceAnswer (com.cloud.agent.api.OvsFetchInterfaceAnswer)1 OvsFetchInterfaceCommand (com.cloud.agent.api.OvsFetchInterfaceCommand)1 OvsSetupBridgeCommand (com.cloud.agent.api.OvsSetupBridgeCommand)1 OvsVpcPhysicalTopologyConfigCommand (com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand)1 OvsVpcRoutingPolicyConfigCommand (com.cloud.agent.api.OvsVpcRoutingPolicyConfigCommand)1 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 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)1