Skip to content

Commit 0860955

Browse files
Update test build path errors in test compose
Signed-off-by: cogniware-devops <ambarish.desai@cogniware.ai>
1 parent b58ff8b commit 0860955

1 file changed

Lines changed: 171 additions & 32 deletions

File tree

CogniwareIms/tests/test_compose_on_xeon.sh

Lines changed: 171 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,52 @@
44

55
set -e
66

7-
WORKPATH=$(dirname "$PWD")
7+
# Calculate WORKPATH - handle both local and CI environments
8+
# If run from tests/ directory: WORKPATH = parent directory
9+
# If run from root: WORKPATH = current directory
10+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11+
echo "SCRIPT_DIR: $SCRIPT_DIR"
12+
13+
# Try multiple path detection strategies
14+
WORKPATH=""
15+
if [ -f "$SCRIPT_DIR/../cogniwareims.py" ]; then
16+
# We're in the CogniwareIms directory structure
17+
WORKPATH="$(cd "$SCRIPT_DIR/.." && pwd)"
18+
echo "Found cogniwareims.py at parent: $WORKPATH"
19+
elif [ -f "$SCRIPT_DIR/../../CogniwareIms/cogniwareims.py" ]; then
20+
# We're in GenAIExamples/CogniwareIms/tests
21+
WORKPATH="$(cd "$SCRIPT_DIR/../.." && pwd)/CogniwareIms"
22+
echo "Found cogniwareims.py at grandparent/CogniwareIms: $WORKPATH"
23+
elif [ -d "$SCRIPT_DIR/../docker_compose/intel/cpu/xeon" ]; then
24+
# We're in tests/, parent has docker_compose
25+
WORKPATH="$(cd "$SCRIPT_DIR/.." && pwd)"
26+
echo "Found docker_compose at parent: $WORKPATH"
27+
elif [ -d "$SCRIPT_DIR/../../CogniwareIms/docker_compose/intel/cpu/xeon" ]; then
28+
# We're in GenAIExamples/CogniwareIms/tests
29+
WORKPATH="$(cd "$SCRIPT_DIR/../.." && pwd)/CogniwareIms"
30+
echo "Found docker_compose at grandparent/CogniwareIms: $WORKPATH"
31+
else
32+
# Fallback: assume we're in the example directory
33+
WORKPATH="$(cd "$SCRIPT_DIR/.." && pwd)"
34+
echo "Using fallback WORKPATH: $WORKPATH"
35+
fi
36+
837
LOG_PATH="$WORKPATH/tests"
938

39+
# Verify WORKPATH by checking for docker_compose directory
40+
echo "WORKPATH: $WORKPATH"
41+
echo "Verifying WORKPATH..."
42+
if [ ! -d "$WORKPATH/docker_compose/intel/cpu/xeon" ] && [ ! -d "$WORKPATH/CogniwareIms/docker_compose/intel/cpu/xeon" ]; then
43+
echo "ERROR: docker_compose/intel/cpu/xeon not found in WORKPATH"
44+
echo "WORKPATH: $WORKPATH"
45+
echo "Looking for: $WORKPATH/docker_compose/intel/cpu/xeon"
46+
echo "Or: $WORKPATH/CogniwareIms/docker_compose/intel/cpu/xeon"
47+
echo "Available directories in WORKPATH:"
48+
ls -la "$WORKPATH" 2>/dev/null | head -20 || echo "Cannot list WORKPATH"
49+
exit 1
50+
fi
51+
echo "WORKPATH verified successfully"
52+
1053
# Get IP address with fallback to localhost
1154
if command -v hostname >/dev/null 2>&1; then
1255
ip_address=$(hostname -I | awk '{print $1}' 2>/dev/null || echo "127.0.0.1")
@@ -27,7 +70,7 @@ wait_for_service() {
2770
local service_name=$2
2871
local max_attempts=${3:-30}
2972
local attempt=0
30-
73+
3174
echo "Waiting for $service_name..."
3275
while [ $attempt -lt $max_attempts ]; do
3376
if curl -s -f "$url" > /dev/null 2>&1; then
@@ -38,34 +81,83 @@ wait_for_service() {
3881
echo "Waiting for $service_name... (attempt $attempt/$max_attempts)"
3982
sleep 10
4083
done
41-
84+
4285
echo "ERROR: $service_name failed to become ready after $((max_attempts * 10)) seconds"
4386
return 1
4487
}
4588

4689
function build_docker_images() {
4790
echo "Building Docker images..."
48-
cd $WORKPATH/docker_build_image
91+
local build_dir=""
92+
if [ -d "$WORKPATH/docker_image_build" ]; then
93+
build_dir="$WORKPATH/docker_image_build"
94+
elif [ -d "$WORKPATH/CogniwareIms/docker_image_build" ]; then
95+
build_dir="$WORKPATH/CogniwareIms/docker_image_build"
96+
else
97+
echo "ERROR: docker_image_build directory not found"
98+
exit 1
99+
fi
100+
101+
cd "$build_dir"
102+
echo "Building from: $(pwd)"
103+
echo "Verifying build context..."
104+
if [ ! -f "../backend/Dockerfile" ]; then
105+
echo "ERROR: backend/Dockerfile not found relative to build directory"
106+
echo "Current directory: $(pwd)"
107+
echo "Expected: $(pwd)/../backend/Dockerfile"
108+
exit 1
109+
fi
110+
if [ ! -f "../frontend/Dockerfile" ]; then
111+
echo "ERROR: frontend/Dockerfile not found relative to build directory"
112+
echo "Current directory: $(pwd)"
113+
echo "Expected: $(pwd)/../frontend/Dockerfile"
114+
exit 1
115+
fi
116+
echo "Build context verified. Starting build..."
49117
docker compose -f build.yaml build
50118
}
51119

52120
function start_services() {
53-
echo "Starting services on Intel Xeon..."
54-
cd $WORKPATH/docker_compose/intel/xeon
121+
echo "Starting Cogniware IMS services on Intel Xeon..."
122+
local compose_dir=""
123+
if [ -d "$WORKPATH/docker_compose/intel/cpu/xeon" ]; then
124+
compose_dir="$WORKPATH/docker_compose/intel/cpu/xeon"
125+
elif [ -d "$WORKPATH/CogniwareIms/docker_compose/intel/cpu/xeon" ]; then
126+
compose_dir="$WORKPATH/CogniwareIms/docker_compose/intel/cpu/xeon"
127+
else
128+
echo "ERROR: docker_compose/intel/cpu/xeon directory not found"
129+
echo "WORKPATH: $WORKPATH"
130+
echo "Searched for:"
131+
echo " - $WORKPATH/docker_compose/intel/cpu/xeon"
132+
echo " - $WORKPATH/CogniwareIms/docker_compose/intel/cpu/xeon"
133+
if [ -d "$WORKPATH/docker_compose" ]; then
134+
echo "Found docker_compose directory structure:"
135+
find "$WORKPATH/docker_compose" -type d -maxdepth 3 2>/dev/null | head -10
136+
fi
137+
exit 1
138+
fi
139+
140+
echo "Changing to compose directory: $compose_dir"
141+
cd "$compose_dir" || {
142+
echo "ERROR: Failed to cd to $compose_dir"
143+
exit 1
144+
}
145+
echo "Current directory: $(pwd)"
55146

56147
# Set environment variables
57148
export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}
58149
export LLM_MODEL_ID=${LLM_MODEL_ID:-"Intel/neural-chat-7b-v3-3"}
59150
export EMBEDDING_MODEL_ID=${EMBEDDING_MODEL_ID:-"BAAI/bge-base-en-v1.5"}
60151
export RERANK_MODEL_ID=${RERANK_MODEL_ID:-"BAAI/bge-reranker-base"}
152+
export POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-"postgres"}
61153

62154
echo "Starting Docker Compose services..."
63155
docker compose up -d
64156

