Skip to content

Commit fbe3b04

Browse files
committed
CLOUDSTACK-8628: Send an alert when fencing a KVM host failed
Also change the logging a bit so that you get useful logs when not running on DEBUG level Signed-off-by: Wido den Hollander <wido@widodh.nl> This closes apache#580
1 parent d1f76a2 commit fbe3b04

2 files changed

Lines changed: 38 additions & 10 deletions

File tree

‎server/src/com/cloud/ha/KVMFencer.java‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.log4j.Logger;
2727

2828
import com.cloud.agent.AgentManager;
29+
import com.cloud.alert.AlertManager;
2930
import com.cloud.agent.api.FenceAnswer;
3031
import com.cloud.agent.api.FenceCommand;
3132
import com.cloud.exception.AgentUnavailableException;
@@ -48,6 +49,8 @@ public class KVMFencer extends AdapterBase implements FenceBuilder {
4849
@Inject
4950
AgentManager _agentMgr;
5051
@Inject
52+
AlertManager _alertMgr;
53+
@Inject
5154
ResourceManager _resourceMgr;
5255

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

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

88+
int i = 0;
8589
for (HostVO h : hosts) {
8690
if (h.getHypervisorType() == HypervisorType.KVM || h.getHypervisorType() == HypervisorType.LXC) {
8791
if (h.getStatus() != Status.Up) {
8892
continue;
8993
}
94+
95+
i++;
96+
9097
if (h.getId() == host.getId()) {
9198
continue;
9299
}
93100
FenceAnswer answer;
94101
try {
95102
answer = (FenceAnswer)_agentMgr.send(h.getId(), fence);
96103
} catch (AgentUnavailableException e) {
97-
if (s_logger.isDebugEnabled()) {
98-
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
99-
}
104+
s_logger.info("Moving on to the next host because " + h.toString() + " is unavailable");
100105
continue;
101106
} catch (OperationTimedoutException e) {
102-
if (s_logger.isDebugEnabled()) {
103-
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
104-
}
107+
s_logger.info("Moving on to the next host because " + h.toString() + " is unavailable");
105108
continue;
106109
}
107110
if (answer != null && answer.getResult()) {
@@ -110,9 +113,12 @@ public Boolean fenceOff(VirtualMachine vm, Host host) {
110113
}
111114
}
112115

113-
if (s_logger.isDebugEnabled()) {
114-
s_logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
115-
}
116+
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(),
117+
"Unable to fence off host: " + host.getId(),
118+
"Fencing off host " + host.getId() + " did not succeed after asking " + i + " hosts. " +
119+
"Check Agent logs for more information.");
120+
121+
s_logger.error("Unable to fence off " + vm.toString() + " on " + host.toString());
116122

117123
return false;
118124
}

‎server/test/com/cloud/ha/KVMFencerTest.java‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.mockito.runners.MockitoJUnitRunner;
3232

3333
import com.cloud.agent.AgentManager;
34+
import com.cloud.alert.AlertManager;
3435
import com.cloud.agent.api.FenceAnswer;
3536
import com.cloud.agent.api.FenceCommand;
3637
import com.cloud.exception.AgentUnavailableException;
@@ -50,6 +51,8 @@ public class KVMFencerTest {
5051
@Mock
5152
AgentManager agentManager;
5253
@Mock
54+
AlertManager alertMgr;
55+
@Mock
5356
ResourceManager resourceManager;
5457

5558
KVMFencer fencer;
@@ -58,6 +61,7 @@ public class KVMFencerTest {
5861
public void setup() {
5962
fencer = new KVMFencer();
6063
fencer._agentMgr = agentManager;
64+
fencer._alertMgr = alertMgr;
6165
fencer._hostDao = hostDao;
6266
fencer._resourceMgr = resourceManager;
6367
}
@@ -67,6 +71,8 @@ public void testWithSingleHost() {
6771
HostVO host = Mockito.mock(HostVO.class);
6872
Mockito.when(host.getClusterId()).thenReturn(1l);
6973
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
74+
Mockito.when(host.getDataCenterId()).thenReturn(1l);
75+
Mockito.when(host.getPodId()).thenReturn(1l);
7076
Mockito.when(host.getStatus()).thenReturn(Status.Up);
7177
Mockito.when(host.getId()).thenReturn(1l);
7278
VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
@@ -80,6 +86,8 @@ public void testWithSingleHostDown() {
8086
HostVO host = Mockito.mock(HostVO.class);
8187
Mockito.when(host.getClusterId()).thenReturn(1l);
8288
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
89+
Mockito.when(host.getDataCenterId()).thenReturn(1l);
90+
Mockito.when(host.getPodId()).thenReturn(1l);
8391
Mockito.when(host.getStatus()).thenReturn(Status.Down);
8492
Mockito.when(host.getId()).thenReturn(1l);
8593
VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
@@ -94,12 +102,16 @@ public void testWithHosts() throws AgentUnavailableException, OperationTimedoutE
94102
Mockito.when(host.getClusterId()).thenReturn(1l);
95103
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
96104
Mockito.when(host.getStatus()).thenReturn(Status.Up);
105+
Mockito.when(host.getDataCenterId()).thenReturn(1l);
106+
Mockito.when(host.getPodId()).thenReturn(1l);
97107
Mockito.when(host.getId()).thenReturn(1l);
98108

99109
HostVO secondHost = Mockito.mock(HostVO.class);
100110
Mockito.when(secondHost.getClusterId()).thenReturn(1l);
101111
Mockito.when(secondHost.getHypervisorType()).thenReturn(HypervisorType.KVM);
102112
Mockito.when(secondHost.getStatus()).thenReturn(Status.Up);
113+
Mockito.when(secondHost.getDataCenterId()).thenReturn(1l);
114+
Mockito.when(secondHost.getPodId()).thenReturn(1l);
103115
Mockito.when(host.getId()).thenReturn(2l);
104116

105117
VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
@@ -118,12 +130,16 @@ public void testWithFailingFence() throws AgentUnavailableException, OperationTi
118130
Mockito.when(host.getClusterId()).thenReturn(1l);
119131
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
120132
Mockito.when(host.getStatus()).thenReturn(Status.Up);
133+
Mockito.when(host.getDataCenterId()).thenReturn(1l);
134+
Mockito.when(host.getPodId()).thenReturn(1l);
121135
Mockito.when(host.getId()).thenReturn(1l);
122136

123137
HostVO secondHost = Mockito.mock(HostVO.class);
124138
Mockito.when(secondHost.getClusterId()).thenReturn(1l);
125139
Mockito.when(secondHost.getHypervisorType()).thenReturn(HypervisorType.KVM);
126140
Mockito.when(secondHost.getStatus()).thenReturn(Status.Up);
141+
Mockito.when(secondHost.getDataCenterId()).thenReturn(1l);
142+
Mockito.when(secondHost.getPodId()).thenReturn(1l);
127143
Mockito.when(host.getId()).thenReturn(2l);
128144

129145
VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
@@ -141,12 +157,16 @@ public void testWithTimeoutingFence() throws AgentUnavailableException, Operatio
141157
Mockito.when(host.getClusterId()).thenReturn(1l);
142158
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
143159
Mockito.when(host.getStatus()).thenReturn(Status.Up);
160+
Mockito.when(host.getDataCenterId()).thenReturn(1l);
161+
Mockito.when(host.getPodId()).thenReturn(1l);
144162
Mockito.when(host.getId()).thenReturn(1l);
145163

146164
HostVO secondHost = Mockito.mock(HostVO.class);
147165
Mockito.when(secondHost.getClusterId()).thenReturn(1l);
148166
Mockito.when(secondHost.getHypervisorType()).thenReturn(HypervisorType.KVM);
149167
Mockito.when(secondHost.getStatus()).thenReturn(Status.Up);
168+
Mockito.when(secondHost.getDataCenterId()).thenReturn(1l);
169+
Mockito.when(secondHost.getPodId()).thenReturn(1l);
150170
Mockito.when(host.getId()).thenReturn(2l);
151171

152172
VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
@@ -165,6 +185,8 @@ public void testWithSingleNotKVM() {
165185
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.Any);
166186
Mockito.when(host.getStatus()).thenReturn(Status.Down);
167187
Mockito.when(host.getId()).thenReturn(1l);
188+
Mockito.when(host.getDataCenterId()).thenReturn(1l);
189+
Mockito.when(host.getPodId()).thenReturn(1l);
168190
VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
169191

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

0 commit comments

Comments
 (0)