Search in sources :

Example 1 with OvsCreateTunnelCommand

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

the class LibvirtComputingResourceTest method testOvsCreateTunnelCommandFailure2.

@SuppressWarnings("unchecked")
@Test(expected = Exception.class)
public void testOvsCreateTunnelCommandFailure2() {
    final String remoteIp = "127.0.0.1";
    final Integer key = 1;
    final Long from = 1l;
    final Long to = 2l;
    final long networkId = 1l;
    final String fromIp = "127.0.0.1";
    final String networkName = "eth";
    final String networkUuid = "8edb1156-a851-4914-afc6-468ee52ac861";
    final OvsCreateTunnelCommand command = new OvsCreateTunnelCommand(remoteIp, key, from, to, networkId, fromIp, networkName, networkUuid);
    final String bridge = command.getNetworkName();
    when(libvirtComputingResource.findOrCreateTunnelNetwork(bridge)).thenReturn(true);
    when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getFrom(), command.getNetworkName())).thenThrow(Exception.class);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(bridge);
    verify(libvirtComputingResource, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getFrom(), command.getNetworkName());
}
Also used : 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) OvsCreateTunnelCommand(com.cloud.agent.api.OvsCreateTunnelCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with OvsCreateTunnelCommand

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

the class LibvirtComputingResourceTest method testOvsCreateTunnelCommandFailure1.

@Test
public void testOvsCreateTunnelCommandFailure1() {
    final String remoteIp = "127.0.0.1";
    final Integer key = 1;
    final Long from = 1l;
    final Long to = 2l;
    final long networkId = 1l;
    final String fromIp = "127.0.0.1";
    final String networkName = "eth";
    final String networkUuid = "8edb1156-a851-4914-afc6-468ee52ac861";
    final OvsCreateTunnelCommand command = new OvsCreateTunnelCommand(remoteIp, key, from, to, networkId, fromIp, networkName, networkUuid);
    final String bridge = command.getNetworkName();
    when(libvirtComputingResource.findOrCreateTunnelNetwork(bridge)).thenReturn(false);
    when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getFrom(), command.getNetworkName())).thenReturn(true);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(bridge);
    verify(libvirtComputingResource, times(0)).configureTunnelNetwork(command.getNetworkId(), command.getFrom(), command.getNetworkName());
}
Also used : 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) OvsCreateTunnelCommand(com.cloud.agent.api.OvsCreateTunnelCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with OvsCreateTunnelCommand

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

the class OvsTunnelManagerImpl method checkAndCreateTunnel.

@DB
protected void checkAndCreateTunnel(Network nw, Host host) {
    s_logger.debug("Creating tunnels with OVS tunnel manager");
    long hostId = host.getId();
    int key = getGreKey(nw);
    String bridgeName = generateBridgeName(nw, key);
    List<Long> toHostIds = new ArrayList<Long>();
    List<Long> fromHostIds = new ArrayList<Long>();
    List<Long> networkSpannedHosts = _ovsNetworkToplogyGuru.getNetworkSpanedHosts(nw.getId());
    for (Long rh : networkSpannedHosts) {
        if (rh == hostId) {
            continue;
        }
        OvsTunnelNetworkVO ta = _tunnelNetworkDao.findByFromToNetwork(hostId, rh.longValue(), nw.getId());
        // Try and create the tunnel even if a previous attempt failed
        if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) {
            s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + rh.longValue());
            if (ta == null) {
                createTunnelRecord(hostId, rh.longValue(), nw.getId(), key);
            }
            if (!toHostIds.contains(rh)) {
                toHostIds.add(rh);
            }
        }
        ta = _tunnelNetworkDao.findByFromToNetwork(rh.longValue(), hostId, nw.getId());
        // Try and create the tunnel even if a previous attempt failed
        if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) {
            s_logger.debug("Attempting to create tunnel from:" + rh.longValue() + " to:" + hostId);
            if (ta == null) {
                createTunnelRecord(rh.longValue(), hostId, nw.getId(), key);
            }
            if (!fromHostIds.contains(rh)) {
                fromHostIds.add(rh);
            }
        }
    }
    // TODO: Should we propagate the exception here?
    try {
        String myIp = getGreEndpointIP(host, nw);
        if (myIp == null)
            throw new GreTunnelException("Unable to retrieve the source " + "endpoint for the GRE tunnel." + "Failure is on host:" + host.getId());
        boolean noHost = true;
        for (Long i : toHostIds) {
            HostVO rHost = _hostDao.findById(i);
            String otherIp = getGreEndpointIP(rHost, nw);
            if (otherIp == null)
                throw new GreTunnelException("Unable to retrieve the remote " + "endpoint for the GRE tunnel." + "Failure is on host:" + rHost.getId());
            Commands cmds = new Commands(new OvsCreateTunnelCommand(otherIp, key, Long.valueOf(hostId), i, nw.getId(), myIp, bridgeName, nw.getUuid()));
            s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + i + " for the network " + nw.getId());
            s_logger.debug("Ask host " + hostId + " to create gre tunnel to " + i);
            Answer[] answers = _agentMgr.send(hostId, cmds);
            handleCreateTunnelAnswer(answers);
            noHost = false;
        }
        for (Long i : fromHostIds) {
            HostVO rHost = _hostDao.findById(i);
            String otherIp = getGreEndpointIP(rHost, nw);
            Commands cmds = new Commands(new OvsCreateTunnelCommand(myIp, key, i, Long.valueOf(hostId), nw.getId(), otherIp, bridgeName, nw.getUuid()));
            s_logger.debug("Ask host " + i + " to create gre tunnel to " + hostId);
            Answer[] answers = _agentMgr.send(i, cmds);
            handleCreateTunnelAnswer(answers);
            noHost = false;
        }
        // anyway. This will ensure VIF rules will be triggered
        if (noHost) {
            Commands cmds = new Commands(new OvsSetupBridgeCommand(bridgeName, hostId, nw.getId()));
            s_logger.debug("Ask host " + hostId + " to configure bridge for network:" + nw.getId());
            Answer[] answers = _agentMgr.send(hostId, cmds);
            handleSetupBridgeAnswer(answers);
        }
    } catch (GreTunnelException | OperationTimedoutException | AgentUnavailableException e) {
        // I really thing we should do a better handling of these exceptions
        s_logger.warn("Ovs Tunnel network created tunnel failed", e);
    }
}
Also used : OvsTunnelNetworkVO(com.cloud.network.ovs.dao.OvsTunnelNetworkVO) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) OvsCreateTunnelCommand(com.cloud.agent.api.OvsCreateTunnelCommand) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) Answer(com.cloud.agent.api.Answer) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) OvsSetupBridgeCommand(com.cloud.agent.api.OvsSetupBridgeCommand) DB(com.cloud.utils.db.DB)

