From 6f8f4f6a1b74e49246d331bf5f9e49c132f8f5bd Mon Sep 17 00:00:00 2001 From: varac Date: Wed, 3 Sep 2014 17:00:25 +0200 Subject: first round of linting --- leap-platform-test | 158 ++++++++++++++++++++++++++--------------------------- 1 file changed, 78 insertions(+), 80 deletions(-) diff --git a/leap-platform-test b/leap-platform-test index ac707ed..e003ef8 100755 --- a/leap-platform-test +++ b/leap-platform-test @@ -30,7 +30,7 @@ EOF add_nodes() { suffix=$IP_SUFFIX_START - for i in $@ + for i in "$@" do node=${i%:*} services=${i#*:} @@ -45,48 +45,48 @@ add_nodes() { ;; esac - $LEAP_CMD node add --local $node ip_address:$ip $config services:$services + $LEAP_CMD node add --local "$node" ip_address:"$ip" "$config" services:"$services" done } bootstrap_nodes() { - for vm in $@ + for vm in "$@" do - $LEAP_CMD $OPTS local start $vm - wait_for_node $vm - $LEAP_CMD $OPTS node init $vm + $LEAP_CMD "$OPTS" local start "$vm" + wait_for_node "$vm" + $LEAP_CMD "$OPTS" node init "$vm" # set hostname + do dist-upgrade - $LEAP_CMD $OPTS deploy $vm --tags site_apt::dist_upgrade,site_config::hosts,site_squid_deb_proxy::client - $LEAP_CMD $OPTS local save $vm + $LEAP_CMD "$OPTS" deploy "$vm" --tags site_apt::dist_upgrade,site_config::hosts,site_squid_deb_proxy::client + $LEAP_CMD "$OPTS" local save "$vm" done } create_provider() { - if [ -e $PROVIDERDIR ] + if [ -e "$PROVIDERDIR" ] then - echo $PROVIDERDIR exists - exiting + echo "$PROVIDERDIR" exists - exiting exit 1 fi - mkdir -p $PROVIDERDIR - cd $PROVIDERDIR + mkdir -p "$PROVIDERDIR" + cd "$PROVIDERDIR" - $LEAP_CMD $OPTS new --contacts $CONTACTS --domain $DOMAIN --name $PROVIDER --platform=$PLATFORMDIR . - cd $PLATFORMDIR - git checkout $PLATFORM_BRANCH + $LEAP_CMD "$OPTS" new --contacts "$CONTACTS" --domain "$DOMAIN" --name "$PROVIDER" --platform="$PLATFORMDIR" . + cd "$PLATFORMDIR" + git checkout "$PLATFORM_BRANCH" git submodule sync git submodule update --init - cd $PROVIDERDIR + cd "$PROVIDERDIR" # for now, we use the vagrant pubkey until https://leap.se/code/issues/2039 is solved - $LEAP_CMD $OPTS add-user --self --ssh-pub-key=$SSHKEY - $LEAP_CMD $OPTS cert ca && leap cert csr + $LEAP_CMD "$OPTS" add-user --self --ssh-pub-key="$SSHKEY" + $LEAP_CMD "$OPTS" cert ca && leap cert csr # copy for faster testing #cp $ROOTDIR/dh.pem.test $PROVIDERDIR/files/ca/dh.pem - $LEAP_CMD $OPTS cert dh - add_nodes $NODES + $LEAP_CMD "$OPTS" cert dh + add_nodes "$NODES" } deploy() { @@ -105,33 +105,33 @@ deploy() { fi - for vm in $@ + for vm in "$@" do - [ -e $LOGDIR ] || mkdir -p $LOGDIR - date=`date +"%F-%H%M%S"` + [ -e "$LOGDIR" ] || mkdir -p "$LOGDIR" + date=$( date +"%F-%H%M%S" ) LOG1="$LOGDIR/deploy-$vm.log" LOG2="$LOGDIR/deploy-$vm-$date.log" ERRLOG1="$LOGDIR/deploy-$vm-$date-error.log" ERRLOG2="$LOGDIR/deploy-error.log" - echo "Deploying \"$vm\" on `date`"|tee -a $LOG1 $LOG2 + echo "Deploying \"$vm\" on $( date )"|tee -a "$LOG1" "$LOG2" - $LEAP_CMD $OPTS -v 2 deploy $vm 2>&1 | tee -a $LOG1 $LOG2 | egrep -v "$FILTER_ALL" | tee -a $ERRLOG1 $ERRLOG2 > /dev/null + $LEAP_CMD "$OPTS" -v 2 deploy "$vm" 2>&1 | tee -a "$LOG1" "$LOG2" | egrep -v "$FILTER_ALL" | tee -a "$ERRLOG1" "$ERRLOG2" > /dev/null - if [ -s $ERRLOG1 ] + if [ -s "$ERRLOG1" ] then - touch $deploy_failure - versions=`versions` + touch "$deploy_failure" + versions=$( versions ) msg="From: $MAIL_FROM\nTo: $MAIL_TO\nSubject: WARNING - \"leap deploy\" of platform $PLATFORM_BRANCH branch on \"$vm\" had errors !\n\n" - echo "`date`: $msg" | tee -a $LOG1 $LOG2 $ERRLOG2 + echo "$( date ): $msg" | tee -a "$LOG1" "$LOG2" "$ERRLOG2" echo - msg="${msg} Output of error log below:\n\n`cat $ERRLOG1` \n\n" + msg="${msg} Output of error log below:\n\n$( cat "$ERRLOG1" ) \n\n" msg="${msg}-------------------------------------------------------------------\n\n" msg="${msg}error log: ${ERRLOG1}\n" msg="${msg}comlete log: ${LOG2}\n\n" - msg="${msg}Tested on `date` on \"$vm\" with following versions/git commit IDs: \n\n$versions" + msg="${msg}Tested on $( date ) on \"$vm\" with following versions/git commit IDs: \n\n$versions" - cat $ERRLOG1 + cat "$ERRLOG1" if [ "$MAIL_TO" != '' ]; then echo "Sending this mail to $MAIL_TO:" @@ -139,24 +139,24 @@ deploy() { fi else - echo "Deploy to $vm on `date` went fine."| tee -a $LOG1 $LOG2 - rm $ERRLOG1 + echo "Deploy to $vm on $( date ) went fine."| tee -a "$LOG1" "$LOG2" + rm "$ERRLOG1" fi done } get_ip () { - grep ip_address $PROVIDERDIR/nodes/$1.json |cut -f 2 -d:|sed 's/[",]//g' + grep ip_address "$PROVIDERDIR/nodes/$1.json" |cut -f 2 -d:|sed 's/[",]//g' } ip_pingable () { - ping -q -W10 -c1 $1 >/dev/null 2>&1 + ping -q -W10 -c1 "$1" >/dev/null 2>&1 return $? } log_start() { echo - echo "Starting $0 on `date`" + echo "Starting $0 on $( date )" } @@ -166,17 +166,17 @@ reset_deploy() { update_platform update_leap_cli - cd $PROVIDERDIR + cd "$PROVIDERDIR" log_start - echo "Starting deploy_nodes for nodes $@ as background tasks on `date`" + echo "Starting deploy_nodes for nodes $@ as background tasks on $( date )" for i in $nodes do - $LEAP_CMD $OPTS local reset $i - wait_for_node $i - deploy $i & + $LEAP_CMD "$OPTS" local reset "$i" + wait_for_node "$i" + deploy "$i" & done # needed in a detached screen session, otherwise it would terminate before deploy jobs @@ -185,11 +185,11 @@ reset_deploy() { wait - if [ ! -e $deploy_failure -a -n $MAIL_TO ] + if [ ! -e "$deploy_failure" -a -n "$MAIL_TO" ] then - versions=`versions` + versions=$( versions ) msg="From: $MAIL_FROM\nTo: $MAIL_TO\nSubject: OK - \"leap deploy\" of platform $PLATFORM_BRANCH branch went fine.\n\n" - msg="${msg}Tested on `date` on these nodes: \"$nodes\"\nwith following versions/git commit IDs: \n\n$versions" + msg="${msg}Tested on $( date ) on these nodes: \"$nodes\"\nwith following versions/git commit IDs: \n\n$versions" echo "Sending deploy success mail to $MAIL_TO" printf "$msg" | /usr/sbin/sendmail -t @@ -198,8 +198,8 @@ reset_deploy() { run_tests test_failure=$? - versions=`versions` - msg="Tested on `date` on these nodes: \"$nodes\"\nwith following versions/git commit IDs: \n\n$versions" + versions=$( versions ) + msg="Tested on $( date ) on these nodes: \"$nodes\"\nwith following versions/git commit IDs: \n\n$versions" if [ $test_failure -eq 0 ] then subj="OK - \"leap test\" of platform $PLATFORM_BRANCH branch is all green." @@ -207,64 +207,64 @@ reset_deploy() { subj="WARNING - \"leap test\" of platform $PLATFORM_BRANCH branch failed !!" fi - echo $subj + echo "$subj" echo "Sending test mail to $MAIL_TO" # unfortunatly, no tls atm, fixed in sendemail 1.56-3 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=679911 - sendemail -f $MAIL_FROM -t $MAIL_TO -o tls=no -m "${msg}" -u "${subj}" -a $TEST_LOG2 + sendemail -f "$MAIL_FROM" -t "$MAIL_TO" -o tls=no -m "${msg}" -u "${subj}" -a "$TEST_LOG2" } ssh_up () { - nc -w 4 $1 22 > /dev/null + nc -w 4 "$1" 22 > /dev/null return $? } run_tests () { - date=`date +"%F-%H%M%S"` + date=$( date +"%F-%H%M%S" ) TEST_FILTER='net.ssh.authentication.agent.*could not connect to ssh-agent' - echo -e "\nRunning leap test on `date`" | tee -a $TEST_LOG1 $TEST_LOG2 - $LEAP_CMD $OPTS test 2>&1 | egrep -v "$TEST_FILTER" | tee -a $TEST_LOG1 $TEST_LOG2 + echo -e "\nRunning leap test on $date" | tee -a "$TEST_LOG1" "$TEST_LOG2" + $LEAP_CMD "$OPTS" test 2>&1 | egrep -v "$TEST_FILTER" | tee -a "$TEST_LOG1" "$TEST_LOG2" test_failure=${PIPESTATUS[0]} if [ $test_failure -ne 0 ] then - echo 'WARNING - "leap test" failed !' | tee -a $TEST_LOG1 $TEST_LOG2 + echo 'WARNING - "leap test" failed !' | tee -a "$TEST_LOG1" "$TEST_LOG2" else - echo 'OK - "leap test" is all green !' | tee -a $TEST_LOG1 $TEST_LOG2 + echo 'OK - "leap test" is all green !' | tee -a "$TEST_LOG1" "$TEST_LOG2" fi - return $test_failure + return "$test_failure" } update_leap_cli () { - cd $LEAP_SRC + cd "$LEAP_SRC" git pull sudo bundle } update_platform () { - cd $PLATFORMDIR + cd "$PLATFORMDIR" git pull } versions () { - cd $PLATFORMDIR - platform_head=`git rev-parse HEAD` - platform_commit=`git show | head -6` + cd "$PLATFORMDIR" + platform_head=$( git rev-parse HEAD ) + platform_commit=$( git show | head -6 ) - cd $LEAP_SRC - cli_head=`git rev-parse HEAD` - cli_commit=`git show $cli_head | head -6` + cd "$LEAP_SRC" + cli_head=$( git rev-parse HEAD ) + cli_commit=$( git show "$cli_head" | head -6 ) - cd $PROVIDERDIR - [ -d .git ] && provider_head=`git rev-parse HEAD` - if [ -n $provider_head ] + cd "$PROVIDERDIR" + [ -d .git ] && provider_head=$( git rev-parse HEAD ) + if [ -n "$provider_head" ] then provider_head='not under version control' fi @@ -287,12 +287,12 @@ versions () { wait_for_node() { vm=$1 - ip=`get_ip $vm` + ip=$( get_ip "$vm" ) online=0 echo "Waiting for ssh on VM $vm (IP: $ip) to come up..." while [ $online -eq 0 ] do - ssh_up $ip && online=1 + ssh_up "$ip" && online=1 sleep 1 done } @@ -346,7 +346,7 @@ nodelist=$@ #echo "nodelist: $nodelist" #echo "all: $all" -if [ -z $config ] +if [ -z "$config" ] then usage echo "Please provide a config file" @@ -354,26 +354,26 @@ then fi # provider specific config -source $config +source "$config" # common config for all providers source /etc/leap/platform-test-common.cfg -date=`date +"%F-%H%M%S"` +date=$( date +"%F-%H%M%S" ) TEST_LOG1="$LOGDIR/test.log" TEST_LOG2="$LOGDIR/test-$date.log" -[ -e $PROVIDERDIR ] && cd $PROVIDERDIR +[ -e "$PROVIDERDIR" ] && cd "$PROVIDERDIR" if $print_versions then - versions=`versions` + versions=$( versions ) echo "$versions" echo exit 0 fi -if [ -z $LEAP_CMD -o -z $LEAP_SRC ] +if [ -z "$LEAP_CMD" -o -z "$LEAP_SRC" ] then echo "please provide a path to the leap_cli binary and the source in the config file, using the LEAP_CMD and LEAP_SRC var." exit 1 @@ -386,15 +386,15 @@ if $all ; then # strip services from nodes_services # i.e. nodes_services='redevcouchdb1:couchdb redevcouchdb2:couchdb' # -> nodes='redevcouchdb1 redevcouchdb2' - nodes=`echo "$NODES" | sed 's/:[[:alnum:],]*//g'` + nodes=$( echo "$NODES" | sed 's/:[[:alnum:],]*//g' ) else # use nodelist provided via cmdline parameters nodes=$nodelist fi -if [[ "`pidof -x $(basename $0) -o %PPID`" ]] +if [[ $( pidof -x "$( basename "$0" )" -o %PPID ) ]] then - echo "Other process(es) found running for $(basename $0) - exiting." + echo "Other process(es) found running for $(basename "$0") - exiting." exit 1 fi @@ -407,5 +407,3 @@ case $cmd in test) run_tests "$nodes";; (*) usage; echo "Please specify a command."; exit 1;; esac - - -- cgit v1.2.3