forked from huzichunjohn/openstack-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnova-resize-bench.sh
175 lines (147 loc) · 4.48 KB
/
nova-resize-bench.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
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
#!/usr/bin/env bash
#
# Benchmark "nova resize"
#
# Copyright © 2013 eNovance <[email protected]>
#
# Author: Emilien Macchi <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# OpenStack Credentials
export OS_TENANT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=password
export OS_AUTH_URL="http://<keystone-fqdn>:5000/v2.0/"
start=`date +%s`
# Funtions
create_volume () {
nova volume-create --display-name test 1
if ! timeout 30 sh -c "while ! cinder list | grep test | grep -q available; do sleep 1; done"; then
echo "Failed to create a volume!"
exit 1
fi
}
attach_volume () {
VOLUME_ID=$(cinder list | grep test | awk '{print $2}')
nova volume-attach scaling-test $VOLUME_ID /dev/vdb
if ! timeout 30 sh -c "while ! cinder list | grep test | grep -q "in-use"; do sleep 1; done"; then
echo "Failed to attach the volume!"
exit 1
fi
}
detach_volume () {
VOLUME_ID=$(cinder list | grep test | awk '{print $2}')
nova volume-detach scaling-test $VOLUME_ID
if ! timeout 30 sh -c "while ! cinder list | grep test | grep -q "available"; do sleep 1; done"; then
echo "Failed to attach the volume!"
exit 1
fi
}
# Spawn a small volume
echo " "
echo "We create a Small volume"
create_volume
# Spawn a small VM
echo " "
echo "We start a Small VM"
nova boot --poll --key_name test --image Cirros --flavor 2 scaling-test
if ! timeout 30 sh -c "while ! nova show scaling-test | grep status | grep -q ACTIVE; do sleep 1; done"; then
echo "server didn't become active!"
exit 1
fi
attach_volume
IP=$(nova show scaling-test | grep network | awk '{print $5}')
ping $IP>ping 2>/dev/null& pid=$!
# Resize the VM from small to Large
start1=`date +%s`
echo " "
echo "Resizing from Small to Large"
# Workaround for https://bugs.launchpad.net/nova/+bug/1190364
detach_volume
nova resize scaling-test 4
if ! timeout 30 sh -c "while ! nova show scaling-test | grep status | grep -q RESIZE; do sleep 1; done"; then
echo "Resize failed."
exit 1
fi
# Confirm Resizing
echo " "
echo "Confirm resizing"
if ! timeout 30 sh -c "while ! nova show scaling-test | grep status | grep -q VERIFY_RESIZE; do sleep 1; done"; then
echo "Resize failed."
exit 1
fi
nova resize-confirm scaling-test
if ! timeout 30 sh -c "while ! nova show scaling-test | grep status | grep -q ACTIVE; do sleep 1; done"; then
echo "Resize failed."
echo 1
fi
attach_volume
end1=`date +%s`
runtime1=$((end1-start1))
kill -INT $pid 2>/dev/null
lost1=$(grep transmitted ping)
echo " "
echo "The VM has been resized from small to large:"
nova show scaling-test
echo " "
# Resize the VM from Large to Tiny
start2=`date +%s`
ping $IP>ping 2>/dev/null& pid=$!
echo " "
echo "Resizing from Large to Tiny"
detach_volume
nova resize scaling-test 1
if ! timeout 30 sh -c "while ! nova show scaling-test | grep status | grep -q RESIZE; do sleep 1; done"; then
echo "Resize failed."
exit 1
fi
# Confirm Resizing
echo " "
echo "Confirm resizing"
if ! timeout 30 sh -c "while ! nova show scaling-test | grep status | grep -q VERIFY_RESIZE; do sleep 1; done"; then
echo "Resize failed."
exit 1
fi
nova resize-confirm scaling-test
if ! timeout 30 sh -c "while ! nova show scaling-test | grep status | grep -q ACTIVE; do sleep 1; done"; then
echo "Resize failed."
echo 1
fi
attach_volume
end2=`date +%s`
runtime2=$((end2-start2))
kill -INT $pid 2>/dev/null
lost2=$(grep transmitted ping)
echo " "
echo "The VM has been resized from Large to Tiny:"
nova show scaling-test
echo " "
# We delete the instance
nova delete scaling-test
rm ping
end=`date +%s`
runtime=$((end-start))
echo " "
echo "Resizing has been finished with success !"
echo " "
echo "Total time : $runtime seconds"
echo "Resize from Small to Large : $runtime1 seconds"
echo "Resize from Large to Tiny : $runtime2 seconds"
echo " "
echo "Network Stats during Small to Large resizing :"
echo $lost1
echo " "
echo "Network Stats during Large to Tiny resizing :"
echo $lost2