Skip to content

Instantly share code, notes, and snippets.

@ThinGuy
Created February 19, 2018 19:04
Show Gist options
  • Save ThinGuy/b47f70df3f1a3401d0dac754e63cd7ba to your computer and use it in GitHub Desktop.
Save ThinGuy/b47f70df3f1a3401d0dac754e63cd7ba to your computer and use it in GitHub Desktop.
Basic openstack tests as functions
####OpenStack Test Functions######
#This file should be sourced, not ran
###Prettyfication section####
tstatus() {
RC=$(echo $?)
[[ $RC -eq 0 ]] && { printf '\e[75G\e[1;37m[ \e[1;32mOK\e[1;37m ]\e[0m\n';return $RC; }
[[ $RC -eq 1 ]] && { printf '\e[75G\e[1;37m[\e[1;31mFAIL\e[1;37m]\e[0m\n';return $RC; }
}
ESpinner() {
local TheMsg="${1}"
local StrLen=$(echo "$TheMsg"|sed -e 's/\\e[[0-9;]*[a-zA-Z]//g' -e 's/\\n//g'|wc -c)
local bs=$'\b'
local ThePipes="⋮\u2003${bs} ⋰\u2003${bs} ⋯\u2003${bs} ⋱\u2003${bs}"
for pipe in $ThePipes;do
printf '\e[0m\e[3G'"${TheMsg}"'\e[77G\e[0m\e[0;38;5;208m'"${pipe}"'\r\e[0m'
sleep .045
done
printf '\e[0m\e[3G'"${TheMsg}"'\e[0m\e[77G\e[0m\e[0;38;5;208m\r\e[0m'
}
DULMsg() {
echo
printf "${@}"
local StrLen=$(($(echo ${@}|sed -e 's/\\e[[0-9;]*[a-zA-Z]//g' -e 's/\\n//g'|wc -c)-2))
[[ ${@} =~ .*\n$ || ${@} =~ .*\n.$ ]] || echo
printf '=%.0s' $(seq 0 1 ${StrLen});printf "${RT}\n"
}
###Begin Test Section####
user-check() {
clear
[[ -f ~/test-openrc.sh ]] && source ~/test-openrc.sh || { printf "\nCannot find ~/test-openrc.sh\n";exit; }
command -v openstack > /dev/null 2>&1 || { printf "\nERROR: ${0##*/} requires openstack tools to be installed\n";exit 1; }
}
user-list-test() {
STARTtime=$(date +"%s")
DULMsg "\nAuthentication Sanity Tests"
printf "\nListing Users...\n"
local LU=$(openstack user list);tstatus
[[ $? -eq 0 ]] && printf "${LU}" || return 1
printf "\nListing Projects...\n"
local PU=$(openstack project list);tstatus
[[ $? -eq 0 ]] && printf "${LU}" || return 1
ENDtime=$(date +"%s")
TOTALtime=$((${ENDtime}-${STARTtime}))
printf "\n\tTest took 0H:$(($TOTALtime / 60))M:$(($TOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log
unset ENDtime TOTALtime STARTtime
}
create-sec-groups() {
STARTtime=$(date +"%s")
echo
DULMsg "\nCreating Openstack Security Rules"
printf "\nCreating ICMP rule..."
openstack security group rule create --proto icmp default >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating ssh rule..."
openstack security group rule create --proto tcp --dst-port 22 default >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating http rule..."
openstack security group rule create --proto tcp --dst-port 80 default >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating https rule..."
openstack security group rule create --proto tcp --dst-port 443 default >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating RDP rule..."
openstack security group rule create --proto tcp --dst-port 3389 default >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating vnc rule..."
openstack security group rule create --proto tcp --dst-port 5900:5999 default >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating novnc rule..."
openstack security group rule create --proto tcp --dst-port 6080 default >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
openstack security group rule list
ENDtime=$(date +"%s")
TOTALtime=$((${ENDtime}-${STARTtime}))
printf "\n\tTest took 0H:$(($TOTALtime / 60))M:$(($TOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log
unset ENDtime TOTALtime STARTtime
}
delete-sec-groups() {
STARTtime=$(date +"%s")
echo
DULMsg "\nCreating Openstack Security Rules"
printf "Deleting ICMP rule..."
openstack security group rule delete $(openstack security group rule list|awk '/icmp/{print $2}') >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting ssh rule..."
openstack security group rule delete $(openstack security group rule list|awk '/22:22/{print $2}') >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting http rule..."
openstack security group rule delete $(openstack security group rule list|awk '/80:80/{print $2}') >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting https rule..."
openstack security group rule delete $(openstack security group rule list|awk '/443:443/{print $2}') >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting RDP rule..."
openstack security group rule delete $(openstack security group rule list|awk '/3389:3389/{print $2}') >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting vnc rule..."
openstack security group rule delete $(openstack security group rule list|awk '/5900:5999/{print $2}') >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting novnc rule..."
openstack security group rule delete $(openstack security group rule list|awk '/6080:6080/{print $2}') >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
openstack security group rule list
ENDtime=$(date +"%s")
TOTALtime=$((${ENDtime}-${STARTtime}))
printf "\n\tTest took 0H:$(($TOTALtime / 60))M:$(($TOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log
unset ENDtime TOTALtime STARTtime
}
import-rsa-key() {
STARTtime=$(date +"%s")
DULMsg "\nImport default public key"
printf "\nImporting ${USER}'s key..\n."
openstack keypair create --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus-key ~/.ssh/id_rsa.pub default >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
openstack keypair list
ENDtime=$(date +"%s")
TOTALtime=$((${ENDtime}-${STARTtime}))
printf "\n\tTest took 0H:$(($TOTALtime / 60))M:$(($TOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log
unset ENDtime TOTALtime STARTtime
}
delete-rsa-key() {
STARTtime=$(date +"%s")
DULMsg "\nDelete default public key\n"
openstack keypair delete $(openstack keypair list|awk '/default/{print $4}') >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
openstack keypair list
ENDtime=$(date +"%s")
TOTALtime=$((${ENDtime}-${STARTtime}))
printf "\n\tTest took 0H:$(($TOTALtime / 60))M:$(($TOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log
unset ENDtime TOTALtime STARTtime
}
create-flavors() {
STARTtime=$(date +"%s")
DULMsg "\nCreating Openstack Flavors"
#Remove the m1.tiny as it is too small for Ubuntu.
printf "\nCreating m1.nano flavor..."
openstack flavor create m1.nano --id auto --ram 64 --vcpus 1 --disk 1 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating m1.tiny flavor..."
openstack flavor create m1.tiny --id auto --ram 512 --vcpus 1 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating m1.small flavor..."
openstack flavor create m1.small --id auto --ram 2048 --vcpus 1 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating m1.medium flavor..."
openstack flavor create m1.medium --id auto --ram 4096 --vcpus 2 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating m1.large flavor..."
openstack flavor create m1.large --id auto --ram 8192 --vcpus 4 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating m1.xlarge flavor..."
openstack flavor create m1.xlarge --id auto --ram 16384 --vcpus 8 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating m1.xxlarge flavor..."
openstack flavor create m1.xxlarge --id auto --ram 32768 --vcpus 8 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating m1.xxxlarge flavor..."
openstack flavor create m1.xxxlarge --id auto --ram 65536 --vcpus 8 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating ram8cpu2 flavor..."
openstack flavor create ram8cpu2 --id auto --ram 8192 --vcpus 2 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating m1.nano flavor..."
openstack flavor create ram16cpu2 --id auto --ram 16384 --vcpus 2 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating ram16cpu2 flavor..."
openstack flavor create ram16cpu4 --id auto --ram 16384 --vcpus 4 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating ram16cpu4 flavor..."
openstack flavor create ram10cpu4 --id auto --ram 10240 --vcpus 4 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating ram10cpu4 flavor..."
openstack flavor create ram24cpu4 --id auto --ram 24576 --vcpus 4 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating ram24cpu4 flavor..."
openstack flavor create ram32cpu4 --id auto --ram 32768 --vcpus 4 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating ram32cpu4 flavor..."
openstack flavor create ram64cpu8 --id auto --ram 65536 --vcpus 8 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating ram64cpu8 flavor..."
openstack flavor create ram32cpu8 --id auto --ram 32768 --vcpus 8 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating ram32cpu8 flavor..."
openstack flavor create ram24cpu8 --id auto --ram 24576 --vcpus 8 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating ram24cpu8 flavor..."
openstack flavor create ram8cpu12 --id auto --ram 8192 --vcpus 12 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Creating ram32cpu16 flavor..."
openstack flavor create ram32cpu16 --id auto --ram 32768 --vcpus 16 --disk 20 --ephemeral 0 --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
openstack flavor list;sleep 2
ENDtime=$(date +"%s")
TOTALtime=$((${ENDtime}-${STARTtime}))
printf "\n\tTest took 0H:$(($TOTALtime / 60))M:$(($TOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log
echo
unset ENDtime TOTALtime STARTtime
}
delete-flavors() {
STARTtime=$(date +"%s")
DULMsg "\nDeleting Openstack Flavors"
printf "Deleting m1.nano flavor..."
openstack flavor delete m1.nano >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting m1.tiny flavor..."
openstack flavor delete m1.tiny >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting m1.small flavor..."
openstack flavor delete m1.small >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting m1.medium flavor..."
openstack flavor delete m1.medium >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting m1.large flavor..."
openstack flavor delete m1.large >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting m1.xlarge flavor..."
openstack flavor delete m1.xlarge >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting m1.xxlarge flavor..."
openstack flavor delete m1.xxlarge >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting m1.xxxlarge flavor..."
openstack flavor delete m1.xxxlarge >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting ram8cpu2 flavor..."
openstack flavor delete ram8cpu2 >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting m1.nano flavor..."
openstack flavor delete ram16cpu2 >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting ram16cpu2 flavor..."
openstack flavor delete ram16cpu4 >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting ram16cpu4 flavor..."
openstack flavor delete ram10cpu4 >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting ram10cpu4 flavor..."
openstack flavor delete ram24cpu4 >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting ram24cpu4 flavor..."
openstack flavor delete ram32cpu4 >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting ram32cpu4 flavor..."
openstack flavor delete ram64cpu8 >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting ram64cpu8 flavor..."
openstack flavor delete ram32cpu8 >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting ram32cpu8 flavor..."
openstack flavor delete ram24cpu8 >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting ram24cpu8 flavor..."
openstack flavor delete ram8cpu12 >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
printf "Deleting ram32cpu16 flavor..."
openstack flavor delete ram32cpu16 >> /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus
openstack flavor list;sleep 2
ENDtime=$(date +"%s")
TOTALtime=$((${ENDtime}-${STARTtime}))
printf "\n\tTest took 0H:$(($TOTALtime / 60))M:$(($TOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log
echo
unset ENDtime TOTALtime STARTtime
}
set-admin-quota() {
STARTtime=$(date +"%s")
DULMsg "\nSet quota for Admin Project"
for i in $(openstack project list|awk '/admin/{print $2}');do
printf "Setting large quota for $i to use during tempest testing..."
local AQ="$(openstack quota set --ram 2048000 --cores 2000 --instances 1000 $i)";tstatus
[[ $? -eq 0 ]] && printf "${AQ}"
done
ENDtime=$(date +"%s")
TOTALtime=$((${ENDtime}-${STARTtime}))
printf "\n\tTest took 0H:$(($TOTALtime / 60))M:$(($TOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log
unset ENDtime TOTALtime STARTtime
}
download-cloud-images() {
STARTtime=$(date +"%s")
DULMsg "\nDownload Cloud Images"
rm -rf /srv/data
IMG_FOLDER=/srv/data
sudo mkdir -p $IMG_FOLDER
sudo chown -R ubuntu:ubuntu $IMG_FOLDER
URLS="
http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img \
http://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img \
http://cloud-images.ubuntu.com/zesty/current/zesty-server-cloudimg-amd64.img \
http://mirror.catn.com/pub/catn/images/qcow2/centos6.4-x86_64-gold-master.img \
http://download.cirros-cloud.net/0.3.2/cirros-0.3.2-x86_64-disk.img
"
for URL in $URLS;do
if [[ -f $IMG_FOLDER/${URL##*/} ]];then
{ printf "${URL##*/} already exists.\n"; }
else
IMGDL=$(wget -q -O $IMG_FOLDER/${URL##*/} $URL >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1) &
pid=$!
trap '/usr/bin/setterm --cursor on; exec 2>&1; kill '$pid' 2>/dev/null; return; ' EXIT
setterm --cursor off
while kill -0 $pid 2>/dev/null;do
ESpinner "Downloading ${URL##*/}"
done
wait $pid
tstatus
trap - EXIT
setterm --cursor on
fi
done
ENDtime=$(date +"%s")
TOTALtime=$((${ENDtime}-${STARTtime}))
printf "\n\tTest took 0H:$(($TOTALtime / 60))M:$(($TOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log
unset ENDtime TOTALtime STARTtime
} 2>/dev/null
import-cloud-images() {
STARTtime=$(date +"%s")
DULMsg "\nImport Cloud Images"
for i in zesty xenial trusty centos cirros;do
IMG=$(find /srv/data/ -type f -name "*${i}*.img" -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")
IMGIMPORT=$(openstack image create --public >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1;tstatus --min-disk 3 --container-format ovf --disk-format qcow2 --property architecture=x86_64 --file ${IMG} "${i} x86_64 qcow2" >> /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log 2>&1) &
pid=$!
trap '/usr/bin/setterm --cursor on; exec 2>&1; kill '$pid' 2>/dev/null; return; ' EXIT
setterm --cursor off
while kill -0 $pid 2>/dev/null;do
ESpinner "Importing ${IMG##*/} into Glance"
done
wait $pid
tstatus
trap - EXIT
setterm --cursor on
done
openstack image list
ENDtime=$(date +"%s")
TOTALtime=$((${ENDtime}-${STARTtime}))
printf "\n\tTest took 0H:$(($TOTALtime / 60))M:$(($TOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log
} 2>/dev/null
smoke-test-insane() {
STARTtime=$(date +"%s")
local usage="
${FUNCNAME} -c <count> -n <network UUID> -i <image UUID> -f <flavor UUID> -p <prefix>
-c|-count\tNumber of VMs to launch
-n|--netowork\tUUID of an existing network (see openstack network list)
-i|--image\tUUID of an existing image (see openstack image list)
-f|--flavor\tUUID of an existing flavor (see openstack flavor list)
-p|--prefix\tName of the machine. Will be padded with up to 4 zeros
-h|--help\tThis message
\n
"
[[ -z ${1} ]] && { printf "$usage";return 0; }
ARGS=$(getopt -o c:n:i:f:s:p:h --long count:,network:,image:,flavor:,prefix:,help -n ${FUNCNAME} -- "$@")
[[ $? -eq 0 ]] && eval set -- "$ARGS" || { printf "$usage";return 1; }
while true;do
case "$1" in
-c|--count) local COUNT=$2;shift 2;;
-n|--network) local NUUID=$2;shift 2;;
-i|--image) local IUUID=$2;shift 2;;
-f|--flavor) local FUUID=$2;shift 2;;
-p|--prefix) local PREFIX=$2;shift 2;;
-h|--help) printf "$usage";return 0;;
--) shift;break;;
esac
done
[[ -z $COUNT ]] && localCOUNT=100
[[ -z $NUUID ]] && local NUUID=Public
[[ -z $IUUID ]] && local IUUID=xenial
[[ -z $SIZE ]] && local SIZE=small
[[ -z $PREFIX ]] && local PREFIX="smoke-test"
#Launch an instance
NUUID=$(openstack network list|awk '/'${NUUID}'/{print $2}')
IUUID=$(openstack image list|awk '/'${IUUID}'/{print $2;exit}')
FUUID=$(openstack flavor list|awk '/'${SIZE}'/{print $2}')
for (( c=1; c<=${COUNT}; c++ ));do echo "${PREFIX}-$(printf '%05d' $((10#${c})))";done|xargs -I@ -n1 -P${COUNT} nova boot --flavor ${FUUID} --key-name default --image $IUUID --nic net-id=$NUUID --security-groups default "@" > /tmp/${FUNCNAME}.log 2>&1 &
PID=$(pgrep -f "nova boot" -o)
while [[ -n $PID ]];do
nova list
PID=$(pgrep -f "nova boot" -o)
done
ENDtime=$(date +"%s")
TOTALtime=$((${ENDtime}-${STARTtime}))
printf "\n\tTest took 0H:$(($TOTALtime / 60))M:$(($TOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log
unset ENDtime TOTALtime STARTtime
}
smoke-test-serial() {
STARTtime=$(date +"%s")
local usage="
${FUNCNAME} -c <count> -n <network UUID> -i <image UUID> -f <flavor UUID> -p <prefix>
-c|-count\tNumber of VMs to launch
-n|--netowork\tUUID of an existing network (see openstack network list)
-i|--image\tUUID of an existing image (see openstack image list)
-f|--flavor\tUUID of an existing flavor (see openstack flavor list)
-p|--prefix\tName of the machine. Will be padded with up to 4 zeros
-h|--help\tThis message
\n
"
[[ -z ${1} ]] && { printf "$usage";return 0; }
ARGS=$(getopt -o c:n:i:f:s:p:h --long count:,network:,image:,flavor:,prefix:,help -n ${FUNCNAME} -- "$@")
[[ $? -eq 0 ]] && eval set -- "$ARGS" || { printf "$usage";return 1; }
while true;do
case "$1" in
-c|--count) local COUNT=$2;shift 2;;
-n|--network) local NUUID=$2;shift 2;;
-i|--image) local IUUID=$2;shift 2;;
-f|--flavor) local FUUID=$2;shift 2;;
-p|--prefix) local PREFIX=$2;shift 2;;
-h|--help) printf "$usage";return 0;;
--) shift;break;;
esac
done
[[ -z $COUNT ]] && localCOUNT=100
[[ -z $NUUID ]] && local NUUID=Public
[[ -z $IUUID ]] && local IUUID=xenial
[[ -z $SIZE ]] && local SIZE=small
[[ -z $PREFIX ]] && local PREFIX="smoke-test"
#Launch an instance
NUUID=$(openstack network list|awk '/'${NUUID}'/{print $2}')
IUUID=$(openstack image list|awk '/'${IUUID}'/{print $2;exit}')
FUUID=$(openstack flavor list|awk '/'${SIZE}'/{print $2}')
for (( c=1; c<=${COUNT}; c++ ));do
nova boot --flavor ${FUUID} --key-name default --image $IUUID --nic net-id=$NUUID --security-groups default "${PREFIX}-$(printf '%05d' $((10#${c})))" > /tmp/${FUNCNAME}.log 2>&1 &
nova list
done
ENDtime=$(date +"%s")
TOTALtime=$((${ENDtime}-${STARTtime}))
printf "\n\tTest took 0H:$(($TOTALtime / 60))M:$(($TOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log
unset ENDtime TOTALtime STARTtime
}
cleanup-smoke-test-instances() {
STARTtime=$(date +"%s")
local usage="
${FUNCNAME} -p <prefix>
-p|--prefix\tname of the machine. Will be padded with up to 4 zeros
-h|--help\tThis message
\n
"
[[ -z ${1} ]] && { printf "$usage";return 0; }
ARGS=$(getopt -o p:h --long prefix:,help -n ${FUNCNAME} -- "$@")
[[ $? -eq 0 ]] && eval set -- "$ARGS" || { printf "$usage";return 1; }
while true;do
case "$1" in
-p|--prefix) local PREFIX=$2;shift 2;;
-h|--help) printf "$usage";return 0;;
--) shift;break;;
esac
done
[[ -z $PREFIX ]] && local PREFIX="smoke-test"
local COUNT=$(nova list|grep -c ${PREFIX})
for i in $(nova list|awk '/'${PREFIX}'/{print $2}');do echo $i;done|xargs -I@ -n1 -P${COUNT} nova delete "@"
while [[ -n $(nova list |awk '/'${PREFIX}'/') ]];do
nova list
done
ENDtime=$(date +"%s")
TOTALtime=$((${ENDtime}-${STARTtime}))
printf "\n\tTest took 0H:$(($TOTALtime / 60))M:$(($TOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log
unset ENDtime TOTALtime STARTtime
}
bring-up() {
BUSTARTtime=$(date +"%s")
user-check
user-list-test
create-sec-groups
import-rsa-key
create-flavors
set-admin-quota
download-cloud-images
import-cloud-images
smoke-test-serial -c 50
BUENDtime=$(date +"%s")
BUTOTALtime=$((${BUENDtime}-${BUSTARTtime}))
printf "\n\tTotal bring up time took 0H:$(($BUTOTALtime / 60))M:$(($BUTOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-bu.$(date "+%Y.%m.%d-%H.%M.%S").log
unset BUSTARTtime BUENDtime BUTOTALtime
}
tear-down() {
TDSTARTtime=$(date +"%s")
delete-sec-groups
delete-rsa-key
delete-flavors
download-cloud-images
import-cloud-images
cleanup-smoke-test-instances -p "smoke-test"
TDENDtime=$(date +"%s")
TDTOTALtime=$((${TDENDtime}-${TDSTARTtime}))
printf "\n\tTotal tear down time took 0H:$(($TDTOTALtime / 60))M:$(($TDTOTALtime % 60))S to complete.\n\n" |tee -a /tmp/sanity-test-td.$(date "+%Y.%m.%d-%H.%M.%S").log
unset TDSTARTtime TDENDtime TDTOTALtime
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment