Repository navigation
Expand file tree
/
Copy pathintegration_test.sh
More file actions
executable file
·628 lines (522 loc) · 19.1 KB
/
Copy pathintegration_test.sh
File metadata and controls
executable file
·628 lines (522 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
#!/bin/bash
# Lightstack Integration Test Suite
# Tests all OpenStack API endpoints and Horizon compatibility
# NOT using 'set -e': this suite tracks pass/fail counts itself, and bash's
# ((counter++)) returns exit status 1 when the counter was 0 — under set -e that
# aborts the whole run right after the first PASS (same reason quick_test.sh skips it).
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Test counters
TESTS_PASSED=0
TESTS_FAILED=0
TESTS_TOTAL=0
# Configuration
LIGHTSTACK_URL="${LIGHTSTACK_URL:-http://localhost:35357}"
ADMIN_USER="${ADMIN_USER:-admin}"
ADMIN_PASSWORD="${ADMIN_PASSWORD:-secret}"
PROJECT_NAME="${PROJECT_NAME:-default}"
# Function to print test status
print_test() {
local test_name=$1
echo -e "\n${YELLOW}[TEST]${NC} $test_name"
}
print_pass() {
echo -e "${GREEN}[PASS]${NC} $1"
((TESTS_PASSED++))
((TESTS_TOTAL++))
}
print_fail() {
echo -e "${RED}[FAIL]${NC} $1"
((TESTS_FAILED++))
((TESTS_TOTAL++))
}
print_info() {
echo -e " ℹ $1"
}
# Function to check if Lightstack is running
check_lightstack_running() {
print_test "Checking if Lightstack is running"
if curl -s -f "${LIGHTSTACK_URL}/v3" > /dev/null 2>&1; then
print_pass "Lightstack is running on ${LIGHTSTACK_URL}"
return 0
else
print_fail "Lightstack is not running on ${LIGHTSTACK_URL}"
echo "Start Lightstack with: ./lightstack --config config/lightstack.yaml"
exit 1
fi
}
# Test 1: Keystone Authentication
test_keystone_auth() {
print_test "Keystone: Unscoped token authentication"
response=$(curl -s -i -X POST "${LIGHTSTACK_URL}/v3/auth/tokens" \
-H "Content-Type: application/json" \
-d '{
"auth": {
"identity": {
"methods": ["password"],
"password": {
"user": {
"name": "'$ADMIN_USER'",
"domain": {"name": "Default"},
"password": "'$ADMIN_PASSWORD'"
}
}
}
}
}')
# Extract token from X-Subject-Token header
TOKEN=$(echo "$response" | grep -i "X-Subject-Token:" | awk '{print $2}' | tr -d '\r')
if [ -n "$TOKEN" ]; then
print_pass "Unscoped token obtained: ${TOKEN:0:20}..."
export OS_TOKEN=$TOKEN
else
print_fail "Failed to obtain unscoped token"
echo "$response"
return 1
fi
# Test scoped token
print_test "Keystone: Scoped token authentication"
response=$(curl -s -i -X POST "${LIGHTSTACK_URL}/v3/auth/tokens" \
-H "Content-Type: application/json" \
-d '{
"auth": {
"identity": {
"methods": ["password"],
"password": {
"user": {
"name": "'$ADMIN_USER'",
"domain": {"name": "Default"},
"password": "'$ADMIN_PASSWORD'"
}
}
},
"scope": {
"project": {
"name": "'$PROJECT_NAME'",
"domain": {"name": "Default"}
}
}
}
}')
SCOPED_TOKEN=$(echo "$response" | grep -i "X-Subject-Token:" | awk '{print $2}' | tr -d '\r')
if [ -n "$SCOPED_TOKEN" ]; then
print_pass "Scoped token obtained: ${SCOPED_TOKEN:0:20}..."
export OS_TOKEN=$SCOPED_TOKEN
# Check for service catalog
if echo "$response" | grep -q "catalog"; then
print_pass "Service catalog present in response"
else
print_fail "Service catalog missing from scoped token response"
fi
else
print_fail "Failed to obtain scoped token"
return 1
fi
}
# Test 2: Keystone User/Project Management
test_keystone_resources() {
print_test "Keystone: List users"
response=$(curl -s -H "X-Auth-Token: $OS_TOKEN" "${LIGHTSTACK_URL}/v3/users")
if echo "$response" | grep -q "users"; then
print_pass "User list retrieved"
print_info "Found $(echo "$response" | grep -o '"name"' | wc -l) users"
else
print_fail "Failed to retrieve user list"
fi
print_test "Keystone: List projects"
response=$(curl -s -H "X-Auth-Token: $OS_TOKEN" "${LIGHTSTACK_URL}/v3/projects")
if echo "$response" | grep -q "projects"; then
print_pass "Project list retrieved"
print_info "Found $(echo "$response" | grep -o '"name"' | wc -l) projects"
else
print_fail "Failed to retrieve project list"
fi
}
# Test 3: Nova Server Operations
test_nova_servers() {
print_test "Nova: List servers"
response=$(curl -s -H "X-Auth-Token: $OS_TOKEN" "http://localhost:8774/v2.1/servers")
if echo "$response" | grep -q "servers"; then
print_pass "Server list retrieved"
print_info "Found $(echo "$response" | grep -o '"id"' | wc -l) servers"
else
print_fail "Failed to retrieve server list"
fi
print_test "Nova: List flavors"
response=$(curl -s -H "X-Auth-Token: $OS_TOKEN" "http://localhost:8774/v2.1/flavors")
if echo "$response" | grep -q "flavors"; then
print_pass "Flavor list retrieved"
# Extract first flavor ID for later tests
FLAVOR_ID=$(echo "$response" | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4)
export FLAVOR_ID
print_info "Using flavor: $FLAVOR_ID"
else
print_fail "Failed to retrieve flavor list"
fi
print_test "Nova: List hypervisors"
response=$(curl -s -H "X-Auth-Token: $OS_TOKEN" "http://localhost:8774/v2.1/os-hypervisors")
if echo "$response" | grep -q "hypervisors"; then
print_pass "Hypervisor list retrieved"
else
print_fail "Failed to retrieve hypervisor list"
fi
}
# Test 4: Neutron Network Operations
test_neutron_networks() {
print_test "Neutron: List networks"
response=$(curl -s -H "X-Auth-Token: $OS_TOKEN" "http://localhost:9696/v2.0/networks")
if echo "$response" | grep -q "networks"; then
print_pass "Network list retrieved"
print_info "Found $(echo "$response" | grep -o '"id"' | wc -l) networks"
else
print_fail "Failed to retrieve network list"
fi
print_test "Neutron: Create network"
NETWORK_NAME="test-network-$$"
response=$(curl -s -X POST -H "X-Auth-Token: $OS_TOKEN" \
-H "Content-Type: application/json" \
"http://localhost:9696/v2.0/networks" \
-d '{
"network": {
"name": "'$NETWORK_NAME'",
"admin_state_up": true
}
}')
if echo "$response" | grep -q "$NETWORK_NAME"; then
NETWORK_ID=$(echo "$response" | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4)
export NETWORK_ID
print_pass "Network created: $NETWORK_ID"
else
print_fail "Failed to create network"
echo "$response"
fi
print_test "Neutron: Create subnet"
response=$(curl -s -X POST -H "X-Auth-Token: $OS_TOKEN" \
-H "Content-Type: application/json" \
"http://localhost:9696/v2.0/subnets" \
-d '{
"subnet": {
"network_id": "'$NETWORK_ID'",
"ip_version": 4,
"cidr": "192.168.100.0/24",
"gateway_ip": "192.168.100.1"
}
}')
if echo "$response" | grep -q "192.168.100"; then
SUBNET_ID=$(echo "$response" | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4)
export SUBNET_ID
print_pass "Subnet created: $SUBNET_ID"
else
print_fail "Failed to create subnet"
fi
print_test "Neutron: List security groups"
response=$(curl -s -H "X-Auth-Token: $OS_TOKEN" "http://localhost:9696/v2.0/security-groups")
if echo "$response" | grep -q "security_groups"; then
print_pass "Security group list retrieved"
else
print_fail "Failed to retrieve security group list"
fi
}
# Test 5: Cinder Volume Operations
test_cinder_volumes() {
print_test "Cinder: List volumes"
# Extract project ID from token
PROJECT_ID=$(curl -s -H "X-Auth-Token: $OS_TOKEN" "${LIGHTSTACK_URL}/v3/auth/projects" | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4)
response=$(curl -s -H "X-Auth-Token: $OS_TOKEN" "http://localhost:8776/v3/volumes")
if echo "$response" | grep -q "volumes"; then
print_pass "Volume list retrieved"
print_info "Found $(echo "$response" | grep -o '"id"' | wc -l) volumes"
else
print_fail "Failed to retrieve volume list"
fi
print_test "Cinder: Create volume"
VOLUME_NAME="test-volume-$$"
response=$(curl -s -X POST -H "X-Auth-Token: $OS_TOKEN" \
-H "Content-Type: application/json" \
"http://localhost:8776/v3/volumes" \
-d '{
"volume": {
"name": "'$VOLUME_NAME'",
"size": 1
}
}')
if echo "$response" | grep -q "$VOLUME_NAME"; then
VOLUME_ID=$(echo "$response" | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4)
export VOLUME_ID
print_pass "Volume created: $VOLUME_ID"
else
print_fail "Failed to create volume"
echo "$response"
fi
print_test "Cinder: List volume types"
response=$(curl -s -H "X-Auth-Token: $OS_TOKEN" "http://localhost:8776/v3/types")
if echo "$response" | grep -q "volume_types"; then
print_pass "Volume type list retrieved"
else
print_fail "Failed to retrieve volume type list"
fi
}
# Test 6: Glance Image Operations
test_glance_images() {
print_test "Glance: List images"
response=$(curl -s -H "X-Auth-Token: $OS_TOKEN" "http://localhost:9292/v2/images")
if echo "$response" | grep -q "images"; then
print_pass "Image list retrieved"
print_info "Found $(echo "$response" | grep -o '"id"' | wc -l) images"
else
print_fail "Failed to retrieve image list"
fi
print_test "Glance: Create image metadata"
IMAGE_NAME="test-image-$$"
response=$(curl -s -X POST -H "X-Auth-Token: $OS_TOKEN" \
-H "Content-Type: application/json" \
"http://localhost:9292/v2/images" \
-d '{
"name": "'$IMAGE_NAME'",
"disk_format": "raw",
"container_format": "bare",
"visibility": "private"
}')
if echo "$response" | grep -q "$IMAGE_NAME"; then
IMAGE_ID=$(echo "$response" | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4)
export IMAGE_ID
print_pass "Image metadata created: $IMAGE_ID"
else
print_fail "Failed to create image metadata"
echo "$response"
fi
print_test "Glance: Upload image data"
# Create small test file (1MB)
dd if=/dev/urandom of=/tmp/test-image-$$.raw bs=1M count=1 2>/dev/null
response=$(curl -s -w "\n%{http_code}" -X PUT -H "X-Auth-Token: $OS_TOKEN" \
-H "Content-Type: application/octet-stream" \
"http://localhost:9292/v2/images/${IMAGE_ID}/file" \
--data-binary @/tmp/test-image-$$.raw)
http_code=$(echo "$response" | tail -1)
if [ "$http_code" = "204" ]; then
print_pass "Image data uploaded successfully"
else
print_fail "Failed to upload image data (HTTP $http_code)"
fi
# Cleanup temp file
rm -f /tmp/test-image-$$.raw
print_test "Glance: Download image data"
response=$(curl -s -w "\n%{http_code}" -H "X-Auth-Token: $OS_TOKEN" \
"http://localhost:9292/v2/images/${IMAGE_ID}/file" \
-o /tmp/downloaded-image-$$.raw)
http_code=$(echo "$response" | tail -1)
if [ "$http_code" = "200" ]; then
size=$(stat -f%z /tmp/downloaded-image-$$.raw 2>/dev/null || stat -c%s /tmp/downloaded-image-$$.raw 2>/dev/null)
print_pass "Image data downloaded successfully ($size bytes)"
else
print_fail "Failed to download image data (HTTP $http_code)"
fi
# Cleanup
rm -f /tmp/downloaded-image-$$.raw
}
# Test 7: Cross-Service Integration
test_cross_service() {
print_test "Cross-Service: Create VM with network and volume"
if [ -z "$NETWORK_ID" ] || [ -z "$FLAVOR_ID" ] || [ -z "$IMAGE_ID" ]; then
print_fail "Prerequisites missing (network, flavor, or image)"
return 1
fi
SERVER_NAME="test-server-$$"
response=$(curl -s -X POST -H "X-Auth-Token: $OS_TOKEN" \
-H "Content-Type: application/json" \
"http://localhost:8774/v2.1/servers" \
-d '{
"server": {
"name": "'$SERVER_NAME'",
"flavorRef": "'$FLAVOR_ID'",
"imageRef": "'$IMAGE_ID'",
"networks": [{"uuid": "'$NETWORK_ID'"}],
"block_device_mapping_v2": [
{
"boot_index": 0,
"uuid": "'$IMAGE_ID'",
"source_type": "image",
"destination_type": "local"
}
]
}
}')
if echo "$response" | grep -q "$SERVER_NAME"; then
SERVER_ID=$(echo "$response" | jq -r '.server.id')
export SERVER_ID
print_pass "Server created: $SERVER_ID"
# Wait for server to become active
print_info "Waiting for server to become active..."
for i in {1..10}; do
sleep 2
status=$(curl -s -H "X-Auth-Token: $OS_TOKEN" \
"http://localhost:8774/v2.1/servers/${SERVER_ID}" | \
jq -r '.server.status')
if [ "$status" = "ACTIVE" ] || [ "$status" = "ERROR" ]; then
break
fi
done
if [ "$status" = "ACTIVE" ]; then
print_pass "Server is active"
else
print_fail "Server did not become active (status: $status)"
fi
else
print_fail "Failed to create server"
echo "$response"
fi
}
# Test 8: Cleanup
test_cleanup() {
print_test "Cleanup: Deleting test resources"
# Delete server
if [ -n "$SERVER_ID" ]; then
curl -s -X DELETE -H "X-Auth-Token: $OS_TOKEN" \
"http://localhost:8774/v2.1/servers/${SERVER_ID}" > /dev/null
print_info "Deleted server: $SERVER_ID"
fi
# Delete image
if [ -n "$IMAGE_ID" ]; then
curl -s -X DELETE -H "X-Auth-Token: $OS_TOKEN" \
"http://localhost:9292/v2/images/${IMAGE_ID}" > /dev/null
print_info "Deleted image: $IMAGE_ID"
fi
# Delete volume
if [ -n "$VOLUME_ID" ]; then
PROJECT_ID=$(curl -s -H "X-Auth-Token: $OS_TOKEN" "${LIGHTSTACK_URL}/v3/auth/projects" | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4)
curl -s -X DELETE -H "X-Auth-Token: $OS_TOKEN" \
"http://localhost:8776/v3/volumes/${VOLUME_ID}" > /dev/null
print_info "Deleted volume: $VOLUME_ID"
fi
# Delete network (will cascade delete subnet)
if [ -n "$NETWORK_ID" ]; then
curl -s -X DELETE -H "X-Auth-Token: $OS_TOKEN" \
"http://localhost:9696/v2.0/networks/${NETWORK_ID}" > /dev/null
print_info "Deleted network: $NETWORK_ID"
fi
print_pass "Cleanup completed"
}
# Test 9: Stress Test (Concurrent Operations)
test_stress() {
print_test "Stress Test: Creating 5 concurrent networks"
pids=()
for i in {1..5}; do
(
curl -s -X POST -H "X-Auth-Token: $OS_TOKEN" \
-H "Content-Type: application/json" \
"http://localhost:9696/v2.0/networks" \
-d '{"network": {"name": "stress-test-'$i'-$$", "admin_state_up": true}}' \
> /dev/null
) &
pids+=($!)
done
# Wait for all requests
failed=0
for pid in "${pids[@]}"; do
if ! wait $pid; then
((failed++))
fi
done
if [ $failed -eq 0 ]; then
print_pass "All 5 concurrent network creations succeeded"
else
print_fail "$failed out of 5 concurrent network creations failed"
fi
# Cleanup stress test networks
response=$(curl -s -H "X-Auth-Token: $OS_TOKEN" "http://localhost:9696/v2.0/networks")
stress_networks=$(echo "$response" | grep -o '"id":"[^"]*"' | grep -A1 "stress-test" | grep '"id"' | cut -d'"' -f4)
for net_id in $stress_networks; do
curl -s -X DELETE -H "X-Auth-Token: $OS_TOKEN" \
"http://localhost:9696/v2.0/networks/${net_id}" > /dev/null 2>&1
done
}
# Test 10: Version Discovery
test_version_discovery() {
print_test "Version Discovery: Keystone"
response=$(curl -s "${LIGHTSTACK_URL}/")
if echo "$response" | grep -q "versions"; then
print_pass "Keystone version discovery works"
else
print_fail "Keystone version discovery failed"
fi
print_test "Version Discovery: Nova"
response=$(curl -s "http://localhost:8774/")
if echo "$response" | grep -q "versions"; then
print_pass "Nova version discovery works"
else
print_fail "Nova version discovery failed"
fi
print_test "Version Discovery: Neutron"
response=$(curl -s "http://localhost:9696/")
if echo "$response" | grep -q "versions"; then
print_pass "Neutron version discovery works"
else
print_fail "Neutron version discovery failed"
fi
print_test "Version Discovery: Glance"
response=$(curl -s "http://localhost:9292/")
if echo "$response" | grep -q "versions"; then
print_pass "Glance version discovery works"
else
print_fail "Glance version discovery failed"
fi
}
# Main test execution
main() {
echo "======================================"
echo "Lightstack Integration Test Suite"
echo "======================================"
echo ""
check_lightstack_running
echo ""
echo "======================================"
echo "Phase 1: Authentication & Authorization"
echo "======================================"
test_keystone_auth
test_keystone_resources
echo ""
echo "======================================"
echo "Phase 2: Service Endpoints"
echo "======================================"
test_version_discovery
test_nova_servers
test_neutron_networks
test_cinder_volumes
test_glance_images
echo ""
echo "======================================"
echo "Phase 3: Cross-Service Integration"
echo "======================================"
test_cross_service
echo ""
echo "======================================"
echo "Phase 4: Stress Testing"
echo "======================================"
test_stress
echo ""
echo "======================================"
echo "Phase 5: Cleanup"
echo "======================================"
test_cleanup
echo ""
echo "======================================"
echo "Test Summary"
echo "======================================"
echo -e "Total Tests: $TESTS_TOTAL"
echo -e "${GREEN}Passed: $TESTS_PASSED${NC}"
echo -e "${RED}Failed: $TESTS_FAILED${NC}"
if [ $TESTS_FAILED -eq 0 ]; then
echo ""
echo -e "${GREEN}✓ All tests passed!${NC}"
exit 0
else
echo ""
echo -e "${RED}✗ Some tests failed${NC}"
exit 1
fi
}
# Run main
main