Skip to content
Open
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
10 changes: 10 additions & 0 deletions server/src/main/java/com/cloud/ha/HighAvailabilityManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ public boolean scheduleMigration(final VMInstanceVO vm) {

@Override
public void scheduleRestart(VMInstanceVO vm, boolean investigate, ReasonType reasonType) {
if (VirtualMachine.State.Error.equals(vm.getState())) {
logger.info("Skipping HA restart for VM {} because it is in Error state", vm);
return;
}

if (!VmHaEnabled.valueIn(vm.getDataCenterId())) {
String message = String.format("Unable to schedule restart for the VM %s (%d), VM high availability manager is disabled.", vm.getName(), vm.getId());
if (logger.isDebugEnabled()) {
Expand Down Expand Up @@ -600,6 +605,11 @@ protected Long restart(final HaWorkVO work) {
logger.info("Unable to find vm: " + vmId);
return null;
}
if (VirtualMachine.State.Error.equals(vm.getState())) {
logger.info("Skipping HA restart for VM {} because it is in Error state", vm);
return null;
}
Comment thread
Dogface2k marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Dogface2k can we prevent adding the entires to op_it_work / op_ha_work tables when the instance is in Error state, so that Error-ed instances are never scheduled and picked up here.


if (checkAndCancelWorkIfNeeded(work)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,54 @@ public void scheduleRestartHostNotSupported() {
highAvailabilityManager.scheduleRestart(vm, true);
}

@Test
public void scheduleRestartVMInErrorState() {
VMInstanceVO vm = Mockito.mock(VMInstanceVO.class);
Mockito.when(vm.getState()).thenReturn(VirtualMachine.State.Error);

highAvailabilityManager.scheduleRestart(vm, true);

Mockito.verifyNoInteractions(_haDao, _itMgr, _alertMgr);
}

@Test
public void restartVMInErrorState() {
long vmId = 1L;
long workId = 2L;
VMInstanceVO vm = Mockito.mock(VMInstanceVO.class);

Mockito.when(mockWork.getInstanceId()).thenReturn(vmId);
Mockito.when(mockWork.getId()).thenReturn(workId);
Mockito.when(_haDao.listFutureHaWorkForVm(vmId, workId)).thenReturn(new ArrayList<HaWorkVO>());
Mockito.when(_haDao.listRunningHaWorkForVm(vmId)).thenReturn(new ArrayList<HaWorkVO>());
Mockito.when(_itMgr.findById(vmId)).thenReturn(vm);
Mockito.when(vm.getState()).thenReturn(VirtualMachine.State.Error);

assertNull(highAvailabilityManager.restart(mockWork));

Mockito.verifyNoInteractions(_hostDao, _alertMgr, userVmManager, volumeMgr);
Mockito.verify(mockWork, Mockito.never()).setStep(Mockito.any());
}

@Test
public void restartVMNotInErrorStateContinuesProcessing() {
long vmId = 1L;
long workId = 2L;
VMInstanceVO vm = Mockito.mock(VMInstanceVO.class);

Mockito.when(mockWork.getInstanceId()).thenReturn(vmId);
Mockito.when(mockWork.getId()).thenReturn(workId);
Mockito.when(_haDao.listFutureHaWorkForVm(vmId, workId)).thenReturn(new ArrayList<HaWorkVO>());
Mockito.when(_haDao.listRunningHaWorkForVm(vmId)).thenReturn(new ArrayList<HaWorkVO>());
Mockito.when(_itMgr.findById(vmId)).thenReturn(vm);
Mockito.when(vm.getState()).thenReturn(VirtualMachine.State.Running);
Mockito.doReturn(true).when(highAvailabilityManagerSpy).checkAndCancelWorkIfNeeded(mockWork);

assertNull(highAvailabilityManagerSpy.restart(mockWork));

Mockito.verify(highAvailabilityManagerSpy).checkAndCancelWorkIfNeeded(mockWork);
}

@Test
public void scheduleStop() {
VMInstanceVO vm = Mockito.mock(VMInstanceVO.class);
Expand Down
Loading