You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
4.8 KiB

#!/usr/bin/env bash
DESC="Teste les TPs de 1A sur bigboss et tiny."
SYSTEMS="bigboss tiny societe lambda web"
testTp1Part1() {
echo "[TP n°1 partie bigboss]"
echo
vdnTest "hostname bigboss ......... ?" 'vdn-ssh root@bigboss "test \"\$(hostname)\" = bigboss"'
vdnTest "ip bigboss ............... ?" 'vdn-ssh root@bigboss "ip addr show eth0 | grep -Fq 192.168.30.2"'
vdnTest "ping bigboss -> tiny ..... ?" 'vdn-ssh root@bigboss "timeout 2 ping -c 1 tiny &> /dev/null"'
vdnTest "ping bigboss -> bigboss .. ?" 'vdn-ssh root@bigboss "timeout 2 ping -c 1 bigboss &> /dev/null"'
}
testTp1Part2() {
echo "[TP n°1 partie tiny]"
echo
vdnTest "hostname tiny ............ ?" 'vdn-ssh root@tiny "test \"\$(hostname)\" = tiny"'
vdnTest "ip tiny .................. ?" 'vdn-ssh root@tiny "ip addr show eth1 | grep -Fq 192.168.30.16"'
vdnTest "ping tiny -> bigboss .. ?" 'vdn-ssh root@tiny "timeout 2 ping -c 1 bigboss &> /dev/null"'
vdnTest "ping tiny -> tiny ..... ?" 'vdn-ssh root@tiny "timeout 2 ping -c 1 tiny &> /dev/null"'
}
testTp2() {
echo "[TP n°1 partie \"utilisateurs\"]"
echo
vdnTest "user toto sur bigboss .... ?" 'vdn-ssh root@bigboss "id toto &> /dev/null"'
vdnTest "user titi sur tiny ....... ?" 'vdn-ssh root@tiny "id titi &> /dev/null"'
echo
echo "[TP n°2]"
echo
vdnTest "NFS lecture seule (ro) ... ?" '
vdn-ssh root@tiny "
[ ! -d /mnt/bigboss ] && mkdir /mnt/bigboss;
timeout 3 mount bigboss:/overlays/ro/usr/share/doc /mnt/bigboss;
[ ! -e /mnt/bigboss/xterm ] && exit 1;
umount /mnt/bigboss;
"'
}
testTp3() {
echo "[TP n°3]"
echo
tinyMAC=$(vdn-ssh root@tiny ifconfig eth1 | grep ether)
tinyMAC=$(echo "$tinyMAC" | sed -re 's/^.*ether ([[:xdigit:]:]*).*$/\1/')
vdnTest "DHCP configuré sur bigboss ....... ?" "vdn-ssh root@bigboss \"grep -iq '^[^#]*$tinyMAC' /etc/dhcp/dhcpd.conf\""
vdnTest "DHCP sur bigboss : actif ......... ?" "vdn-ssh root@bigboss \"systemctl status isc-dhcp-server | grep -q 'Active: active'\""
echo
vdnTest "FTP anonyme sur bigboss .......... ?" "vdn-ssh root@tiny 'set -x; echo -e \"open bigboss\nuser anonymous test@bidule.com\nls\" | ftp -i -n | grep -q welcome'"
echo
#vdnTest "bigboss run apache2 .............. ?" "vdn-ssh root@tiny 'netcat -w 1 bigboss 80 &> /dev/null < /dev/null'"
vdnTest "bigboss run apache2 .............. ?" "vdn-ssh root@tiny 'timeout 2 lynx -dump bigboss &> /dev/null'"
e=$?
if [ $e = 0 ]; then
vdnTest "bigboss run apache2 with userdir . ?" "vdn-ssh root@tiny 'unset http_proxy; \
timeout 2 lynx -dump bigboss/~toto 2> /dev/null | grep -iv \"Not found\"'"
vdnTest "toto@bigboss avec HTTP protégé ... ?" "vdn-ssh root@bigboss '\
find /home/toto/public_html -name .htaccess 2> /dev/null | grep -q htaccess$'"
else
echo >&2
echo "Subsequent tests canceled !" >&2
return 1
fi
}
testTp4() {
echo "[TP n°4]"
echo
vdnTest "tiny -> web ....................... ?" "vdn-ssh root@tiny 'unset http_proxy; timeout 2 lynx -dump web'"
echo
vdnTest "root@bigboss id_rsa/id_rsa.pub .... ?" "vdn-ssh root@bigboss 'ls -l ~/.ssh/id_rsa &> /dev/null'"
vdnTest "root@bigboss -> titi@tiny ......... ?" "vdn-ssh root@bigboss 'timeout 2 ssh -o StrictHostKeyChecking=no titi@tiny :'"
}
testTp5() {
echo "[TP n°5]"
echo
local ipLambda=$(vdn-infos lambda PUBLIC_IP)
vdnTest "tiny -> ipLambda .................. ?" "vdn-ssh root@tiny 'unset http_proxy; timeout 2 lynx -dump $ipLambda'"
echo
vdnTest "serveur.rb ........................ ?" "vdn-ssh root@bigboss 'ls /usr/local/bin/server.rb &> /dev/null'"
vdnTest "client.rb ......................... ?" "vdn-ssh root@tiny 'ls /usr/local/bin/client.rb &> /dev/null'"
}
testSum() {
local last=-1 cpt=0 n
set +u
VDN_TESTS_DIR=/tmp/vdn-$USER/tests
if [ -z "$VDN_TESTS_DIR" ]; then
echo
echo "Not used !"
return
fi
set +u
last=-1
echo "[Synthèse]"
echo
while :; do
n=$(ls $VDN_TESTS_DIR | wc -l)
printf "."
if [ $n = $last ]; then
same=$(($same+1))
else
same=0
fi
if [ $same = 10 ]; then
break;
fi
last=$n
sleep 0.5
done
good=$(cat $VDN_TESTS_DIR/* | grep '^0$' | wc -l)
bad=$(($n-$good))
echo
echo
echo "tests:$n ok:$good ko:$bad réussite:$(( ($good*100) /$n ))%"
echo
}
run() {
requireSshGuests $SYSTEMS
#echo "Cette temporisation est pour vous décourager d'utiliser ce test comme debogueur !"
#for i in $(seq 10 -1 0); do echo $i; sleep 1; done
VDN_TESTS_DIR=/tmp/vdn-$USER/tests
[ ! -d $VDN_TESTS_DIR ] && mkdir -p $VDN_TESTS_DIR
rm -f /tmp/vdn-$USER/tests/*
vdnExec testTp1Part1 testTp1Part2 testTp2 testTp3 testTp4 testTp5 testSum
}