Skip to content

Commit f5b96fb

Browse files
refactor: move smoke tests into a seperate shell script
also add shell linter to pre-commit config Assisted-by: coderabbitai Signed-off-by: Nathan Weinberg <nweinber@redhat.com>
1 parent e3d3252 commit f5b96fb

File tree

3 files changed

+83
-43
lines changed

3 files changed

+83
-43
lines changed

.github/workflows/redhat-distro-container.yml

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -55,49 +55,12 @@ jobs:
5555
id: vllm
5656
uses: ./.github/actions/setup-vllm
5757

58-
- name: Test image
59-
id: test
60-
run: |
61-
set -euo pipefail
62-
# Start llama stack
63-
CID="$(docker run -d --pull=never \
64-
-p 8321:8321 \
65-
--env INFERENCE_MODEL=meta-llama/Llama-3.2-1B-Instruct \
66-
--env TRUSTYAI_LMEVAL_USE_K8S=False \
67-
--name llama-stack \
68-
${{ env.IMAGE_NAME }}:${{ github.sha }})"
69-
trap 'docker rm -f "$CID" >/dev/null 2>&1 || true' EXIT
70-
echo "Started Llama Stack container with CID: $CID"
71-
72-
echo "Waiting for Llama Stack server..."
73-
for i in {1..60}; do
74-
echo "Attempt $i to connect to Llama Stack..."
75-
if curl -fsS --max-time 2 http://127.0.0.1:8321/v1/health | grep -q '"status":"OK"'; then
76-
echo "Llama Stack server is up and serving :)"
77-
if curl -fsS --max-time 4 http://127.0.0.1:8321/v1/models | grep -q 'meta-llama/Llama-3.2-1B-Instruct'; then
78-
echo "meta-llama/Llama-3.2-1B-Instruct model was found :)"
79-
if curl -fsS --max-time 6 http://127.0.0.1:8321/v1/openai/v1/chat/completions -H "Content-Type: application/json" -d "{\"model\": \"meta-llama/Llama-3.2-1B-Instruct\",\"messages\": [{\"role\": \"user\", \"content\": \"What color is grass?\"}], \"max_tokens\": 10, \"temperature\": 0.0}" | grep -q 'green'; then
80-
echo "Inference is working :)"
81-
exit 0
82-
else
83-
echo "Inference is not working :("
84-
echo "Container logs:"
85-
docker logs "$CID" || true
86-
exit 1
87-
fi
88-
else
89-
echo "meta-llama/Llama-3.2-1B-Instruct model was not found :("
90-
echo "Container logs:"
91-
docker logs "$CID" || true
92-
exit 1
93-
fi
94-
fi
95-
sleep 1
96-
done
97-
echo "Llama Stack server failed to start :("
98-
echo "Container logs:"
99-
docker logs "$CID" || true
100-
exit 1
58+
- name: Smoke test image
59+
id: smoke-test
60+
shell: bash
61+
env:
62+
INFERENCE_MODEL: meta-llama/Llama-3.2-1B-Instruct
63+
run: ./tests/smoke.sh
10164

10265
- name: Log in to Quay.io
10366
id: login

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ repos:
4040
hooks:
4141
- id: actionlint
4242

43+
- repo: https://github.com/koalaman/shellcheck-precommit
44+
rev: v0.11.0
45+
hooks:
46+
- id: shellcheck
47+
4348
- repo: local
4449
hooks:
4550
- id: pkg-gen

tests/smoke.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
set -uo pipefail
4+
5+
function start_and_wait_for_llama_stack_container {
6+
# Start llama stack
7+
docker run \
8+
-d \
9+
--pull=never \
10+
-p 8321:8321 \
11+
--env INFERENCE_MODEL="$INFERENCE_MODEL" \
12+
--env TRUSTYAI_LMEVAL_USE_K8S=False \
13+
--name llama-stack \
14+
"$IMAGE_NAME:$GITHUB_SHA"
15+
echo "Started Llama Stack container..."
16+
17+
# Wait for llama stack to be ready by doing a health check
18+
echo "Waiting for Llama Stack server..."
19+
for i in {1..60}; do
20+
echo "Attempt $i to connect to Llama Stack..."
21+
resp=$(curl -fsS --max-time 2 http://127.0.0.1:8321/v1/health)
22+
if [ "$resp" == '{"status":"OK"}' ]; then
23+
echo "Llama Stack server is up!"
24+
return
25+
fi
26+
sleep 1
27+
done
28+
echo "Llama Stack server failed to start :("
29+
echo "Container logs:"
30+
docker logs llama-stack || true
31+
exit 1
32+
}
33+
34+
function test_model_list {
35+
echo "===> Looking for model $INFERENCE_MODEL..."
36+
resp=$(curl -fsS --max-time 4 http://127.0.0.1:8321/v1/models)
37+
if echo "$resp" | grep -q "$INFERENCE_MODEL"; then
38+
echo "Model $INFERENCE_MODEL was found :)"
39+
return
40+
else
41+
echo "Model $INFERENCE_MODEL was not found :("
42+
echo "Container logs:"
43+
docker logs llama-stack || true
44+
exit 1
45+
fi
46+
}
47+
48+
function test_model_openai_inference {
49+
echo "===> Attempting to chat with model $INFERENCE_MODEL..."
50+
resp=$(curl -fsS --max-time 6 http://127.0.0.1:8321/v1/openai/v1/chat/completions -H "Content-Type: application/json" -d "{\"model\": \"$INFERENCE_MODEL\",\"messages\": [{\"role\": \"user\", \"content\": \"What color is grass?\"}], \"max_tokens\": 10, \"temperature\": 0.0}")
51+
if echo "$resp" | grep -q "green"; then
52+
echo "===> Inference is working :)"
53+
return
54+
else
55+
echo "===> Inference is not working :("
56+
echo "Container logs:"
57+
docker logs llama-stack || true
58+
exit 1
59+
fi
60+
}
61+
62+
main() {
63+
echo "===> Starting smoke test..."
64+
start_and_wait_for_llama_stack_container
65+
test_model_list
66+
test_model_openai_inference
67+
echo "===> Smoke test completed successfully!"
68+
}
69+
70+
trap 'docker rm -f -v llama-stack >/dev/null 2>&1 || true' EXIT
71+
main "$@"
72+
exit 0

0 commit comments

Comments
 (0)