Commit 16b1c465 authored by Łukasz Nowak's avatar Łukasz Nowak

Pass through test script

parent 7581d70b
#!/bin/bash
# Script for testing deployment script
#
# Assumption: deployment script returning with code 0
# run correctly and everything is done
#
# This script is run inside of KVM, by passing its
# URL with bootstrap-script-url
# The script configuration happens by passing
# it in text form with data-to-vm
#
# Format of data-to-vm is shell script:
# URL=<url>\nWAITTIME=<seconds>\nTRIES=<amount>
#
# Expected values in configuration:
# * URL - the url of the script to download and test
# * WAITTIME - waiting time, before next try
# * TRIES - amount of tries
# Possible TODOs:
# * post results on each try
# * use function + trap to assure posting on exit
LOG_FILE=/var/log/test-script-deployment.log
wget -O /tmp/test-script.cfg.$$ -q http://10.0.2.100/data
source /tmp/test-script.cfg.$$
if [ -z "$LOG_FILE" ] ; then
echo "Output log file is missing"
exit 1
fi
if [ -z "$URL" ] ; then
echo "URL is missing" >> $LOG_FILE 2>&1
exit 1
fi
if [ -z "$WAITTIME" ] ; then
echo "WAITTIME missing" >> $LOG_FILE 2>&1
exit 1
fi
if [ -z "$TRIES" ] ; then
echo "TRIES missing" >> $LOG_FILE 2>&1
exit 1
fi
DEPLOYMENT_SCRIPT=/tmp/test-script-deployment.bash.$$
wget -O $DEPLOYMENT_SCRIPT -q $URL
try=1
while true; do
echo "$0: Try $try. Running '/bin/bash $DEPLOYMENT_SCRIPT'" >> $LOG_FILE 2>&1
/bin/bash $DEPLOYMENT_SCRIPT >> $LOG_FILE 2>&1
result=$?
if [ $result == 0 ] ; then
echo "$0: Try $try. Script executed successfully." >> $LOG_FILE 2>&1
break
fi
if (( try > TRIES )) ; then
echo "$0: Try $try. Amount of tries $TRIES exceeded, giving up." >> $LOG_FILE 2>&1
break
fi
# wait WAITTIME before checking the state
echo "$0: Try $try. Sleeping $WAITTIME before retry." >> $LOG_FILE 2>&1
sleep $WAITTIME
((try++))
done
echo "$0: Try $try. Uploading log and exiting with $result." >> $LOG_FILE 2>&1
t=`date '+%Y%m%d%H%S'`
mv $LOG_FILE ${LOG_FILE}.$t
curl -q -X POST --data-urlencode "path=test-script-result/log-file.log.$t" --data-urlencode "content@${LOG_FILE}.$t" http://10.0.2.100/
exit $result
......@@ -5,8 +5,29 @@ develop-eggs-directory = {{ develop_eggs_directory }}
offline = true
parts =
request-kvm
deploy-unit-test
[request-kvm]
<= slap-connection
recipe = slapos.cookbook:request
software-url = ${slap-connection:software-release-url}
software-type = kvm
name = test-kvm
sla-computer_guid = ${slap-connection:computer-id}
# Tested image
# Passed by request
config-virtual-hard-drive-url = {{ slapparameter_dict.get('image-to-test-url') }}
config-virtual-hard-drive-md5sum = {{ slapparameter_dict.get('image-to-test-md5sum') }}
# The test script
config-bootstrap-script-url = {{ in_vm_test_script }}#{{ in_vm_test_script_md5 }}
# require HTTP server
config-enable-http-server = true
[directory]
recipe = slapos.cookbook:mkdirectory
home = ${buildout:directory}
......
......@@ -14,4 +14,6 @@ context =
key eggs_directory buildout:eggs-directory
key slapparameter_dict slap-configuration:configuration
raw bin_directory ${buildout:bin-directory}
raw in_vm_test_script ${in-vm-test-script:location}/${in-vm-test-script:filename}
raw in_vm_test_script_md5 ${in-vm-test-script:md5sum}
mode = 0644
......@@ -7,10 +7,20 @@ parts =
[template]
output = ${buildout:directory}/template-original.kvm.cfg
[in-vm-test-script]
recipe = slapos.recipe.download
ignore-existing = true
filename = in-vm-test
url = ${:_profile_base_location_}/${:filename}
md5sum = 9039e7515483a9d64396b28fc43c678c
mode = 0644
download-only = true
on-update = true
[template-cdn-test]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg.in
md5sum = 13f5bc9afd895d0c8b0b218a7c5ecb4b
md5sum = 908c84181eab046757f2a1ef56174285
output = ${buildout:directory}/template.cfg
mode = 0644
......@@ -18,7 +28,7 @@ mode = 0644
recipe = hexagonit.recipe.download
ignore-existing = true
url = ${:_profile_base_location_}/instance-cdn-test.cfg.jinja2
md5sum = abf54e393a1fe58dd6dfca37c38f7464
md5sum = cd030eaf5e66607b31497fdd07d6ed17
mode = 0644
download-only = true
on-update = true
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment