This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 4bb0dafbdedd CAMEL-24821: camel-test-infra-ollama - fail when pulling
the model fails
4bb0dafbdedd is described below
commit 4bb0dafbdedd5b2896f547fbba057f4b0a975ddd
Author: Karol Krawczyk <[email protected]>
AuthorDate: Tue Sep 22 07:45:51 2026 +0200
CAMEL-24821: camel-test-infra-ollama - fail when pulling the model fails
OllamaLocalContainerInfraService discarded the ExecResult of both
"ollama pull" invocations, so a pull that failed (no network, unknown
model name, full disk) left only an INFO line and the service reported
a running instance that answered every request with "model not found".
OllamaContainer has no wait strategy of its own beyond the host port,
so nothing else asserted that the model was present.
Both pulls now go through pullModel(kind, model), which checks the exit
code and fails with the model name and the error output of the pull;
the kind ("model" / "embedding model") keeps the two pulls apart in logs
and errors when both name the same model. InterruptedException restores
the interrupt flag. The check is a package-private
requireSuccessfulPull(model, exitCode, stderr) with unit tests that need
no Docker, the first tests in camel-test-infra-ollama.
Closes #26718
Co-authored-by: Claude <[email protected]>
---
.../services/OllamaLocalContainerInfraService.java | 45 +++++++++++++------
.../infra/ollama/services/OllamaModelPullTest.java | 50 ++++++++++++++++++++++
2 files changed, 83 insertions(+), 12 deletions(-)
diff --git
a/test-infra/camel-test-infra-ollama/src/main/java/org/apache/camel/test/infra/ollama/services/OllamaLocalContainerInfraService.java
b/test-infra/camel-test-infra-ollama/src/main/java/org/apache/camel/test/infra/ollama/services/OllamaLocalContainerInfraService.java
index e0b874f33488..9471b68bcf2f 100644
---
a/test-infra/camel-test-infra-ollama/src/main/java/org/apache/camel/test/infra/ollama/services/OllamaLocalContainerInfraService.java
+++
b/test-infra/camel-test-infra-ollama/src/main/java/org/apache/camel/test/infra/ollama/services/OllamaLocalContainerInfraService.java
@@ -31,6 +31,7 @@ import
org.apache.camel.test.infra.ollama.commons.OllamaProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.BindMode;
+import org.testcontainers.containers.Container;
import org.testcontainers.ollama.OllamaContainer;
import org.testcontainers.utility.DockerImageName;
@@ -165,27 +166,47 @@ public class OllamaLocalContainerInfraService implements
OllamaInfraService, Con
LOG.info("Trying to start the Ollama container");
container.start();
- LOG.info("Pulling the model {}", getModel());
- try {
- container.execInContainer("ollama", "pull", getModel());
- } catch (IOException | InterruptedException e) {
- throw new RuntimeException(e);
- }
+ pullModel("model", getModel());
String embeddingModel = embeddingModelName();
if (embeddingModel != null && !embeddingModel.isEmpty()) {
- LOG.info("Pulling the embedding model {}", embeddingModel);
- try {
- container.execInContainer("ollama", "pull", embeddingModel);
- } catch (IOException | InterruptedException e) {
- throw new RuntimeException(e);
- }
+ pullModel("embedding model", embeddingModel);
}
registerProperties();
LOG.info("Ollama instance running at {}", getEndpoint());
}
+ /**
+ * @param kind what the model is pulled as, since both pulls may name the
same model
+ */
+ private void pullModel(String kind, String model) {
+ LOG.info("Pulling the {} {}", kind, model);
+ try {
+ Container.ExecResult result = container.execInContainer("ollama",
"pull", model);
+ requireSuccessfulPull(model, result.getExitCode(),
result.getStderr());
+ } catch (IOException e) {
+ throw new RuntimeException("Pulling the " + kind + " " + model + "
failed", e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RuntimeException("Interrupted while pulling the " + kind
+ " " + model, e);
+ }
+ }
+
+ /**
+ * The container is ready as soon as it accepts a connection on its port,
and a pull that fails leaves it running
+ * without the model, so the service would otherwise report an instance
that answers every request with "model not
+ * found".
+ */
+ static void requireSuccessfulPull(String model, int exitCode, String
stderr) {
+ if (exitCode == 0) {
+ return;
+ }
+ String reason = stderr == null || stderr.isBlank() ? "no error output"
: stderr.strip();
+ throw new IllegalStateException(
+ "Pulling the model %s failed with exit code %d:
%s".formatted(model, exitCode, reason));
+ }
+
@Override
public void shutdown() {
LOG.info("Stopping the Ollama container");
diff --git
a/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaModelPullTest.java
b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaModelPullTest.java
new file mode 100644
index 000000000000..c869b78e9451
--- /dev/null
+++
b/test-infra/camel-test-infra-ollama/src/test/java/org/apache/camel/test/infra/ollama/services/OllamaModelPullTest.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.test.infra.ollama.services;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class OllamaModelPullTest {
+
+ @Test
+ void aPullThatSucceededIsAccepted() {
+ assertDoesNotThrow(() ->
OllamaLocalContainerInfraService.requireSuccessfulPull("granite4:3b", 0, ""));
+ }
+
+ @Test
+ void aPullThatFailedNamesTheModelAndTheError() {
+ IllegalStateException e = assertThrows(IllegalStateException.class,
+ () -> OllamaLocalContainerInfraService.requireSuccessfulPull(
+ "qwen2.5:0.5b", 1, "pull model manifest: file does not
exist\n"));
+
+ assertTrue(e.getMessage().contains("qwen2.5:0.5b"), e.getMessage());
+ assertTrue(e.getMessage().contains("exit code 1"), e.getMessage());
+ assertTrue(e.getMessage().contains("pull model manifest: file does not
exist"), e.getMessage());
+ }
+
+ @Test
+ void aPullThatFailedSilentlyStillFails() {
+ IllegalStateException e = assertThrows(IllegalStateException.class,
+ () ->
OllamaLocalContainerInfraService.requireSuccessfulPull("granite-embedding:30m",
125, null));
+
+ assertTrue(e.getMessage().contains("no error output"), e.getMessage());
+ }
+}