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