Commit faeb9a18 authored by Łukasz Nowak's avatar Łukasz Nowak

Pass through test script

parent 52353e5a
#!/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 }} ...@@ -5,8 +5,29 @@ develop-eggs-directory = {{ develop_eggs_directory }}
offline = true offline = true
parts = parts =
request-kvm
deploy-unit-test 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] [directory]
recipe = slapos.cookbook:mkdirectory recipe = slapos.cookbook:mkdirectory
home = ${buildout:directory} home = ${buildout:directory}
......
...@@ -14,4 +14,6 @@ context = ...@@ -14,4 +14,6 @@ context =
key eggs_directory buildout:eggs-directory key eggs_directory buildout:eggs-directory
key slapparameter_dict slap-configuration:configuration key slapparameter_dict slap-configuration:configuration
raw bin_directory ${buildout:bin-directory} 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 mode = 0644
...@@ -7,10 +7,20 @@ parts = ...@@ -7,10 +7,20 @@ parts =
[template] [template]
output = ${buildout:directory}/template-original.kvm.cfg 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] [template-cdn-test]
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg.in url = ${:_profile_base_location_}/instance.cfg.in
md5sum = 13f5bc9afd895d0c8b0b218a7c5ecb4b md5sum = 908c84181eab046757f2a1ef56174285
output = ${buildout:directory}/template.cfg output = ${buildout:directory}/template.cfg
mode = 0644 mode = 0644
...@@ -18,7 +28,7 @@ mode = 0644 ...@@ -18,7 +28,7 @@ mode = 0644
recipe = hexagonit.recipe.download recipe = hexagonit.recipe.download
ignore-existing = true ignore-existing = true
url = ${:_profile_base_location_}/instance-cdn-test.cfg.jinja2 url = ${:_profile_base_location_}/instance-cdn-test.cfg.jinja2
md5sum = abf54e393a1fe58dd6dfca37c38f7464 md5sum = cd030eaf5e66607b31497fdd07d6ed17
mode = 0644 mode = 0644
download-only = true download-only = true
on-update = 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