Commit 282c940d authored by Reto Da Forno's avatar Reto Da Forno
Browse files

tools added

parent 08e7022b
......@@ -111,7 +111,7 @@ shutdown_timeout = 240
imagevalidator = /home/flocklab/testmanagementserver/targetimage_validator.py
binutils_arm = /home/flocklab/binutils/binutils-arm ;Path to ARM binutils
binutils_msp430 = /home/flocklab/binutils/binutils-msp430/usr/bin ;Path to MSP430 binutils
setsymbolsscript = /home/flocklab/binutils/tos-set-symbols ;Path to script used to set symbols (e.g. node ID)
setsymbolsscript = /home/flocklab/tools/tos-set-symbols ;Path to script used to set symbols (e.g. node ID)
; Recaptcha
[recaptcha]
......
#!/bin/bash
#
# ------------------------------
# Command line tool for FlockLab
# v1.4
#
# Usage:
#
# -v <testconfig.xml>: validate
# -c <testconfig.xml>: create
# -a <testid>: abort
# -d <testid>: delete
# -g <testid>: get via https
# -f <testid>: fetch via webdav
# -o <platform>: get a list of the currently available (online) observers
# -p: get a list of the available platforms
# -h: display help
#
# For the commands -g and -f, the download directory can be specified as an additional argument.
#
# Your FlockLab login credentials need to be stored in .flocklabauth in your home directory as follows:
# USER=[your_username]
# PASSWORD=[your_password]
#
# If you want to be able to download your test results via webdav (-f), you need to install the client 'cadaver'.
# ------------------------------
DEST=${3:-/tmp/flocklab} # destination directory (if not specified, the default is used: /tmp/flocklab)
EXTRACT=1 # extract results?
TESTCONFIG=0 # also download XML test config?
SERVER_URL=https://flocklab.ethz.ch
CURL_PARAMS='-sS -4 --insecure'
FLAUTH_FILE=.flocklabauth
NETRC_FILE=$HOME/.netrc
DAV_URL=https://flocklab-dev-server.ethz.ch/webdav
DAV_CLIENT=cadaver
if [ -f $FLAUTH_FILE ]
then
source ./$FLAUTH_FILE
elif [ -f $HOME/$FLAUTH_FILE ]
then
source $HOME/$FLAUTH_FILE
elif [ -f $NETRC_FILE ]
then
#echo "using credentials from .netrc file"
while read -r LINE; do
if [[ "${LINE,,}" == *"login"* ]]
then
USER=$(echo $LINE | awk '{print $2}')
elif [[ "${LINE,,}" == *"password"* ]]
then
PASSWORD=$(echo $LINE | awk '{print $2}')
fi
done < "$NETRC_FILE"
fi
usage()
{
cat << EOF
command line tool for FlockLab (${SERVER_URL})
usage: $0 [OPTION]
OPTIONS:
-v <testconfig.xml>: validate test config
-c <testconfig.xml>: create / schedule new test
-a <testid>: abort test
-d <testid>: delete test
-g <testid>: get test results (via https)
-f <testid>: fetch test results (via webdav)
-o <platform>: get a list of currently available observers
-p: get a list of available platforms
-h: display this help page
EOF
}
password()
{
cat << EOF
Wrong username / password
please check your settings in $FLAUTH_FILE
EOF
}
fetchtest()
{
# if .netrc file does not exist, create it
if [ ! -f $NETRC_FILE ]
then
echo "default
login $USER
password $PASSWORD" > $NETRC_FILE
chmod 600 $NETRC_FILE
echo ".netrc file created"
fi
TESTID=$OPTARG
if [ ! -d $DEST ]
then
mkdir $DEST
fi
if [ -d $DEST/$TESTID ]
then
echo "Error: directory $DEST/$TESTID already exists"
exit 1
fi
mkdir $DEST/$TESTID
$DAV_CLIENT > $DEST/$TESTID/dav.log 2>&1 <<EOF
open $DAV_URL
get $TESTID/testconfiguration.xml $DEST/$TESTID/testconfiguration.xml
get $TESTID/results.tar.gz $DEST/$TESTID/$TESTID.tar.gz
exit
EOF
if [ `sed '/^\(404\|500\)/!d' $DEST/$TESTID/dav.log | wc -l` -gt 0 ]
then
echo "Error occured while fetching data:"
cat $DEST/$TESTID/dav.log
rm -rf $DEST/$TESTID
else
echo "Downloaded data to $DEST/$TESTID"
if [ $EXTRACT -gt 0 ]
then
tar -xvzf $DEST/$TESTID/$TESTID.tar.gz -C $DEST
if [ $? -eq 0 ]
then
rm $DEST/$TESTID/$TESTID.tar.gz
fi
fi
if [ $TESTCONFIG -eq 0 ]
then
rm $DEST/$TESTID/testconfiguration.xml
fi
rm $DEST/$TESTID/dav.log
fi
}
if [ "$#" -lt 1 ]
then
usage
exit 1
fi
while getopts “v:c:a:d:f:g:o:ph” OPTION
do
case $OPTION in
v)
RESPONSE=`curl $CURL_PARAMS -o - -F username="$USER" -F password="$PASSWORD" -F first="no" -F xmlfile=@$OPTARG $SERVER_URL/xmlvalidate.php`
if [ $? -eq 0 ]
then
if [ `echo $RESPONSE | wc -m` -lt 2 ]
then
password
exit 1
fi
SUCCESS=`echo $RESPONSE | sed '/<p>The file validated correctly.<\/p>/!d' | wc -l`
if [ $SUCCESS -eq 0 ]
then
echo $RESPONSE | sed 's/.*<!-- cmd -->\(.*\)<!-- cmd -->.*/\1/;s/<li>/\n/g;s/<[^>]*>//g'
exit 1
else
echo 'The file validated correctly.'
fi
else
echo 'There were connection problems contacting the FlockLab server '$SERVER_URL
exit 1
fi
;;
c)
RESPONSE=`curl $CURL_PARAMS -o - -F username="$USER" -F password="$PASSWORD" -F first="no" -F xmlfile=@$OPTARG $SERVER_URL/newtest.php`
if [ $? -eq 0 ]
then
if [ `echo $RESPONSE | wc -m` -lt 2 ]
then
password
exit 1
fi
SUCCESS=`echo $RESPONSE | sed '/<!-- cmd --><p>Test (Id [0-9]*) successfully added.<\/p>/!d' | wc -l`
if [ $SUCCESS -eq 0 ]
then
echo $RESPONSE | sed 's/.*<!-- cmd -->\(.*\)<!-- cmd -->.*/\1/;s/<li>/\n/g;s/<[^>]*>//g'
exit 1
else
echo $RESPONSE | sed 's/.*<!-- flocklabscript\,\([0-9]*\),\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}+[0-9]\{4\}\),\([0-9]*\)-->.*/Test successfully added. Test ID: \1, Starttime: \2 (\3)/'
fi
else
echo 'There were connection problems contacting the FlockLab server '$SERVER_URL
exit 1
fi
;;
a)
RESPONSE=`curl $CURL_PARAMS -o - -F username="$USER" -F password="$PASSWORD" -F removeit="Remove test" -F testid=$OPTARG $SERVER_URL/test_abort.php`
if [ $? -eq 0 ]
then
if [ `echo $RESPONSE | wc -m` -lt 2 ]
then
password
exit 1
fi
SUCCESS=`echo $RESPONSE | sed '/<!-- cmd --><p>The test has been aborted.<\/p><!-- cmd -->/!d' | wc -l`
if [ $SUCCESS -eq 0 ]
then
echo $RESPONSE | sed 's/.*<!-- cmd -->\(.*\)<!-- cmd -->.*/\1/;s/<li>/\n/g;s/<[^>]*>//g'
exit 1
else
echo $RESPONSE | sed 's/.*<!-- cmd --><p>\(The test has been aborted\.\)<\/p><!-- cmd -->.*/\1/'
fi
else
echo 'There were connection problems contacting the FlockLab server '$SERVER_URL
exit 1
fi
;;
d)
RESPONSE=`curl $CURL_PARAMS -o - -F username="$USER" -F password="$PASSWORD" -F removeit="Remove test" -F testid=$OPTARG $SERVER_URL/test_delete.php`
if [ $? -eq 0 ]
then
if [ `echo $RESPONSE | wc -m` -lt 2 ]
then
password
exit 1
fi
SUCCESS=`echo $RESPONSE | sed '/<!-- cmd --><p>The test has been removed.<\/p><!-- cmd -->/!d' | wc -l`
if [ $SUCCESS -eq 0 ]
then
echo $RESPONSE | sed 's/.*<!-- cmd -->\(.*\)<!-- cmd -->.*/\1/;s/<li>/\n/g;s/<[^>]*>//g'
exit 1
else
echo $RESPONSE | sed 's/.*<!-- cmd --><p>\(The test has been removed\.\)<\/p><!-- cmd -->.*/\1/'
fi
else
echo 'There were connection problems contacting the FlockLab server '$SERVER_URL
exit 1
fi
;;
g)
echo "Fetching results for test $OPTARG ..."
if [ ! -d $DEST ]
then
mkdir $DEST
fi
OUTFILE=$DEST/$OPTARG.tar.gz
RESPONSE=`curl $CURL_PARAMS -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "testid=${OPTARG}&query=get&username=${USER}&password=${PASSWORD}" -o $OUTFILE $SERVER_URL/result_download_archive.php`
FILESIZE=`stat -c "%s" $OUTFILE`
if [ $FILESIZE -lt 1000 ]
then
OUTFILECONT=`cat $OUTFILE`
if [[ "$OUTFILECONT" == *"error"* ]]
then
ERRORMSG=`echo ${OUTFILECONT:1:-1} | awk -F':' '{print $3}'`
echo "Failed: "$ERRORMSG
rm $OUTFILE
exit 1
fi
fi
echo "Results saved as "$OUTFILE
if [ $EXTRACT -gt 0 ]
then
tar -xvzf $OUTFILE -C $DEST
if [ $? -eq 0 ]
then
rm $OUTFILE
fi
fi
if [ $TESTCONFIG -gt 0 ]
then
if [ $EXTRACT -gt 0 ]
then
OUTFILE=$DEST/$OPTARG/testconfiguration.xml
else
OUTFILE=$DEST/${OPTARG}_config.xml
fi
RESPONSE=`curl $CURL_PARAMS -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "testid=${OPTARG}&query=get&username=${USER}&password=${PASSWORD}" -o $OUTFILE $SERVER_URL/testconfig_download.php`
fi
;;
f)
which $DAV_CLIENT >> /dev/null
if [[ $? != 0 ]]
then
echo 'WebDAV client '$DAV_CLIENT' not found!'
exit 1
fi
echo "Fetching results for test $OPTARG ..."
fetchtest
;;
o)
RESPONSE=`curl $CURL_PARAMS -o - -F username="$USER" -F password="$PASSWORD" -F q="obs" -F platform=$OPTARG $SERVER_URL/api.php`
if [ $? -eq 0 ]
then
echo $RESPONSE
fi
;;
p)
RESPONSE=`curl $CURL_PARAMS -o - -F username="$USER" -F password="$PASSWORD" -F q="platform" $SERVER_URL/api.php`
if [ $? -eq 0 ]
then
echo $RESPONSE
fi
;;
h)
usage
exit 0
;;
?)
usage
exit 0
;;
esac
done
#!/bin/bash
# a simple wrapper to activate the conda virtual environment before executing a script
# for conda:
#export PATH=/home/flocklab/conda_venv/bin/python:$PATH
#[[ -f /scratch/flocklab/conda/bin/conda ]] && eval "$(/scratch/flocklab/conda/bin/conda shell.bash hook)"
#conda activate py36
# alternatively, add the above to .bashrc:
#source ~/.bashrc
# for pyvenv:
source ~/pyvenv/bin/activate
$*
......@@ -4,6 +4,7 @@
USER="flocklab"
HOST="flocklab-dev-server"
RSYNCPARAMS="-a -z -c -K --exclude=.git"
if [ $# -gt 0 ]; then
HOST=$1
......@@ -13,12 +14,13 @@ echo "Going to update files on FlockLab server $HOST..."
sleep 2 # give the user time to abort, just in case
# testmanagement server files
RES=$(rsync -a -z -c -i --dry-run --exclude=".git" -e "ssh -q" testmanagementserver/ ${USER}@${HOST}:testmanagementserver/ | grep '^<fc' | cut -d' ' -f2)
# optional to only look for changed files: | grep '^<fc' | cut -d' ' -f2
RES=$(rsync ${RSYNCPARAMS} -i --dry-run -e 'ssh -q' testmanagementserver ${USER}@${HOST}:testmanagementserver)
if [ -z "$RES" ]; then
echo "Testmanagement server files are up to date."
else
printf "Updating testmanagement server files... "
rsync -a -q -z -c --exclude=".git" -e "ssh -q" testmanagementserver ${USER}@${HOST}:
rsync ${RSYNCPARAMS} -e 'ssh -q' testmanagementserver ${USER}@${HOST}:
if [ $? -ne 0 ]; then
printf "Failed to copy files!\n"
continue
......@@ -27,12 +29,12 @@ else
fi
fi
# webserver files
RES=$(rsync -a -z -c -i -K --dry-run --exclude=".git" -e "ssh -q" webserver/ ${USER}@${HOST}:webserver/ | grep '^<fc' | cut -d' ' -f2)
RES=$(rsync ${RSYNCPARAMS} -i --dry-run -e 'ssh -q' webserver ${USER}@${HOST}:webserver)
if [ -z "$RES" ]; then
echo "Webserver files are up to date."
else
printf "Updating webserver files..."
rsync -a -q -z -c -K --exclude=".git" -e "ssh -q" webserver ${USER}@${HOST}:
rsync ${RSYNCPARAMS} -e 'ssh -q' webserver ${USER}@${HOST}:
if [ $? -ne 0 ]; then
printf "failed to copy repository files!\n"
continue
......@@ -40,4 +42,17 @@ else
printf "done.\n"
fi
fi
# tools
RES=$(rsync ${RSYNCPARAMS} -i --dry-run -e 'ssh -q' tools ${USER}@${HOST}:tools)
if [ -z "$RES" ]; then
echo "Tools are up to date."
else
printf "Updating tools... "
rsync ${RSYNCPARAMS} -e 'ssh -q' tools ${USER}@${HOST}:
if [ $? -ne 0 ]; then
printf "Failed to copy files!\n"
continue
else
printf "done.\n"
fi
fi
Supports Markdown
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