Repository navigation
Expand file tree
/
Copy pathnova_actions_extended_test.sh
More file actions
executable file
·140 lines (125 loc) · 3.97 KB
/
Copy pathnova_actions_extended_test.sh
File metadata and controls
executable file
·140 lines (125 loc) · 3.97 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
#!/bin/bash
# Nova server actions test - pause, unpause, lock, unlock, forceDelete
# Tests additional server lifecycle actions
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
# Base URLs
AUTH_URL="${OS_AUTH_URL:-http://localhost:5001/v3}"
NOVA_URL="${OS_COMPUTE_URL:-http://localhost:8774}"
GLANCE_URL="${OS_IMAGE_URL:-http://localhost:9292}"
echo "=== Nova Server Actions Test (pause/lock/force) ==="
# Get auth token
echo "Authenticating..."
TOKEN=$(curl -s -i -X POST "$AUTH_URL/auth/tokens" \
-H "Content-Type: application/json" \
-d '{
"auth": {
"identity": {
"methods": ["password"],
"password": {
"user": {
"name": "admin",
"domain": {"name": "Default"},
"password": "secret"
}
}
},
"scope": {
"project": {
"name": "default",
"domain": {"name": "Default"}
}
}
}
}' | grep -i '^x-subject-token' | cut -d' ' -f2 | tr -d '\r\n')
if [ -z "$TOKEN" ]; then
echo -e "${RED}FAIL${NC}: Authentication failed"
exit 1
fi
echo -e "${GREEN}OK${NC}: Authenticated"
# Server create refuses an image that does not exist or is not active, so the test boots
# from one it creates and uploads a few bytes to.
IMAGE_ID=$(curl -s -X POST "$GLANCE_URL/v2/images" \
-H "X-Auth-Token: $TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "nova-actions-extended-test-image", "disk_format": "raw", "container_format": "bare"}' | jq -r '.id')
curl -s -o /dev/null -X PUT "$GLANCE_URL/v2/images/$IMAGE_ID/file" \
-H "X-Auth-Token: $TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary "lightstack test image"
# Test 1: Pause server
echo "Test 1: Pause server"
SERVER_ID=$(curl -s -X POST "$NOVA_URL/v2.1/servers" \
-H "X-Auth-Token: $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"server": {
"name": "test-server-pause",
"flavorRef": "00000000-0000-0000-0000-000000000010",
"imageRef": "'"$IMAGE_ID"'"
}
}' | jq -r '.server.id')
curl -s -X POST "$NOVA_URL/v2.1/servers/$SERVER_ID/action" \
-H "X-Auth-Token: $TOKEN" \
-H "Content-Type: application/json" \
-d '{"pause": null}' \
-w "%{http_code}" | grep -q "202\|200"
if [ $? -eq 0 ]; then
echo -e "${GREEN}PASS${NC}: Pause server"
else
echo -e "${RED}FAIL${NC}: Pause server"
fi
# Test 2: Unpause server
echo "Test 2: Unpause server"
curl -s -X POST "$NOVA_URL/v2.1/servers/$SERVER_ID/action" \
-H "X-Auth-Token: $TOKEN" \
-H "Content-Type: application/json" \
-d '{"unpause": null}' \
-w "%{http_code}" | grep -q "202\|200"
if [ $? -eq 0 ]; then
echo -e "${GREEN}PASS${NC}: Unpause server"
else
echo -e "${RED}FAIL${NC}: Unpause server"
fi
# Test 3: Lock server
echo "Test 3: Lock server"
curl -s -X POST "$NOVA_URL/v2.1/servers/$SERVER_ID/action" \
-H "X-Auth-Token: $TOKEN" \
-H "Content-Type: application/json" \
-d '{"lock": null}' \
-w "%{http_code}" | grep -q "202\|200"
if [ $? -eq 0 ]; then
echo -e "${GREEN}PASS${NC}: Lock server"
else
echo -e "${RED}FAIL${NC}: Lock server"
fi
# Test 4: Unlock server
echo "Test 4: Unlock server"
curl -s -X POST "$NOVA_URL/v2.1/servers/$SERVER_ID/action" \
-H "X-Auth-Token: $TOKEN" \
-H "Content-Type: application/json" \
-d '{"unlock": null}' \
-w "%{http_code}" | grep -q "202\|200"
if [ $? -eq 0 ]; then
echo -e "${GREEN}PASS${NC}: Unlock server"
else
echo -e "${RED}FAIL${NC}: Unlock server"
fi
# Test 5: Force delete server
echo "Test 5: Force delete server"
curl -s -X POST "$NOVA_URL/v2.1/servers/$SERVER_ID/action" \
-H "X-Auth-Token: $TOKEN" \
-H "Content-Type: application/json" \
-d '{"forceDelete": null}' \
-w "%{http_code}" | grep -q "202\|204"
if [ $? -eq 0 ]; then
echo -e "${GREEN}PASS${NC}: Force delete server"
else
echo -e "${RED}FAIL${NC}: Force delete server"
fi
curl -s -X DELETE "$GLANCE_URL/v2/images/$IMAGE_ID" -H "X-Auth-Token: $TOKEN" > /dev/null
echo "=== Test Summary ==="
echo "All Nova server action tests completed"