2012-12-13 16:29:10 +00:00
|
|
|
#!/bin/bash -ex
|
2012-11-28 23:07:43 +00:00
|
|
|
|
|
|
|
RUN_TIME=300 # approximate duration of run (seconds)
|
|
|
|
|
|
|
|
[ $# -eq 1 ] && RUN_TIME="$1"
|
|
|
|
|
|
|
|
IMAGE_NAME="image-$$"
|
|
|
|
IMAGE_SIZE="1024" # MB
|
|
|
|
|
|
|
|
function get_time() {
|
|
|
|
date '+%s'
|
|
|
|
}
|
|
|
|
|
|
|
|
function times_up() {
|
|
|
|
local end_time="$1"
|
|
|
|
|
|
|
|
test $(get_time) -ge "${end_time}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function map_unmap() {
|
|
|
|
[ $# -eq 1 ] || exit 99
|
|
|
|
local image_name="$1"
|
|
|
|
|
2014-06-26 13:34:19 +00:00
|
|
|
local dev
|
|
|
|
dev="$(sudo rbd map "${image_name}")"
|
|
|
|
sudo rbd unmap "${dev}"
|
2012-11-28 23:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#### Start
|
|
|
|
|
2014-06-26 13:34:19 +00:00
|
|
|
rbd create "${IMAGE_NAME}" --size="${IMAGE_SIZE}"
|
2012-11-28 23:07:43 +00:00
|
|
|
|
|
|
|
COUNT=0
|
|
|
|
START_TIME=$(get_time)
|
|
|
|
END_TIME=$(expr $(get_time) + ${RUN_TIME})
|
|
|
|
while ! times_up "${END_TIME}"; do
|
|
|
|
map_unmap "${IMAGE_NAME}"
|
|
|
|
COUNT=$(expr $COUNT + 1)
|
|
|
|
done
|
|
|
|
ELAPSED=$(expr "$(get_time)" - "${START_TIME}")
|
|
|
|
|
2014-06-26 13:34:19 +00:00
|
|
|
rbd rm "${IMAGE_NAME}"
|
2012-11-28 23:07:43 +00:00
|
|
|
|
2014-06-26 13:34:19 +00:00
|
|
|
echo "${COUNT} iterations completed in ${ELAPSED} seconds"
|