github.com/rvaralda/deis@v1.4.1/tests/bin/test-setup.sh (about) 1 #!/bin/bash 2 # 3 # Prepares the process environment to run a test 4 5 function log_phase { 6 echo 7 echo ">>> $1 <<<" 8 echo 9 } 10 11 log_phase "Preparing test environment" 12 13 # use GOPATH to determine project root 14 export DEIS_ROOT=${GOPATH?}/src/github.com/deis/deis 15 echo "DEIS_ROOT=$DEIS_ROOT" 16 17 # prepend GOPATH/bin to PATH 18 export PATH=${GOPATH}/bin:$PATH 19 20 # the application under test 21 export DEIS_TEST_APP=${DEIS_TEST_APP:-example-dockerfile-http} 22 echo "DEIS_TEST_APP=$DEIS_TEST_APP" 23 24 # SSH key name used for testing 25 export DEIS_TEST_AUTH_KEY=${DEIS_TEST_AUTH_KEY:-deis-test} 26 echo "DEIS_TEST_AUTH_KEY=$DEIS_TEST_AUTH_KEY" 27 28 # SSH key used for deisctl tunneling 29 export DEIS_TEST_SSH_KEY=${DEIS_TEST_SSH_KEY:-~/.vagrant.d/insecure_private_key} 30 echo "DEIS_TEST_SSH_KEY=$DEIS_TEST_SSH_KEY" 31 32 # domain used for wildcard DNS 33 export DEIS_TEST_DOMAIN=${DEIS_TEST_DOMAIN:-local3.deisapp.com} 34 echo "DEIS_TEST_DOMAIN=$DEIS_TEST_DOMAIN" 35 36 # SSH tunnel used by deisctl 37 export DEISCTL_TUNNEL=${DEISCTL_TUNNEL:-127.0.0.1:2222} 38 echo "DEISCTL_TUNNEL=$DEISCTL_TUNNEL" 39 40 # set units used by deisctl 41 export DEISCTL_UNITS=${DEISCTL_UNITS:-$DEIS_ROOT/deisctl/units} 42 echo "DEISCTL_UNITS=$DEISCTL_UNITS" 43 44 # ip address for docker containers to communicate in functional tests 45 export HOST_IPADDR=${HOST_IPADDR?} 46 echo "HOST_IPADDR=$HOST_IPADDR" 47 48 # the registry used to host dev-release images 49 # must be accessible to local Docker engine and Deis cluster 50 export DEV_REGISTRY=${DEV_REGISTRY?} 51 echo "DEV_REGISTRY=$DEV_REGISTRY" 52 53 # bail if registry is not accessible 54 if ! curl -s $DEV_REGISTRY; then 55 echo "DEV_REGISTRY is not accessible, exiting..." 56 exit 1 57 fi 58 echo ; echo 59 60 # disable git+ssh host key checking 61 export GIT_SSH=$DEIS_ROOT/tests/bin/git-ssh-nokeycheck.sh 62 63 # install required go dependencies 64 go get -v github.com/golang/lint/golint 65 go get -v github.com/tools/godep 66 67 # cleanup any stale example applications 68 rm -rf $DEIS_ROOT/tests/example-* 69 70 # generate ssh key if it doesn't already exist 71 test -e ~/.ssh/$DEIS_TEST_AUTH_KEY || ssh-keygen -t rsa -f ~/.ssh/$DEIS_TEST_AUTH_KEY -N '' 72 73 # prepare the SSH agent 74 ssh-add -D || eval $(ssh-agent) && ssh-add -D 75 ssh-add ~/.ssh/$DEIS_TEST_AUTH_KEY 76 ssh-add $DEIS_TEST_SSH_KEY 77 78 # clean out deis session data 79 rm -rf ~/.deis 80 81 # clean out vagrant environment 82 $THIS_DIR/halt-all-vagrants.sh 83 vagrant destroy --force 84 85 # wipe out all vagrants & deis virtualboxen 86 function cleanup { 87 log_phase "Cleaning up" 88 set +e 89 ${GOPATH}/src/github.com/deis/deis/tests/bin/destroy-all-vagrants.sh 90 VBoxManage list vms | grep deis | sed -n -e 's/^.* {\(.*\)}/\1/p' | xargs -L1 -I {} VBoxManage unregistervm {} --delete 91 vagrant global-status --prune 92 docker rm -f -v `docker ps | grep deis- | awk '{print $1}'` 2>/dev/null 93 log_phase "Test run complete" 94 } 95 96 function dump_logs { 97 log_phase "Error detected, dumping logs" 98 TIMESTAMP=`date +%Y-%m-%d-%H%M%S` 99 FAILED_LOGS_DIR=$HOME/deis-test-failure-$TIMESTAMP 100 mkdir -p $FAILED_LOGS_DIR 101 set +e 102 export FLEETCTL_TUNNEL=$DEISCTL_TUNNEL 103 fleetctl -strict-host-key-checking=false list-units 104 # application unit logs 105 get_logs appssample_v2.web.1 106 get_logs appssample_v2.run.1 107 get_logs buildsample_v2.web.1 108 get_logs buildsample_v3.cmd.1 109 get_logs deispullsample_v2.cmd.1 110 get_logs deispullsample_v2.worker.1 111 get_logs pssample_v2.worker.1 112 get_logs pssample_v2.worker.2 113 # etcd keyspace 114 get_logs deis-controller "etcdctl ls / --recursive" etcdctl-dump 115 # component logs 116 get_logs deis-builder 117 get_logs deis-controller 118 get_logs deis-database 119 get_logs deis-logger 120 get_logs deis-registry 121 get_logs deis-router@1 deis-router deis-router-1 122 get_logs deis-router@2 deis-router deis-router-2 123 get_logs deis-router@3 deis-router deis-router-3 124 # deis-store logs 125 get_logs deis-router@1 deis-store-monitor deis-store-monitor-1 126 get_logs deis-router@1 deis-store-daemon deis-store-daemon-1 127 get_logs deis-router@1 deis-store-metadata deis-store-metadata-1 128 get_logs deis-router@1 deis-store-volume deis-store-volume-1 129 get_logs deis-router@2 deis-store-monitor deis-store-monitor-2 130 get_logs deis-router@2 deis-store-daemon deis-store-daemon-2 131 get_logs deis-router@2 deis-store-metadata deis-store-metadata-2 132 get_logs deis-router@2 deis-store-volume deis-store-volume-2 133 get_logs deis-router@3 deis-store-monitor deis-store-monitor-3 134 get_logs deis-router@3 deis-store-daemon deis-store-daemon-3 135 get_logs deis-router@3 deis-store-metadata deis-store-metadata-3 136 get_logs deis-router@3 deis-store-volume deis-store-volume-3 137 get_logs deis-store-gateway 138 139 # tarball logs 140 BUCKET=jenkins-failure-logs 141 FILENAME=deis-test-failure-$TIMESTAMP.tar.gz 142 cd $FAILED_LOGS_DIR && tar -czf $FILENAME *.log && mv $FILENAME .. && cd .. 143 rm -rf $FAILED_LOGS_DIR 144 if [ `which s3cmd` ] && [ -f $HOME/.s3cfg ]; then 145 echo "configured s3cmd found in path. Attempting to upload logs to S3" 146 s3cmd put $HOME/$FILENAME s3://$BUCKET 147 rm $HOME/$FILENAME 148 echo "Logs are accessible at https://s3.amazonaws.com/$BUCKET/$FILENAME" 149 else 150 echo "Logs are accessible at $HOME/$FILENAME" 151 fi 152 exit 1 153 } 154 155 function get_logs { 156 TARGET="$1" 157 CONTAINER="$2" 158 FILENAME="$3" 159 if [ -z "$CONTAINER" ]; then 160 CONTAINER=$TARGET 161 fi 162 if [ -z "$FILENAME" ]; then 163 FILENAME=$TARGET 164 fi 165 fleetctl -strict-host-key-checking=false ssh "$TARGET" docker logs "$CONTAINER" > $FAILED_LOGS_DIR/$FILENAME.log 166 }