Example 4 with OvsCreateTunnelCommand

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

the class NotAValidCommand method testOvsCreateTunnelCommandFail.

@Test
public void testOvsCreateTunnelCommandFail() {
    final String bridge = "tunnel";
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsCreateTunnelCommand createTunnel = new OvsCreateTunnelCommand("127.0.0.1", 1, 1l, 2l, 1l, "127.0.1.1", "net01", "cd84c713-f448-48c9-ba25-e6740d4a9003");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.findOrCreateTunnelNetwork(conn, createTunnel.getNetworkName())).thenReturn(network);
        when(network.getBridge(conn)).thenReturn(bridge);
        when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "create_tunnel", "bridge", bridge, "remote_ip", createTunnel.getRemoteIp(), "key", createTunnel.getKey().toString(), "from", createTunnel.getFrom().toString(), "to", createTunnel.getTo().toString(), "cloudstack-network-id", createTunnel.getNetworkUuid())).thenReturn("FAIL:1");
    } 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(createTunnel, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    verify(citrixResourceBase, times(1)).configureTunnelNetwork(conn, createTunnel.getNetworkId(), createTunnel.getFrom(), createTunnel.getNetworkName());
    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) OvsCreateTunnelCommand(com.cloud.agent.api.OvsCreateTunnelCommand) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with OvsCreateTunnelCommand

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

the class NotAValidCommand method testOvsCreateTunnelCommandSuccess.

@Test
public void testOvsCreateTunnelCommandSuccess() {
    final String bridge = "tunnel";
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsCreateTunnelCommand createTunnel = new OvsCreateTunnelCommand("127.0.0.1", 1, 1l, 2l, 1l, "127.0.1.1", "net01", "cd84c713-f448-48c9-ba25-e6740d4a9003");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.findOrCreateTunnelNetwork(conn, createTunnel.getNetworkName())).thenReturn(network);
        when(network.getBridge(conn)).thenReturn(bridge);
        when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "create_tunnel", "bridge", bridge, "remote_ip", createTunnel.getRemoteIp(), "key", createTunnel.getKey().toString(), "from", createTunnel.getFrom().toString(), "to", createTunnel.getTo().toString(), "cloudstack-network-id", createTunnel.getNetworkUuid())).thenReturn("SUCCESS:0");
    } 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(createTunnel, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    verify(citrixResourceBase, times(1)).configureTunnelNetwork(conn, createTunnel.getNetworkId(), createTunnel.getFrom(), createTunnel.getNetworkName());
    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) OvsCreateTunnelCommand(com.cloud.agent.api.OvsCreateTunnelCommand) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Answer (com.cloud.agent.api.Answer)8 OvsCreateTunnelCommand (com.cloud.agent.api.OvsCreateTunnelCommand)8 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)6 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)3 RebootAnswer (com.cloud.agent.api.RebootAnswer)3 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)3 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)3 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)3 Connection (com.xensource.xenapi.Connection)3 OvsCreateTunnelAnswer (com.cloud.agent.api.OvsCreateTunnelAnswer)2 OvsFetchInterfaceAnswer (com.cloud.agent.api.OvsFetchInterfaceAnswer)2 OvsSetupBridgeCommand (com.cloud.agent.api.OvsSetupBridgeCommand)2 Commands (com.cloud.agent.manager.Commands)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)2 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)2 HostVO (com.cloud.host.HostVO)2 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)2 OvsTunnelNetworkVO (com.cloud.network.ovs.dao.OvsTunnelNetworkVO)2