forked from openstack/kolla-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-openstack.sh
executable file
·130 lines (119 loc) · 4 KB
/
test-openstack.sh
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
#!/bin/bash
set -o xtrace
set -o errexit
set -o pipefail
# Enable unbuffered output for Ansible in Jenkins.
export PYTHONUNBUFFERED=1
function test_smoke {
openstack --debug compute service list
openstack --debug network agent list
}
function test_instance_boot {
echo "TESTING: Server creation"
openstack server create --wait --image cirros --flavor m1.tiny --key-name mykey --network demo-net kolla_boot_test
openstack --debug server list
# If the status is not ACTIVE, print info and exit 1
if [[ $(openstack server show kolla_boot_test -f value -c status) != "ACTIVE" ]]; then
echo "FAILED: Instance is not active"
openstack --debug server show kolla_boot_test
return 1
fi
echo "SUCCESS: Server creation"
if [[ $ACTION =~ "ceph" ]] || [[ $ACTION == "cinder-lvm" ]]; then
echo "TESTING: Cinder volume attachment"
openstack volume create --size 2 test_volume
attempt=1
while [[ $(openstack volume show test_volume -f value -c status) != "available" ]]; do
echo "Volume not available yet"
attempt=$((attempt+1))
if [[ $attempt -eq 10 ]]; then
echo "Volume failed to become available"
openstack volume show test_volume
return 1
fi
sleep 10
done
openstack server add volume kolla_boot_test test_volume --device /dev/vdb
attempt=1
while [[ $(openstack volume show test_volume -f value -c status) != "in-use" ]]; do
echo "Volume not attached yet"
attempt=$((attempt+1))
if [[ $attempt -eq 10 ]]; then
echo "Volume failed to attach"
openstack volume show test_volume
return 1
fi
sleep 10
done
openstack server remove volume kolla_boot_test test_volume
attempt=1
while [[ $(openstack volume show test_volume -f value -c status) != "available" ]]; do
echo "Volume not detached yet"
attempt=$((attempt+1))
if [[ $attempt -eq 10 ]]; then
echo "Volume failed to detach"
openstack volume show test_volume
return 1
fi
sleep 10
done
openstack volume delete test_volume
echo "SUCCESS: Cinder volume attachment"
fi
echo "TESTING: Server deletion"
openstack server delete --wait kolla_boot_test
echo "SUCCESS: Server deletion"
}
function check_dashboard {
# Query the dashboard, and check that the returned page looks like a login
# page.
DASHBOARD_URL=${OS_AUTH_URL%:*}
output_path=$1
if ! curl --include --location --fail $DASHBOARD_URL > $output_path; then
return 1
fi
if ! grep Login $output_path >/dev/null; then
return 1
fi
}
function test_dashboard {
echo "TESTING: Dashboard"
# The dashboard has been known to take some time to become accessible, so
# use retries.
output_path=$(mktemp)
attempt=1
while ! check_dashboard $output_path; do
echo "Dashboard not accessible yet"
attempt=$((attempt+1))
if [[ $attempt -eq 10 ]]; then
echo "FAILED: Dashboard did not become accessible. Response:"
cat $output_path
return 1
fi
sleep 10
done
echo "SUCCESS: Dashboard"
}
function test_openstack_logged {
. /etc/kolla/admin-openrc.sh
. ~/openstackclient-venv/bin/activate
test_smoke
test_instance_boot
test_dashboard
}
function test_openstack {
echo "Testing OpenStack"
log_file=/tmp/logs/ansible/test-openstack
if [[ -f $log_file ]]; then
log_file=${log_file}-upgrade
fi
test_openstack_logged > $log_file 2>&1
result=$?
if [[ $result != 0 ]]; then
echo "Testing OpenStack failed. See ansible/test-openstack for details"
else
echo "Successfully tested OpenStack. See ansible/test-openstack for details"
fi
return $result
}
test_openstack