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
2 changes: 2 additions & 0 deletions api/src/main/java/com/cloud/event/EventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ public class EventTypes {
public static final String EVENT_MAINTENANCE_CANCEL = "MAINT.CANCEL";
public static final String EVENT_MAINTENANCE_CANCEL_PRIMARY_STORAGE = "MAINT.CANCEL.PS";
public static final String EVENT_MAINTENANCE_PREPARE = "MAINT.PREPARE";
public static final String EVENT_MAINTENANCE_PREPARE_ERROR = "MAINT.PREPARE.ERROR";
public static final String EVENT_MAINTENANCE_PREPARE_PRIMARY_STORAGE = "MAINT.PREPARE.PS";

// Primary storage pool
Expand Down Expand Up @@ -1046,6 +1047,7 @@ public class EventTypes {
entityEventDetails.put(EVENT_MAINTENANCE_CANCEL, Host.class);
entityEventDetails.put(EVENT_MAINTENANCE_CANCEL_PRIMARY_STORAGE, Host.class);
entityEventDetails.put(EVENT_MAINTENANCE_PREPARE, Host.class);
entityEventDetails.put(EVENT_MAINTENANCE_PREPARE_ERROR, Host.class);
entityEventDetails.put(EVENT_MAINTENANCE_PREPARE_PRIMARY_STORAGE, Host.class);

// Primary storage pool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,9 @@ protected boolean setHostIntoErrorInPrepareForMaintenance(HostVO host, List<VMIn
logger.debug("Host {} entering in PrepareForMaintenanceWithErrors state", host);
configureVncAccessForKVMHostFailedMigrations(host, errorVms);
resourceStateTransitTo(host, ResourceState.Event.UnableToMigrate, _nodeId);
ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), CallContext.current().getCallingAccountId(),
EventVO.LEVEL_ERROR, EventTypes.EVENT_MAINTENANCE_PREPARE_ERROR,
String.format("failed to prepare host %s for maintenance due to migration or VM state errors", host), host.getId(), null, 0);
Comment on lines +1729 to +1731
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.cloud.agent.api.GetVncPortCommand;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.event.ActionEventUtils;
import com.cloud.event.EventTypes;
import com.cloud.event.EventVO;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.ha.HighAvailabilityManager;
import com.cloud.host.Host;
Expand Down Expand Up @@ -78,6 +80,7 @@
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -442,16 +445,26 @@ private void verifyErrorInMaintenanceCalls() throws NoTransitionException {
}

private void verifyErrorInPrepareForMaintenanceCalls() throws NoTransitionException {
when(host.getResourceState()).thenReturn(ResourceState.PrepareForMaintenance);
boolean enterMaintenanceMode = resourceManager.checkAndMaintain(hostId);
verify(resourceManager).attemptMaintain(host);
verify(resourceManager).setHostIntoErrorInPrepareForMaintenance(eq(host), any());
verify(resourceManager, never()).setHostIntoMaintenance(any());
verify(resourceManager, never()).setHostIntoErrorInMaintenance(any(), any());
verify(resourceManager, never()).setHostIntoPrepareForMaintenanceAfterErrorsFixed(any());
verify(resourceManager).resourceStateTransitTo(eq(host), eq(UnableToMigrate), anyLong());
String expectedDescription = String.format("failed to prepare host %s for maintenance due to migration or VM state errors", host);
actionEventUtilsMocked.verify(() -> ActionEventUtils.onCompletedActionEvent(
anyLong(), anyLong(), eq(EventVO.LEVEL_ERROR), eq(EventTypes.EVENT_MAINTENANCE_PREPARE_ERROR),
eq(expectedDescription), eq(hostId), isNull(), eq(0L)));
Comment on lines +456 to +459
Assert.assertFalse(enterMaintenanceMode);
}

@Test
public void testMaintenancePrepareErrorEventMapsToHostEntity() {
Assert.assertEquals(Host.class, EventTypes.getEntityClassForEvent(EventTypes.EVENT_MAINTENANCE_PREPARE_ERROR));
}

private void verifyReturnToPrepareForMaintenanceCalls() throws NoTransitionException {
boolean enterMaintenanceMode = resourceManager.checkAndMaintain(hostId);
verify(resourceManager).attemptMaintain(host);
Expand Down
Loading