From: Holger Levsen Date: Thu, 7 Mar 2013 11:50:18 +0000 (+0100) Subject: split testdeploy script into two, seperate sending mails X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=464053dfe9f619e7dda8123660d45343799cfcf6;p=profitbricks%2Fjenkins-build-scripts.git split testdeploy script into two, seperate sending mails --- diff --git a/liveboot_approval_mail.sh b/liveboot_approval_mail.sh new file mode 100755 index 0000000..e052f14 --- /dev/null +++ b/liveboot_approval_mail.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# copyright 2012-2013 Holger Levsen +# GPL2 licenced + +set -e +#set -x +export +echo + +# +# check if we have a LIVEBOOT_BUILD_NUMBER +# +if [ "$LIVEBOOT_BUILD_NUMBER" != "" ] ; then + echo "Ok, got LIVEBOOT_BUILD_NUMBER=$LIVEBOOT_BUILD_NUMBER, which is valid." +else + echo "Fail, no LIVEBOOT_BUILD_NUMBER set." + exit 1 +fi + +# +# check if there is an image for it +# +if [ -d /srv/mirror/liveboot/liveboot-????????-${LIVEBOOT_BUILD_NUMBER}/ ] ; then + SOURCE_DIR=$(ls -d /srv/mirror/liveboot/liveboot-????????-${LIVEBOOT_BUILD_NUMBER}/) + echo "Ok, found directory $SOURCE_DIR" +else + figlet "Failure:" + echo "/srv/mirror/liveboot/liveboot-????????-${LIVEBOOT_BUILD_NUMBER}/ does not exist." + exit 1 +fi + +MAIL=$SOURCE_DIR/mail.txt +if [ ! -e $MAIL ] ; then + figlet "Warning:" + echo "$MAIL does not exist, something wrong with the liveboot web UI or was it simply not used at all?" + exit 1 +fi + +# +# output announcement mail headers +# +while read line ; do + if [ "$line" != "" ] ; then + echo $line + else + break + fi +done < $MAIL +echo +mailtextbody < $MAIL ; echo +echo "Attachments not shown here." +echo +# +# send announcement mail +# +cat $MAIL | /usr/sbin/sendmail -t +echo +echo "Ok, announcement mail sent." + +# +# finish +# +figlet Ok +echo +echo "Please continue testing of $(basename $SOURCE_DIR)." + diff --git a/liveboot_pserver1301_deploy.sh b/liveboot_pserver1301_deploy.sh new file mode 100755 index 0000000..23dce75 --- /dev/null +++ b/liveboot_pserver1301_deploy.sh @@ -0,0 +1,139 @@ +#!/bin/bash + +# copyright 2012-2013 Holger Levsen +# GPL2 licenced + +set -e +#set -x +export +echo + +TESTSERVER=pserver1301.ri.pb.local +TESTSERVER_MGMT_IP=192.168.178.49 +TESTSERVER_MGMT_PASSWD_FILE=/etc/jenkins/pserver1301.ipmi + +# +# check if we have a LIVEBOOT_BUILD_NUMBER +# +if [ "$LIVEBOOT_BUILD_NUMBER" != "" ] ; then + echo "Ok, got LIVEBOOT_BUILD_NUMBER=$LIVEBOOT_BUILD_NUMBER, which is valid." +else + echo "Fail, no LIVEBOOT_BUILD_NUMBER set." + exit 1 +fi + +# +# check if there is an image for it +# +if [ -d /srv/mirror/liveboot/liveboot-????????-${LIVEBOOT_BUILD_NUMBER}/ ] ; then + SOURCE_DIR=$(ls -d /srv/mirror/liveboot/liveboot-????????-${LIVEBOOT_BUILD_NUMBER}/) + echo "Ok, found directory $SOURCE_DIR" +else + figlet "Failure:" + echo "/srv/mirror/liveboot/liveboot-????????-${LIVEBOOT_BUILD_NUMBER}/ does not exist." + exit 1 +fi + +MAIL=$SOURCE_DIR/mail.txt +if [ ! -e $MAIL ] ; then + figlet "Warning:" + echo "$MAIL does not exist, something wrong with the liveboot web UI or was it simply not used at all?" + exit 1 +fi + +# +# create pending-approval link and rsync again +# +cd /srv/mirror/liveboot +rm -f pending-approval +ln -sfv $(basename $SOURCE_DIR) pending-approval +echo "pending-approval link created, pointing to $SOURCE_DIR" +$(dirname $0)/liveboot_rsync.sh + +# +# reboot TESTSERVER +# +echo "Scheduling hard-reset of $TESTSERVER via IPMI on $TESTSERVER_MGMT_IP" +cat $TESTSERVER_MGMT_PASSWD_FILE | ipmitool -H $TESTSERVER_MGMT_IP -U ADMIN -a chassis power reset + +# +# Test if it's gone +# +sleep 3 +if $(ping -c 1 $TESTSERVER >/dev/null) ; then + figlet "Warning:" + echo "$TESTSERVER responds to pings, even though it was reset 3secs ago, this should not happen, please investigate manually." + exit 1 +fi +echo + +# +# check for 10min whether it's booting up again +# +echo "Pinging $TESTSERVER..." +for i in $(seq 1 60) ; do + sleep 10 + echo -n "$(date +%H:%M:%S): " + if $(ping -c 1 $TESTSERVER >/dev/null) ; then + echo "ICMP echo reply from $TESTSERVER, so let's assume it's booting now." + break + fi + echo "no ICMP echo reply received." +done +if ! $(ping -c 1 $TESTSERVER >/dev/null) ; then + figlet "Failure:" + echo "$TESTSERVER still down, please investigate." + exit 1 +fi +echo + +# +# check for 15min whether ssh comes back +# +echo "Checking for sshd running on $TESTSERVER..." +for i in $(seq 1 90) ; do + sleep 10 + if $(ping -c 1 $TESTSERVER >/dev/null) ; then + echo -n "ping $TESTSERVER ok..." + # check ssh FIXME + if $(nc -z $TESTSERVER 22 ) ; then + echo "ok, sshd is running at $(date +%H:%M:%S)" + break + else + echo "but sshd is not running at $(date +%H:%M:%S)" + fi + fi +done +if ! $(nc -z $TESTSERVER 22 ) ; then + figlet "Failure:" + echo "$TESTSERVER still not running sshd, please investigate." + exit 1 +fi +echo + +# +# add jenkins user and sudoers.d/jenkins for it +# +TMPFILE=$(mktemp) +cat > $TMPFILE <<-EOF +addgroup --system jenkins +adduser --system --home /home/jenkins --shell /bin/bash --ingroup jenkins --disabled-password --gecos "Profitbricks jenkins user" jenkins +mkdir -p /home/jenkins/.ssh +echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDiQRvDBjX4+oSAhoKIWQ/QKLDp3Zg5eKif89wjWbE0uvxAeaAzcEcN/Kkxcf6D37KmpQnWS3OyIyy7+K6BKy51HEaemnMLLzcNIKWkhkZZnbbZDWZxURBl+cE7EZ0vlN6dXFCIWftU5UVSo11U3UKUPL3o4omZvAtgakOWBam8OLM2RArzqjLEC0KouCqRBXmbQPllIYKIC1r/nYPdMfDklLna+Y1fEiRYvrP7SwNZBBxZHvqTMXeCv+xGq4QLBbCFHR5RtU4f0IS5Lqx/mrGfYykDP1KDTcqA3fBWURUC1VMmjzd0ez3gvSnLZTLuF1f1VQcydveNZ5beCoDt8j3J jenkins@sagunt" > /home/jenkins/.ssh/authorized_keys +chmod 700 /home/jenkins/.ssh +chmod 700 /home/jenkins/.ssh/authorized_keys +chown jenkins.jenkins -R /home/jenkins +echo "jenkins ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/jenkins +chmod 440 /etc/sudoers.d/jenkins +chown root:root /etc/sudoers.d/jenkins +EOF +scp -t $TMPFILE root@$TESTSERVER:/tmp/ +ssh -t root@$TESTSERVER $TMPFILE +rm $TMPFILE +ssh -t jenkins@$TESTSERVER sudo id + +# +# finish +# +figlet Ok + diff --git a/liveboot_testdeploy.sh b/liveboot_testdeploy.sh deleted file mode 100755 index 8e695c0..0000000 --- a/liveboot_testdeploy.sh +++ /dev/null @@ -1,142 +0,0 @@ -#!/bin/bash - -# copyright 2012-2013 Holger Levsen -# GPL2 licenced - -set -e -#set -x -export -echo - -TESTSERVER=pserver1301.ri.pb.local -TESTSERVER_MGMT_IP=192.168.178.49 -TESTSERVER_MGMT_PASSWD_FILE=/etc/jenkins/pserver1301.ipmi - -# -# check if we have a LIVEBOOT_BUILD_NUMBER -# -if [ "$LIVEBOOT_BUILD_NUMBER" != "" ] ; then - echo "Ok, got LIVEBOOT_BUILD_NUMBER=$LIVEBOOT_BUILD_NUMBER, which is valid." -else - echo "Fail, no LIVEBOOT_BUILD_NUMBER set." - exit 1 -fi - -# -# check if there is an image for it -# -if [ -d /srv/mirror/liveboot/liveboot-????????-${LIVEBOOT_BUILD_NUMBER}/ ] ; then - SOURCE_DIR=$(ls -d /srv/mirror/liveboot/liveboot-????????-${LIVEBOOT_BUILD_NUMBER}/) - echo "Ok, found directory $SOURCE_DIR" -else - figlet "Failure:" - echo "/srv/mirror/liveboot/liveboot-????????-${LIVEBOOT_BUILD_NUMBER}/ does not exist." - exit 1 -fi - -MAIL=$SOURCE_DIR/mail.txt -if [ ! -e $MAIL ] ; then - figlet "Warning:" - echo "$MAIL does not exist, something wrong with the liveboot web UI or was it simply not used at all?" - exit 1 -fi - -# -# create pending-approval link and rsync again -# -cd /srv/mirror/liveboot -rm -f pending-approval -ln -sfv $(basename $SOURCE_DIR) pending-approval -echo "pending-approval link created, pointing to $SOURCE_DIR" -$(dirname $0)/liveboot_rsync.sh - -# -# reboot TESTSERVER -# -echo "Scheduling hard-reset of $TESTSERVER via IPMI on $TESTSERVER_MGMT_IP" -cat $TESTSERVER_MGMT_PASSWD_FILE | ipmitool -H $TESTSERVER_MGMT_IP -U ADMIN -a chassis power reset - -# -# Test if it's gone -# -sleep 3 -if $(ping -c 1 $TESTSERVER >/dev/null) ; then - figlet "Warning:" - echo "$TESTSERVER responds to pings, even though it was reset 3secs ago, this should not happen, please investigate manually." - exit 1 -fi -echo - -# -# check for 10min whether it's booting up again -# -echo "Pinging $TESTSERVER..." -for i in $(seq 1 60) ; do - sleep 10 - echo -n "$(date +%H:%M:%S): " - if $(ping -c 1 $TESTSERVER >/dev/null) ; then - echo "ICMP echo reply from $TESTSERVER, so let's assume it's booting now." - break - fi - echo "no ICMP echo reply received." -done -if ! $(ping -c 1 $TESTSERVER >/dev/null) ; then - figlet "Failure:" - echo "$TESTSERVER still down, please investigate." - exit 1 -fi -echo - -# -# check for 15min whether ssh comes back -# -echo "Checking for sshd running on $TESTSERVER..." -for i in $(seq 1 90) ; do - sleep 10 - if $(ping -c 1 $TESTSERVER >/dev/null) ; then - echo -n "ping $TESTSERVER ok..." - # check ssh FIXME - if $(nc -z $TESTSERVER 22 ) ; then - echo "ok, sshd is running at $(date +%H:%M:%S)" - break - else - echo "but sshd is not running at $(date +%H:%M:%S)" - fi - fi -done -if ! $(nc -z $TESTSERVER 22 ) ; then - figlet "Failure:" - echo "$TESTSERVER still not running sshd, please investigate." - exit 1 -fi -echo - - -# -# output announcement mail headers -# -while read line ; do - if [ "$line" != "" ] ; then - echo $line - else - break - fi -done < $MAIL -echo -mailtextbody < $MAIL ; echo -echo "Attachments not shown here." -echo -# -# send announcement mail -# -cat $MAIL | /usr/sbin/sendmail -t -echo -echo "Ok, announcement mail sent." - -# -# finish -# -figlet Ok -echo -echo "Please continue manual testing of $(basename $SOURCE_DIR)." -