HostExitMaintenanceModeStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { List<BaseEntity> entityList = step.getTransientResourceEntities(); Preconditions.checkArgument(entityList.size() == 1, "There should be only 1 host referenced by step %s", step.getId()); hostEntity = (HostEntity) entityList.get(0); logger.info("Calling deployer to exit host from maintenance mode {}", hostEntity); ChangeHostModeTaskService.State serviceDocument = taskCommand.getDeployerXenonClient() .enterNormalMode(hostEntity.getId()); for (StepEntity nextStep : taskCommand.getTask().getSteps()) { nextStep.createOrUpdateTransientResource(XenonTaskStatusStepCmd.REMOTE_TASK_LINK_RESOURCE_KEY, serviceDocument.documentSelfLink); } } HostExitMaintenanceModeStepCmd(TaskCommand taskCommand,
                                        StepBackend stepBackend,
                                        StepEntity step,
                                        HostBackend hostBackend);   }
@Test(expectedExceptions = HostStateChangeException.class) public void testFailure() throws Throwable { when(deployerClient.enterNormalMode(anyString())).thenReturn(serviceDocument); when(deployerClient.getHostChangeModeStatus(any(String.class))).thenThrow(HostStateChangeException.class); command.execute(); deployerClient.getHostChangeModeStatus(serviceDocument.documentSelfLink); Assert.fail("Should have failed"); }
@Test(expectedExceptions = HostStateChangeException.class) public void testHostStatusChangeFailed() throws Throwable{ ChangeHostModeTaskService.State failedState = new ChangeHostModeTaskService.State(); failedState.hostMode = HostMode.NORMAL; failedState.hostServiceLink = this.hostEntity.getId(); failedState.taskState = new TaskState(); failedState.taskState.stage = TaskState.TaskStage.FAILED; failedState.taskState.failure = new ServiceErrorResponse(); failedState.taskState.failure.message = "failed"; when(deployerClient.getHostChangeModeStatus(anyString())).thenReturn(failedState); commandStatus.execute(); fail("should have failed"); }