Skip to content

Commit 52561ee

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 3c319e9 commit 52561ee

File tree

3 files changed

+84
-43
lines changed

3 files changed

+84
-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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
--env TRUSTYAI_LM_EVAL_NAMESPACE=dummy \
14+
--name llama-stack \
15+
"$IMAGE_NAME:$GITHUB_SHA"
16+
echo "Started Llama Stack container..."
17+
18+
# Wait for llama stack to be ready by doing a health check
19+
echo "Waiting for Llama Stack server..."
20+
for i in {1..60}; do
21+
echo "Attempt $i to connect to Llama Stack..."
22+
resp=$(curl -fsS http://127.0.0.1:8321/v1/health)
23+
if [ "$resp" == '{"status":"OK"}' ]; then
24+
echo "Llama Stack server is up!"
25+
return
26+
fi
27+
sleep 1
28+
done
29+
echo "Llama Stack server failed to start :("
30+
echo "Container logs:"
31+
docker logs llama-stack || true
32+
exit 1
33+
}
34+
35+
function test_model_list {
36+
echo "===> Looking for model $INFERENCE_MODEL..."
37+
resp=$(curl -fsS http://127.0.0.1:8321/v1/models)
38+
if echo "$resp" | grep -q "$INFERENCE_MODEL"; then
39+
echo "Model $INFERENCE_MODEL was found :)"
40+
return
41+
else
42+
echo "Model $INFERENCE_MODEL was not found :("
43+
echo "Container logs:"
44+
docker logs llama-stack || true
45+
exit 1
46+
fi
47+
}
48+
49+
function test_model_openai_inference {
50+
echo "===> Attempting to chat with model $INFERENCE_MODEL..."
51+
resp=$(curl -fsS 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}")
52+
if echo "$resp" | grep -q "green"; then
53+
echo "===> Inference is working :)"
54+
return
55+
else
56+
echo "===> Inference is not working :("
57+
echo "Container logs:"
58+
docker logs llama-stack || true
59+
exit 1
60+
fi
61+
}
62+
63+
main() {
64+
echo "===> Starting smoke test..."
65+
start_and_wait_for_llama_stack_container
66+
test_model_list
67+
test_model_openai_inference
68+
echo "===> Smoke test completed successfully!"
69+
}
70+
71+
trap 'docker rm -f -v llama-stack >/dev/null 2>&1 || true' EXIT
72+
main "$@"
73+
exit 0

0 commit comments

Comments
 (0)