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);
}
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations