Cleanup image prepare script

This commit is contained in:
Ilya Shakhat
2015-02-04 16:46:38 +03:00
parent aaff5e4c7a
commit 0d15808d29
3 changed files with 38 additions and 10 deletions

View File

@@ -2,3 +2,17 @@ Shaker
======
Shake VMs with our sheer-class tests!
Installation
------------
The tool requires OpenStack clients to be installed and available from the system shell.
OpenStack user must be specified in the environment (e.g. like sourcing openrc file).
During installation the tool uploads Ubuntu cloud image, boots VM, installs all needed packages
into it and creates snapshot with name `shaker-image`.
To install:
1. Run `./bin/prepare.sh`
How to run
----------

View File

@@ -13,5 +13,5 @@ remote_shell() {
host=$1
key=$2
command=$3
ssh -i ${key} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ubuntu@${host} "$command"
ssh -i ${key} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 ubuntu@${host} "$command"
}

View File

@@ -10,7 +10,8 @@ setup_image() {
message "Installing Shaker image, will take some time"
message "Downloading Ubuntu cloud image"
IMG_FILE="shaker-template-image"
UUID=$(cat /proc/sys/kernel/random/uuid)
IMG_FILE="shaker-template-${UUID}"
glance image-create --name ${IMG_FILE} --disk-format qcow2 --container-format bare --is-public True --copy-from ${UBUNTU_CLOUD_IMAGE_URL}
until [ -n "$(glance image-show ${IMG_FILE} | grep status | grep active)" ]; do
@@ -18,25 +19,26 @@ setup_image() {
done
message "Creating security group"
SEC_GROUP="shaker-access"
SEC_GROUP="shaker-access-${UUID}"
nova secgroup-create ${SEC_GROUP} "Security Group for Shaker"
nova secgroup-add-rule ${SEC_GROUP} icmp -1 -1 0.0.0.0/0
nova secgroup-add-rule ${SEC_GROUP} tcp 1 65535 0.0.0.0/0
nova secgroup-add-rule ${SEC_GROUP} udp 1 65535 0.0.0.0/0
message "Creating flavor"
nova flavor-create --is-public true m1.mini 6 1024 10 1
FLAVOR_NAME="shaker-flavor"
nova flavor-create --is-public true ${FLAVOR_NAME} auto 1024 10 1
message "Creating key pair"
KEY_NAME="shaker-key"
KEY_NAME="shaker-key-${UUID}"
KEY="`mktemp`"
nova keypair-add ${KEY_NAME} > ${KEY_NAME}
nova keypair-add ${KEY_NAME} > ${KEY}
chmod og-rw ${KEY}
message "Booting VM"
NETWORK_ID=`neutron net-show net04 -f value -c id`
VM="shaker-template"
nova boot --poll --flavor m1.mini --image ${IMG_FILE} --key_name ${KEY} --nic net-id=${NETWORK_ID} --security-groups ${SEC_GROUP} ${VM}
nova boot --poll --flavor ${FLAVOR_NAME} --image ${IMG_FILE} --key_name ${KEY_NAME} --nic net-id=${NETWORK_ID} --security-groups ${SEC_GROUP} ${VM}
message "Associating a floating IP with VM"
FLOATING_IP=`neutron floatingip-create -f value -c floating_ip_address net04_ext | tail -1`
@@ -44,23 +46,33 @@ setup_image() {
message "Waiting for VM to boot up"
until remote_shell ${FLOATING_IP} ${KEY} "echo"; do
sleep 5
sleep 10
done
message "Installing packages into VM"
remote_shell ${FLOATING_IP} ${KEY} "sudo apt-add-repository \"deb http://nova.clouds.archive.ubuntu.com/ubuntu/ trusty multiverse\""
remote_shell ${FLOATING_IP} ${KEY} "sudo apt-get update"
remote_shell ${FLOATING_IP} ${KEY} "sudo apt-get -y install iperf netperf python-pip python-dev"
remote_shell ${FLOATING_IP} ${KEY} "sudo pip install netperf-wrapper numpy"
remote_shell ${FLOATING_IP} ${KEY} "sudo apt-get -y install iperf netperf python-pip git"
remote_shell ${FLOATING_IP} ${KEY} "sudo pip install netperf-wrapper"
message "Making VM snapshot"
nova image-create --poll ${VM} ${IMAGE_NAME}
glance image-update --is-public True ${IMAGE_NAME}
message "Destroy VM"
nova delete ${VM}
message "Waiting for VM to die"
until [ -z "$(nova list | grep ${VM})" ]; do
sleep 5
done
message "Cleaning up resources"
FP_ID=`neutron floatingip-list -f csv -c id -c floating_ip_address --quote none | grep ${FLOATING_IP} | awk -F "," '{print $1}'`
neutron floatingip-delete ${FP_ID}
nova secgroup-delete ${SEC_GROUP}
nova keypair-delete ${KEY_NAME}
}
main() {
@@ -68,6 +80,8 @@ main() {
echo "-- ${CHECK_IMAGE} --"
if [ "${CHECK_IMAGE}" == "" ]; then
setup_image
else
message "Image ${IMAGE_NAME} already exists"
fi
}