Search in sources :

Example 1 with DockerException

use of com.yahoo.vespa.hosted.dockerapi.DockerException in project vespa by vespa-engine.

the class NodeAgentImplTest method start_container_subtask_failure_leads_to_container_restart.

@Test
public void start_container_subtask_failure_leads_to_container_restart() throws IOException {
    final long restartGeneration = 1;
    final long rebootGeneration = 0;
    final ContainerNodeSpec nodeSpec = nodeSpecBuilder.wantedDockerImage(dockerImage).nodeState(Node.State.active).wantedVespaVersion(vespaVersion).wantedRestartGeneration(restartGeneration).currentRestartGeneration(restartGeneration).wantedRebootGeneration(rebootGeneration).build();
    NodeAgentImpl nodeAgent = spy(makeNodeAgent(null, false));
    when(nodeRepository.getContainerNodeSpec(hostName)).thenReturn(Optional.of(nodeSpec));
    when(pathResolver.getApplicationStoragePathForNodeAdmin()).thenReturn(Files.createTempDirectory("foo"));
    when(pathResolver.getApplicationStoragePathForHost()).thenReturn(Files.createTempDirectory("bar"));
    when(dockerOperations.pullImageAsyncIfNeeded(eq(dockerImage))).thenReturn(false);
    when(storageMaintainer.getDiskUsageFor(eq(containerName))).thenReturn(Optional.of(201326592000L));
    doThrow(new DockerException("Failed to set up network")).doNothing().when(dockerOperations).startContainer(eq(containerName), eq(nodeSpec));
    try {
        nodeAgent.converge();
        fail("Expected to get DockerException");
    } catch (DockerException ignored) {
    }
    verify(dockerOperations, never()).removeContainer(any(), any());
    verify(dockerOperations, times(1)).createContainer(eq(containerName), eq(nodeSpec));
    verify(dockerOperations, times(1)).startContainer(eq(containerName), eq(nodeSpec));
    verify(nodeAgent, never()).runLocalResumeScriptIfNeeded(any());
    // The docker container was actually started and is running, but subsequent exec calls to set up
    // networking failed
    mockGetContainer(dockerImage, true);
    nodeAgent.converge();
    verify(dockerOperations, times(1)).removeContainer(any(), eq(nodeSpec));
    verify(dockerOperations, times(2)).createContainer(eq(containerName), eq(nodeSpec));
    verify(dockerOperations, times(2)).startContainer(eq(containerName), eq(nodeSpec));
    verify(nodeAgent, times(1)).runLocalResumeScriptIfNeeded(any());
}
Also used : DockerException(com.yahoo.vespa.hosted.dockerapi.DockerException) ContainerNodeSpec(com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec) Test(org.junit.Test)

Aggregations

DockerException (com.yahoo.vespa.hosted.dockerapi.DockerException)1 ContainerNodeSpec (com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec)1 Test (org.junit.Test)1