Bug 1148966 - Use container based travis CI to improve test wait times. r=Callek
authorRail Aliiev <rail@mozilla.com>
Mon, 30 Mar 2015 09:30:27 -0400
changeset 11858 df468d1dc88d4f0612be16b6894deaa5294e29d4
parent 11857 05c0f42e3e6770655fb9ec7b4c5bd79fdad64042
child 11859 9678c4380ac4dffa47b284a684286bed72a1b907
push id3
push userahalberstadt@mozilla.com
push dateWed, 29 Apr 2015 14:58:39 +0000
reviewersCallek
bugs1148966
Bug 1148966 - Use container based travis CI to improve test wait times. r=Callek
.travis.yml
test-masters.sh
tox.ini
tox_env.sh
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,21 +1,36 @@
 language: python
 python:
   - "2.7"
 
+sudo: false
+
+env:
+  global:
+    - PIP_FIND_LINKS=file://$HOME/.cache/pip
+    - PIP_CACHE_DIR=$HOME/.cache/pip
+  matrix:
+    - TOX_ENV=flake8 IGNORE_FAILURES=true
+    - TOX_ENV=py27
+    - TOX_ENV=py27-unittests
+
+cache:
+  directories:
+    - $HOME/.cache/pip
+    - $TRAVIS_BUILD_DIR/.tox
+
 install:
   - pip install tox
 
 script:
-  - tox
+  - if [[ $IGNORE_FAILURES == true ]]; then tox -e $TOX_ENV || true; else tox -e $TOX_ENV; fi
+  # Remove logs to avoid cache uploads
+  - rm -rf $HOME/.cache/pip/log
 
-after_script:
-  # only in after_script can it run without failing the job
-  - tox -e pep8
 
 # currently cannot customise per user fork, see:
 # https://github.com/travis-ci/travis-ci/issues/1094
 # please comment out this section in your personal fork!
 notifications:
   irc:
     channels:
       - "irc.mozilla.org#releng"
--- a/test-masters.sh
+++ b/test-masters.sh
@@ -1,103 +1,97 @@
 #!/bin/bash
 # This script has been rewritten in setup_master.py using
 # the -t option.  We use that now
-exit=0
-
-# even though it isn't fully used, the config check does require a valid
+# Even though it isn't fully used, the config check does require a valid
 # shared memory setup AT THE DEFAULT LOCATION. If you're running on a
 # laptop, that may not exist. Fail early.
 #
 # OSX note: it "works" (for test-masters purposes) to just create the
 #           directory, even though that isn't how shared memory is
 #           handled on OSX. The directories must be owned by the id
 #           running the tests.
 #
 # if you want to run trial tests without needing to execute the full test suite
 # call this script with: run-test
 
