Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ public Answer execute(final FenceCommand command, final LibvirtComputingResource
final KVMHAMonitor monitor = libvirtComputingResource.getMonitor();

final List<NfsStoragePool> pools = monitor.getStoragePools();

/**
* We can only safely fence off hosts when we use NFS
* On NFS primary storage pools hosts continuesly write
* a heartbeat. Disable Fencing Off for hosts without NFS
*/
if (pools.size() == 0) {
String logline = "No NFS storage pools found. No way to safely fence " + command.getVmName() + " on host " + command.getHostGuid();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add an alert for admin here, _alertMgr.sendAlert?

s_logger.warn(logline);
return new FenceAnswer(command, false, logline);
}

final KVMHAChecker ha = new KVMHAChecker(pools, command.getHostIp());

final Future<Boolean> future = executors.submit(ha);
Expand Down
26 changes: 16 additions & 10 deletions server/src/com/cloud/ha/KVMFencer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.log4j.Logger;

import com.cloud.agent.AgentManager;
import com.cloud.alert.AlertManager;
import com.cloud.agent.api.FenceAnswer;
import com.cloud.agent.api.FenceCommand;
import com.cloud.exception.AgentUnavailableException;
Expand All @@ -48,6 +49,8 @@ public class KVMFencer extends AdapterBase implements FenceBuilder {
@Inject
AgentManager _agentMgr;
@Inject
AlertManager _alertMgr;
@Inject
ResourceManager _resourceMgr;

@Override
Expand Down Expand Up @@ -75,33 +78,33 @@ public KVMFencer() {
@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
if (host.getHypervisorType() != HypervisorType.KVM && host.getHypervisorType() != HypervisorType.LXC) {
s_logger.debug("Don't know how to fence non kvm hosts " + host.getHypervisorType());
s_logger.warn("Don't know how to fence non kvm hosts " + host.getHypervisorType());
return null;
}

List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(host.getClusterId());
FenceCommand fence = new FenceCommand(vm, host);

int i = 0;
for (HostVO h : hosts) {
if (h.getHypervisorType() == HypervisorType.KVM || h.getHypervisorType() == HypervisorType.LXC) {
if (h.getStatus() != Status.Up) {
continue;
}

i++;

if (h.getId() == host.getId()) {
continue;
}
FenceAnswer answer;
try {
answer = (FenceAnswer)_agentMgr.send(h.getId(), fence);
} catch (AgentUnavailableException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
}
s_logger.info("Moving on to the next host because " + h.toString() + " is unavailable");
continue;
} catch (OperationTimedoutException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
}
s_logger.info("Moving on to the next host because " + h.toString() + " is unavailable");
continue;
}
if (answer != null && answer.getResult()) {
Expand All @@ -110,9 +113,12 @@ public Boolean fenceOff(VirtualMachine vm, Host host) {
}
}

if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(),
"Unable to fence off host: " + host.getId(),
"Fencing off host " + host.getId() + " did not succeed after asking " + i + " hosts. " +
"Check Agent logs for more information.");

s_logger.error("Unable to fence off " + vm.toString() + " on " + host.toString());

return false;
}
Expand Down
22 changes: 22 additions & 0 deletions server/test/com/cloud/ha/KVMFencerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.mockito.runners.MockitoJUnitRunner;

import com.cloud.agent.AgentManager;
import com.cloud.alert.AlertManager;
import com.cloud.agent.api.FenceAnswer;
import com.cloud.agent.api.FenceCommand;
import com.cloud.exception.AgentUnavailableException;
Expand All @@ -50,6 +51,8 @@ public class KVMFencerTest {
@Mock
AgentManager agentManager;
@Mock
AlertManager alertMgr;
@Mock
ResourceManager resourceManager;

KVMFencer fencer;
Expand All @@ -58,6 +61,7 @@ public class KVMFencerTest {
public void setup() {
fencer = new KVMFencer();
fencer._agentMgr = agentManager;
fencer._alertMgr = alertMgr;
fencer._hostDao = hostDao;
fencer._resourceMgr = resourceManager;
}
Expand All @@ -67,6 +71,8 @@ public void testWithSingleHost() {
HostVO host = Mockito.mock(HostVO.class);
Mockito.when(host.getClusterId()).thenReturn(1l);
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(host.getDataCenterId()).thenReturn(1l);
Mockito.when(host.getPodId()).thenReturn(1l);
Mockito.when(host.getStatus()).thenReturn(Status.Up);
Mockito.when(host.getId()).thenReturn(1l);
VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
Expand All @@ -80,6 +86,8 @@ public void testWithSingleHostDown() {
HostVO host = Mockito.mock(HostVO.class);
Mockito.when(host.getClusterId()).thenReturn(1l);
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(host.getDataCenterId()).thenReturn(1l);
Mockito.when(host.getPodId()).thenReturn(1l);
Mockito.when(host.getStatus()).thenReturn(Status.Down);
Mockito.when(host.getId()).thenReturn(1l);
VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
Expand All @@ -94,12 +102,16 @@ public void testWithHosts() throws AgentUnavailableException, OperationTimedoutE
Mockito.when(host.getClusterId()).thenReturn(1l);
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(host.getStatus()).thenReturn(Status.Up);
Mockito.when(host.getDataCenterId()).thenReturn(1l);
Mockito.when(host.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(1l);

HostVO secondHost = Mockito.mock(HostVO.class);
Mockito.when(secondHost.getClusterId()).thenReturn(1l);
Mockito.when(secondHost.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(secondHost.getStatus()).thenReturn(Status.Up);
Mockito.when(secondHost.getDataCenterId()).thenReturn(1l);
Mockito.when(secondHost.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(2l);

VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
Expand All @@ -118,12 +130,16 @@ public void testWithFailingFence() throws AgentUnavailableException, OperationTi
Mockito.when(host.getClusterId()).thenReturn(1l);
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(host.getStatus()).thenReturn(Status.Up);
Mockito.when(host.getDataCenterId()).thenReturn(1l);
Mockito.when(host.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(1l);

HostVO secondHost = Mockito.mock(HostVO.class);
Mockito.when(secondHost.getClusterId()).thenReturn(1l);
Mockito.when(secondHost.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(secondHost.getStatus()).thenReturn(Status.Up);
Mockito.when(secondHost.getDataCenterId()).thenReturn(1l);
Mockito.when(secondHost.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(2l);

VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
Expand All @@ -141,12 +157,16 @@ public void testWithTimeoutingFence() throws AgentUnavailableException, Operatio
Mockito.when(host.getClusterId()).thenReturn(1l);
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(host.getStatus()).thenReturn(Status.Up);
Mockito.when(host.getDataCenterId()).thenReturn(1l);
Mockito.when(host.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(1l);

HostVO secondHost = Mockito.mock(HostVO.class);
Mockito.when(secondHost.getClusterId()).thenReturn(1l);
Mockito.when(secondHost.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(secondHost.getStatus()).thenReturn(Status.Up);
Mockito.when(secondHost.getDataCenterId()).thenReturn(1l);
Mockito.when(secondHost.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(2l);

VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
Expand All @@ -165,6 +185,8 @@ public void testWithSingleNotKVM() {
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.Any);
Mockito.when(host.getStatus()).thenReturn(Status.Down);
Mockito.when(host.getId()).thenReturn(1l);
Mockito.when(host.getDataCenterId()).thenReturn(1l);
Mockito.when(host.getPodId()).thenReturn(1l);
VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);

Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Collections.singletonList(host));
Expand Down