github.com/scaleway/scaleway-cli@v1.11.1/examples/kernel-quick-checks.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # I'm a script used to check the stability of new kernels.
     4  #
     5  # I spawn 16 servers, boot them, and perform several checks such as a
     6  # local iperf, some IOs (parallel download of 5GO on a NBD mounted
     7  # disk).
     8  #
     9  # I generate a Markdown report with results
    10  
    11  # parameters
    12  if [ $# -ne 1 ]; then
    13      echo "usage: $0 build-id"
    14      exit 1
    15  fi
    16  
    17  # globals
    18  BUILD_ID=$1
    19  WORKDIR=$(mktemp -d -t minibench)
    20  NB_INSTANCES=16
    21  INSTANCE_NAME='minibench-kernel'
    22  
    23  # we expect the following in the environment
    24  #
    25  # - JENKINS_MIRROR
    26  # - SANDBOX_DTB_UUID
    27  if [ -f env.bash ]
    28  then
    29      source env.bash
    30  fi
    31  
    32  # fetch kernel and publish to S3
    33  function prepare {
    34      echo >&2 '[+] preparing kernel...'
    35      local kernel=$(wget "${JENKINS_MIRROR}/" -O /dev/stdout 2>/dev/null | sed -e 's/<a href="\([^"]*\)\/">.*/\1/' -e 'tx' -e 'd' -e ':x' | grep "^.*\-${BUILD_ID}$\|^.*\-${BUILD_ID}\-.*$")
    36      if [ -z "$kernel" ]; then
    37  	echo "can't find $BUILD_ID on jenkins"
    38  	exit 1
    39      fi
    40  
    41      wget "${JENKINS_MIRROR}/${kernel}/uImage" -O /tmp/uImage 2>/dev/null
    42      wget "${JENKINS_MIRROR}/${kernel}/dtbs/pimouss-computing.dtb" -O /tmp/dtb 2>/dev/null
    43  
    44      s3cmd put --acl-public /tmp/uImage s3://mxs/uImage-$kernel &>/dev/null
    45      s3cmd put --acl-public /tmp/dtb s3://mxs/dtb-$kernel &>/dev/null
    46  
    47      s3cmd put --acl-public /tmp/uImage s3://mxs/uImage-sandbox &>/dev/null
    48      s3cmd put --acl-public /tmp/dtb s3://mxs/dtb-sandbox &>/dev/null
    49  
    50      rm -f /tmp/uImage /tmp/dtb
    51  }
    52  
    53  # destroy all existing servers matching name
    54  function cleanup {
    55      echo >&2 '[+] cleaning up existing servers...'
    56      for uuid in $(scw ps -a --no-trunc | tail -n +2 | awk '// { print $1, $NF; }' | grep "^.* ${INSTANCE_NAME}\-" | awk '// { print $1; }'); do
    57  	scw stop -t $uuid
    58      done
    59  
    60      touch $WORKDIR/uuids.txt
    61      touch $WORKDIR/ips.txt
    62  }
    63  
    64  # create $NB_INSTANCES servers with a bootscript pointing to the prepared kernel
    65  function boot {
    66      echo >&2 "[+] creating $NB_INSTANCES servers..."
    67      for i in $(eval echo {1..$NB_INSTANCES}); do
    68  	scw create --bootscript $SANDBOX_DTB_UUID --volume 50G --name "$INSTANCE_NAME-$i" Ubuntu_Trusty_14_04_LTS >> $WORKDIR/uuids.txt
    69      done
    70      cat $WORKDIR/uuids.txt
    71  
    72      echo >&2 "[+] booting $NB_INSTANCES servers..."
    73      for uuid in $(cat $WORKDIR/uuids.txt); do
    74  	scw start -s $uuid &
    75  	sleep .5
    76      done
    77      wait `jobs -p`
    78  
    79      echo >&2 "[+] fetching IPs..."
    80      for uuid in $(cat $WORKDIR/uuids.txt); do
    81  	scw inspect $uuid | grep address | awk '// { print $2; }' | tr -d '"' | awk '// { print $1; }' >> $WORKDIR/ips.txt
    82      done
    83  }
    84  
    85  # run several tests and output a Markdown report
    86  function report {
    87      # status
    88      echo >&2 "[+] report status"
    89      echo "## Status of instances"
    90      echo ""
    91      NB_INSTANCES_OK=$(wc -l $WORKDIR/ips.txt | awk '// { print $1; }')
    92      echo "- $NB_INSTANCES_OK / $NB_INSTANCES have correctly booted"
    93      echo ""
    94  
    95      # fping
    96      echo >&2 "[+] report fping"
    97      echo "## fping"
    98      echo ""
    99      fping $(cat $WORKDIR/ips.txt) | sed 's/\(.*\)/    \1/'
   100      echo ""
   101  
   102      # uname -a
   103      echo >&2 "[+] report uname"
   104      echo "## uname"
   105      echo ""
   106      for uuid in $(cat $WORKDIR/uuids.txt); do
   107  	scw exec $uuid 'uname -a' | sed 's/\(.*\)/    \1/'
   108      done
   109      echo ""
   110  
   111      # iperf
   112      echo >&2 "[+] report iperf"
   113      echo "## iperf"
   114      echo ""
   115      for uuid in $(cat $WORKDIR/uuids.txt); do
   116  	scw exec $uuid 'iperf -s & sleep 5 ; iperf -c localhost' | sed 's/\(.*\)/    \1/'
   117      done
   118      echo ""
   119  
   120      # quick stability check
   121      echo >&2 "[+] report stability 1st pass"
   122      echo "## stability"
   123      echo ""
   124      for uuid in $(cat $WORKDIR/uuids.txt); do
   125  	scw exec $uuid 'find /usr -type f | xargs md5sum &> /tmp/a'
   126  	scw exec $uuid 'find /usr -type f | xargs cat &> /tmp/megafile'
   127  	scw exec $uuid 'for i in {1..5}; do wget --no-verbose --page-requisites http://ping.online.net/1000Mo.dat -O $i 2>/dev/null & done; wait $(jobs -p)' | sed 's/\(.*\)/    \1/'
   128      done
   129  
   130      echo >&2 "[+] report stability 2nd pass"
   131      for uuid in $(cat $WORKDIR/uuids.txt); do
   132  	scw exec $uuid 'find /usr -type f | xargs md5sum &> /tmp/b'
   133      done
   134  
   135      echo >&2 "[+] report stability 3rd pass"
   136      for uuid in $(cat $WORKDIR/uuids.txt); do
   137  	scw exec $uuid 'diff /tmp/a /tmp/b' | sed 's/\(.*\)/    \1/'
   138      done
   139  
   140      echo >&2 "[+] report stability fping"
   141      echo ""
   142      fping $(cat $WORKDIR/ips.txt) | sed 's/\(.*\)/    \1/'
   143      echo ""
   144  }
   145  
   146  function main {
   147      prepare
   148      cleanup
   149      boot
   150      report > report-${BUILD_ID}.md
   151      echo >&2 "[+] report is at report-${BUILD_ID}.md"
   152      cleanup
   153  }
   154  
   155  main
   156  rm -rf $WORKDIR