+function run_unittests {
+  exit_code=0
+  for dir in mozilla mozilla-tests; do
+    cd $dir
+    for f in test/*.py; do
+      trial $f || exit_code=1
+    done
+    rm -rf _trial_temp
+    cd ..
+  done
+  if [ $exit_code != 0 ]; then
+    exit 1
+  fi
+}
+
+if [ "$1" == "--unittests-only" ]; then
+    # run trial and exit
+    run_unittests
+    exit
+fi
+
 shm=(/dev/shm)
 good_shm=true
 for needed_dir in ${shm[@]}; do
     if ! test -w $needed_dir; then
         echo 1>&2 "No shm setup, please create writable directory '$needed_dir'"
         good_shm=false
     fi
 done
 $good_shm || exit 1
 
 WORK=test-output
 mkdir $WORK 2>/dev/null
 
 
-function run_unittests {
-for dir in mozilla mozilla-tests; do
-  cd $dir
-  for f in test/*.py; do
-    trial $f || exit=1
-  done
-  rm -rf _trial_temp
-  cd ..
-done
-}
-
-if [ "$1" == "run-tests" ]
-then
-    # run trial and exit
-    run_unittests
-    exit
-fi
-
 actioning="Checking"
 MASTERS_JSON_URL="${MASTERS_JSON_URL:-https://hg.mozilla.org/build/tools/raw-file/tip/buildfarm/maintenance/production-masters.json}"
 
 atexit=()
 trap 'for cmd in "${atexit[@]}"; do eval $cmd; done' EXIT
 
 # I have had problems where a whole bunch of parallel HTTP requests caused
 # errors (?), so fetch it once here and pass it in.
 MASTERS_JSON=$(mktemp $WORK/tmp.masters.XXXXXXXXXX)
 curl -q -o$MASTERS_JSON "$MASTERS_JSON_URL" || exit 1
 atexit+=("rm $MASTERS_JSON")
 
 FAILFILE=$(mktemp $WORK/tmp.failfile.XXXXXXXXXX)
 atexit+=("rm $FAILFILE")
 
 # Construct the set of masters that we will test.
-MASTERS=($(./setup-master.py -l -j "$MASTERS_JSON" --tested-only "$@"))
+MASTERS=($(./setup-master.py -l -j "$MASTERS_JSON" --tested-only --error-logs))
 
 # Fire off all the tests in parallel.
 for MASTER in ${MASTERS[*]}; do (
     OUTFILE=$(mktemp $WORK/tmp.testout.XXXXXXXXXX)
 
-    ./setup-master.py -t -j "$MASTERS_JSON" "$@" $MASTER > $OUTFILE 2>&1 || echo "$MASTER" >> $FAILFILE
+    ./setup-master.py -t -j "$MASTERS_JSON" --error-logs $MASTER > $OUTFILE 2>&1 || echo "$MASTER" >> $FAILFILE
     cat $OUTFILE # Make the output a little less interleaved
-    rm $OUTFILE
+    rm -f $OUTFILE
 ) &
 atexit+=("[ -e /proc/$! ] && kill $!")
 done
 
 echo "$actioning ${#MASTERS[*]} masters..."
 echo "${MASTERS[*]}"
 wait
 
-check_for_virtual_env() {
-    if test -z "$VIRTUAL_ENV"; then
-        echo "NOTE: you were not using a virtual environment" 1>&2
-    fi
-}
-
 if [ -s $FAILFILE ]; then
     echo "*** $(wc -l < $FAILFILE) master tests failed ***" >&2
     echo "Failed masters:" >&2
     sed -e 's/^/  /' "$FAILFILE" >&2
-    check_for_virtual_env
+    if test -z "$VIRTUAL_ENV"; then
+        echo "NOTE: you were not using a virtual environment" 1>&2
+    fi
     exit 1
 fi
 
-run_unittests
-
-if test "$exit" -ne 0 ; then
-    check_for_virtual_env
+# Allow skipping (Travis)
+if [ "$1" != "--no-unittests" ]; then
+    run_unittests
 fi
-
-exit $exit
--- a/tox.ini
+++ b/tox.ini
@@ -1,45 +1,52 @@
 [tox]
-envlist = py27
+envlist = py27,py27-unittests
 skipsdist=True
 
 [testenv]
 basepython = python2.7
 
 setenv =
     PYTHONPATH = {toxworkdir}:{toxworkdir}/tools/lib/python
 
 deps =
     Jinja2==2.5.5
+    MozillaPulse==0.80
     MySQL-python==1.2.3
     SQLAlchemy==0.6.4
     Twisted==10.1.0
     amqplib==0.6.1
     anyjson==0.3
     argparse==1.1
     carrot==0.10.7
     distribute==0.6.14
     mozci==0.4.1
     pyOpenSSL==0.14
     pyasn1==0.0.11a
     pycrypto==2.3
     pytest==2.7.0
     pytz==2011d
     wsgiref==0.1.2
     zope.interface==3.6.1
-    MozillaPulse==0.80
 
 commands =
     ./tox_env.sh "{toxinidir}" "{toxworkdir}"
-    ./test-masters.sh -e
+    ./test-masters.sh --no-unittests
     py.test test
 
 
-[testenv:pep8]
-# Don't fail on pep8 yet
-# Would love to enable failing this by default - See:
-# https://bitbucket.org/hpk42/tox/issue/124/ignore-command-exit-codes
+[testenv:flake8]
+deps=
+    flake8
+commands=
+    flake8
+
+[testenv:py27-unittests]
 deps=
-    pep8
-    {[testenv]deps}
+    Twisted==10.1.0
 commands=
-    pep8 --max-line-length=159 --exclude=.svn,CVS,.bzr,.hg,.git,__pycache__,seamonkey,calendar,.tox
+    ./test-masters.sh --unittests-only
+
+[flake8]
+exclude = .ropeproject,.tox
+show-source = True
+max-line-length=159
--- a/tox_env.sh
+++ b/tox_env.sh
@@ -4,17 +4,17 @@ TOX_INI_DIR="${1}"
 TOX_WORK_DIR="${2}"
 
 function hgme {
     repo="${1}"
     if [ ! -d "${TOX_WORK_DIR}/${repo}" ]; then
         hg clone https://hg.mozilla.org/build/${repo} "${TOX_WORK_DIR}/${repo}"
     else
         # this is equivalent to hg purge but doesn't require the hg purge plugin to be enabled
-        hg status -un0 -R "${TOX_WORK_DIR}/${repo}" | xargs rm -rf
+        hg status -un0 -R "${TOX_DIR}/${repo}" | xargs --no-run-if-empty --null rm -rf
         hg pull -u -R "${TOX_WORK_DIR}/${repo}"
     fi
 }
 
 hgme tools
 hgme buildbotcustom
 hgme buildbot
 hgme braindump