65-
# Wait for services to be ready (increased wait time for CI)
157+
# Wait for services to be ready
66158
echo "Waiting for services to initialize..."
67159
sleep 90
68-
160+
69161
# Check if containers are running
70162
echo "Checking container status..."
71163
docker compose ps
@@ -89,13 +181,35 @@ function validate_services() {
89181
echo "Waiting for Redis container... (attempt $attempt/$max_attempts)"
90182
sleep 5
91183
done
92-
184+
93185
if [ $attempt -eq $max_attempts ]; then
94186
echo "ERROR: Redis failed to become ready"
95187
docker logs redis-vector-db || true
96188
exit 1
97189
fi
98190

191+
# Check PostgreSQL
192+
echo "Checking PostgreSQL..."
193+
max_attempts=30
194+
attempt=0
195+
while [ $attempt -lt $max_attempts ]; do
196+
if docker ps | grep -q "postgres-db"; then
197+
if docker exec postgres-db pg_isready -U postgres > /dev/null 2>&1; then
198+
echo "PostgreSQL is ready!"
199+
break
200+
fi
201+
fi
202+
attempt=$((attempt + 1))
203+
echo "Waiting for PostgreSQL container... (attempt $attempt/$max_attempts)"
204+
sleep 5
205+
done
206+
207+
if [ $attempt -eq $max_attempts ]; then
208+
echo "ERROR: PostgreSQL failed to become ready"
209+
docker logs postgres-db || true
210+
exit 1
211+
fi
212+
99213
# Check TGI service
100214
wait_for_service "http://${ip_address}:8008/health" "TGI service" 30 || exit 1
101215

@@ -114,81 +228,106 @@ function validate_services() {
114228
echo "All microservices are healthy!"
115229
}
116230

117-
function validate_megaservice() {
118-
echo "Validating InventoryMS megaservice..."
231+
function validate_backend() {
232+
echo "Validating Cogniware IMS backend..."
119233

120234
# Check backend health
121-
wait_for_service "http://${ip_address}:8888/health" "InventoryMS backend" 30 || exit 1
235+
wait_for_service "http://${ip_address}:8000/api/health" "Cogniware IMS backend" 30 || exit 1
122236

123-
# Test chat completion endpoint
237+
# Test chat endpoint
124238
echo "Testing chat completion..."
125239
max_attempts=3
126240
attempt=0
127241
while [ $attempt -lt $max_attempts ]; do
128-
response=$(curl -s -X POST http://${ip_address}:8888/v1/chat/completions \
242+
response=$(curl -s -X POST http://${ip_address}:8000/api/chat \
129243
-H "Content-Type: application/json" \
130244
-d '{
131-
"messages": [
132-
{"role": "user", "content": "What Intel processors are available for data centers?"}
133-
]
245+
"message": "What Intel processors are best for inventory systems?",
246+
"session_id": "test_session",
247+
"user_role": "Inventory Manager"
134248
}' || echo "")
135-
249+
136250
if [ -z "$response" ]; then
137-
echo "Empty response from chat completion endpoint (attempt $((attempt + 1))/$max_attempts)"
251+
echo "Empty response from chat endpoint (attempt $((attempt + 1))/$max_attempts)"
138252
attempt=$((attempt + 1))
139253
sleep 5
140254
continue
141255
fi
142-
256+
143257
if echo "$response" | grep -qi "error"; then
144-
echo "Chat completion test failed!"
258+
echo "Chat test failed!"
145259
echo "Response: $response"
146260
attempt=$((attempt + 1))
147261
if [ $attempt -ge $max_attempts ]; then
148262
exit 1
149263
fi
150264
sleep 5
151265
else
152-
echo "Chat completion test successful!"
153-
echo "Megaservice validation successful!"
154-
return 0
266+
echo "Chat test successful!"
267+
break
155268
fi
156269
done
157270

158-
exit 1
271+
# Test knowledge stats
272+
echo "Testing knowledge base stats..."
273+
wait_for_service "http://${ip_address}:8000/api/knowledge/stats" "Knowledge base stats" 10 || exit 1
274+
275+
echo "Backend validation successful!"
159276
}
160277

161278
function validate_frontend() {
162-
echo "Validating InventoryMS frontend..."
279+
echo "Validating Cogniware IMS frontend..."
163280

164281
# Check UI health
165-
wait_for_service "http://${ip_address}:3000" "InventoryMS UI" 30 || exit 1
282+
wait_for_service "http://${ip_address}:3000" "Cogniware IMS UI" 30 || exit 1
166283

167284
echo "Frontend validation successful!"
168285
}
169286

170287
function stop_services() {
171288
echo "Stopping services..."
172-
cd $WORKPATH/docker_compose/intel/xeon
173-
docker compose down -v
289+
local compose_dir=""
290+
if [ -d "$WORKPATH/docker_compose/intel/cpu/xeon" ]; then
291+
compose_dir="$WORKPATH/docker_compose/intel/cpu/xeon"
292+
elif [ -d "$WORKPATH/CogniwareIms/docker_compose/intel/cpu/xeon" ]; then
293+
compose_dir="$WORKPATH/CogniwareIms/docker_compose/intel/cpu/xeon"
294+
else
295+
echo "Warning: docker_compose/intel/cpu/xeon directory not found, attempting cleanup anyway"
296+
docker compose down -v 2>/dev/null || {
297+
echo "Warning: Some containers may not have stopped cleanly"
298+
docker ps -a | grep cogniware || true
299+
}
300+
return
301+
fi
302+
303+
if [ -n "$compose_dir" ]; then
304+
cd "$compose_dir" || {
305+
echo "Warning: Failed to cd to $compose_dir, attempting cleanup from current directory"
306+
}
307+
fi
308+
docker compose down -v 2>/dev/null || {
309+
echo "Warning: Some containers may not have stopped cleanly"
310+
docker ps -a | grep cogniware || true
311+
}
174312
}
175313

176314
function main() {
177315
echo "========================================="
178-
echo "InventoryMS E2E Test on Intel Xeon"
316+
echo "Cogniware IMS E2E Test on Intel Xeon"
179317
echo "========================================="
180318

181319
stop_services
182320
build_docker_images
183321
start_services
184322
validate_services
185-
validate_megaservice
323+
validate_backend
186324
validate_frontend
187325
stop_services
188326

189327
echo "========================================="
190-
echo "InventoryMS E2E Test Passed!"
328+
echo "Cogniware IMS E2E Test Passed!"
191329
echo "========================================="
192330
}
193331

194332
main
333+

0 commit comments

Comments
 (0)