Skip to content

Instantly share code, notes, and snippets.

@cygmris
Forked from BugRoger/volumes.sh
Created August 31, 2018 09:58
Show Gist options
  • Save cygmris/27293b8b96844a3f34263d8358cbe26d to your computer and use it in GitHub Desktop.
Save cygmris/27293b8b96844a3f34263d8358cbe26d to your computer and use it in GitHub Desktop.
Nova Volume Mount Error Reproduction
#!/bin/bash
COUNT=2
PREFIX=dup
function openstack {
docker run \
-e http_proxy= \
-e https_proxy= \
-e no_proxy= \
-e "OS_AUTH_URL=$OS_AUTH_URL" \
-e "OS_IDENTITY_API_VERSION=3" \
-e "OS_REGION_NAME=$OS_REGION_NAME" \
-e "OS_PROJECT_ID=$OS_PROJECT_ID" \
-e "OS_PROJECT_NAME=$OS_PROJECT_NAME" \
-e "OS_PROJECT_DOMAIN_NAME=$OS_PROJECT_DOMAIN_NAME" \
-e "OS_USER_ID=$OS_USER_ID" \
-e "OS_USERNAME=$OS_USERNAME" \
-e "OS_USER_DOMAIN_NAME=$OS_PROJECT_DOMAIN_NAME" \
-e "OS_PASSWORD=$OS_PASSWORD" \
hub.global.cloud.sap/monsoon/cc-openstack-cli:latest -- openstack "$@"
}
function create_volumes {
for i in $(seq 1 $COUNT)
do
echo Creating volume $PREFIX$i
openstack volume create --size=1 $PREFIX$i &
done
wait
}
function delete_volumes {
volumes=$(filter_volumes available)
for volume in $volumes
do
echo Deleting $volume
openstack volume delete $volume &
done
wait
}
function attach_volumes {
server=$(openstack server list --limit 1 -f value -c ID)
volumes=$(filter_volumes available)
for volume in $volumes
do
echo Attaching $volume to $server
openstack server add volume $server $volume &
done
wait
}
function detach_volumes {
server=$(openstack server list --limit 1 -f value -c ID)
volumes=$(filter_volumes in-use)
for volume in $volumes
do
echo Detaching $volume from $server
openstack server remove volume $server $volume &
done
wait
}
function filter_volumes {
status=$1
openstack volume list -c ID -c Status -f value | grep $status | cut -f 1 -d " "
}
function wait_for_volumes_to_be {
volumes=$(filter_volumes $1 | wc -l)
total=$(openstack volume list -f value | wc -l)
while [ $volumes -lt $total ]
do
echo "Waiting for all volumes to be $1 ($volumes/$total)"
sleep 1
volumes=$(filter_volumes $1 | wc -l)
done
}
# create_volumes
# wait_for_volumes_to_be available
attach_volumes
wait_for_volumes_to_be in-use
detach_volumes
wait_for_volumes_to_be available
delete_volumes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment