[[ "${CI_DEBUG:-true}" == [Tt]rue ]] && set -x
IMAGE_URL=https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
- IMAGE_NAME=cirros
+ #if an existing image name is provided in the enviroment, use that one
+ IMAGE_NAME=${IMAGE_NAME:-cirros}
IMAGE_FILE="${IMAGE_NAME}.img"
IMAGE_FORMAT=qcow2
VM_NAME=doctor_vm1
}
download_image() {
- [ -e "$IMAGE_FILE" ] && return 0
- wget "$IMAGE_URL" -o "$IMAGE_FILE"
+ #if a different name was provided for the image in the enviroment there's no need to download the image
+ use_existing_image=false
+ openstack image list | grep -q " $IMAGE_NAME " && use_existing_image=true
+
+ if [[ "$use_existing_image" == false ]] ; then
+ [ -e "$IMAGE_FILE" ] && return 0
+ wget "$IMAGE_URL" -o "$IMAGE_FILE"
+ fi
}
register_image() {
while [[ ${count} -lt 60 ]]
do
state=$(openstack $as_doctor_user server list | grep " $VM_NAME " | awk '{print $6}')
- [[ "$state" == "ACTIVE" ]] && return 0
+ if [[ "$state" == "ACTIVE" ]]; then
+ # NOTE(cgoncalves): sleeping for a bit to stabilize
+ # See python-openstackclient/functional/tests/compute/v2/test_server.py:wait_for_status
+ sleep 5
+ return 0
+ fi
[[ "$state" == "ERROR" ]] && echo "vm state is ERROR" && exit 1
count=$(($count+1))
sleep 1
image_id=$(openstack image list | grep " $IMAGE_NAME " | awk '{print $2}')
sleep 1
- [ -n "$image_id" ] && openstack image delete "$image_id"
+ #if an existing image was used, there's no need to remove it here
+ if [[ "$use_existing_image" == false ]] ; then
+ [ -n "$image_id" ] && openstack image delete "$image_id"
+ fi
openstack role remove "$DOCTOR_ROLE" --user "$DOCTOR_USER" \
--project "$DOCTOR_PROJECT"
openstack project delete "$DOCTOR_PROJECT"
echo "creating VM..."
boot_vm
wait_for_vm_launch
-openstack $as_doctor_user server show $VM_NAME
echo "get computer host info..."
get_compute_host_info
echo "creating alarm..."
-#TODO: change back to use, network problems depends on infra and installers
+#TODO: change back to use, network problems depends on infra and installers
#get_consumer_ip
create_alarm