sudo: true dist: trusty language: python addons: apt: packages: - expect-dev # for unbuffer env: global: - ETCDVERSION=3.0.17 ZKVERSION=3.4.11 CONSULVERSION=0.7.4 - PYVERSIONS="2.7 3.5 3.6" - EXCLUDE_BEHAVE="3.5" - BOTO_CONFIG=/doesnotexist matrix: include: - python: "3.5" env: TEST_SUITE="python setup.py" - python: "3.6" env: DCS="etcd" TEST_SUITE="behave" - python: "3.6" env: DCS="exhibitor" TEST_SUITE="behave" - python: "3.6" env: DCS="consul" TEST_SUITE="behave" - python: "3.6" env: DCS="kubernetes" TEST_SUITE="behave" branches: only: - master - /^v\d+\.\d+(\.\d+)?$/ cache: directories: - $HOME/mycache before_cache: - | rm -fr $HOME/mycache/python* for pv in $PYVERSIONS; do if [[ $TEST_SUITE != "behave" || $pv != $EXCLUDE_BEHAVE ]]; then fpv=$(basename $(readlink $HOME/virtualenv/python${pv})) mv $HOME/virtualenv/${fpv} $HOME/mycache/${fpv} fi done install: - | set -e if [[ $TEST_SUITE == "behave" ]]; then function get_consul() { CC=~/mycache/consul_${CONSULVERSION} if [[ ! -x $CC ]]; then curl -L https://releases.hashicorp.com/consul/${CONSULVERSION}/consul_${CONSULVERSION}_linux_amd64.zip \ | gunzip > $CC [[ ${PIPESTATUS[0]} == 0 ]] || return 1 chmod +x $CC fi ln -s $CC consul } function get_etcd() { EC=~/mycache/etcd_${ETCDVERSION} if [[ ! -x $EC ]]; then curl -L https://github.com/coreos/etcd/releases/download/v${ETCDVERSION}/etcd-v${ETCDVERSION}-linux-amd64.tar.gz \ | tar xz -C . --strip=1 --wildcards --no-anchored etcd [[ ${PIPESTATUS[0]} == 0 ]] || return 1 mv etcd $EC fi ln -s $EC etcd } function get_kubernetes() { wget -O localkube "https://storage.googleapis.com/minikube/k8sReleases/v1.7.0/localkube-linux-amd64" chmod +x localkube sudo nohup ./localkube --logtostderr=true --enable-dns=false > localkube.log 2>&1 & echo "Waiting for localkube to start..." if ! timeout 120 sh -c "while ! curl -ks http://127.0.0.1:8080/ >/dev/null; do sleep 1; done"; then sudo cat localkube.log echo "localkube did not start" exit 1 fi echo "Check certificate permissions" sudo chmod 644 /var/lib/localkube/certs/* sudo ls -altr /var/lib/localkube/certs/ echo "Set up .kube/config" mkdir ~/.kube echo -e "apiVersion: v1\nclusters:\n- cluster:\n certificate-authority: /var/lib/localkube/certs/ca.crt\n server: https://127.0.0.1:8443\n name: local\ncontexts:\n- context:\n cluster: local\n user: myself\n name: local\ncurrent-context: local\nkind: Config\npreferences: {}\nusers:\n- name: myself\n user:\n client-certificate: /var/lib/localkube/certs/apiserver.crt\n client-key: /var/lib/localkube/certs/apiserver.key\n" > ~/.kube/config } function get_exhibitor() { ZC=~/mycache/zookeeper-${ZKVERSION} if [[ ! -d $ZC ]]; then curl -L http://www.apache.org/dist/zookeeper/zookeeper-${ZKVERSION}/zookeeper-${ZKVERSION}.tar.gz | tar xz [[ ${PIPESTATUS[0]} == 0 ]] || return 1 mv zookeeper-${ZKVERSION}/conf/zoo_sample.cfg zookeeper-${ZKVERSION}/conf/zoo.cfg mv zookeeper-${ZKVERSION} $ZC fi $ZC/bin/zkServer.sh start # following lines are 'emulating' exhibitor REST API while true; do echo -e 'HTTP/1.0 200 OK\nContent-Type: application/json\n\n{"servers":["127.0.0.1"],"port":2181}' \ | nc -l 8181 &> /dev/null done& } attempt_num=1 until get_${DCS}; do [[ $attempt_num -ge 3 ]] && exit 1 echo "Attempt $attempt_num failed! Trying again in $attempt_num seconds..." sleep $(( attempt_num++ )) done fi for pv in $PYVERSIONS; do if [[ $TEST_SUITE != "behave" || $pv != $EXCLUDE_BEHAVE ]]; then fpv=$(basename $(readlink $HOME/virtualenv/python$pv)) if [[ -d ~/mycache/${fpv} ]]; then mv ~/virtualenv/${fpv} ~/virtualenv/${fpv}.bckp mv ~/mycache/${fpv} ~/virtualenv/${fpv} fi source ~/virtualenv/python${pv}/bin/activate # explicitly install all needed python modules to cache them for p in '-r requirements.txt' 'psycopg2-binary behave codacy-coverage coverage coveralls flake8 mock pytest-cov pytest setuptools'; do pip install $p --upgrade done fi done script: - | for pv in $PYVERSIONS; do if [[ $TEST_SUITE == "behave" && $pv == $EXCLUDE_BEHAVE ]]; then continue fi source ~/virtualenv/python${pv}/bin/activate if [[ $TEST_SUITE != "behave" ]]; then echo Running unit tests using python${pv} unbuffer $TEST_SUITE test $TEST_SUITE flake8 elif [[ $pv != $EXCLUDE_BEHAVE ]]; then echo Running acceptance tests using python${pv} if ! PATH=.:/usr/lib/postgresql/9.6/bin:$PATH unbuffer $TEST_SUITE; then # output all log files when tests are failing grep . features/output/*_failed/*postgres?.* exit 1 fi fi done set +e after_success: # before_cache is executed earlier than after_success, so we need to restore one of virtualenv directories - fpv=$(basename $(readlink $HOME/virtualenv/python3.6)) && mv $HOME/mycache/${fpv} $HOME/virtualenv/${fpv} - coveralls - if [[ $TEST_SUITE != "behave" ]]; then python-codacy-coverage -r coverage.xml; fi - if [[ $DCS == "exhibitor" ]]; then ~/mycache/zookeeper-${ZKVERSION}/bin/zkServer.sh stop; fi - sudo kill $(jobs -p)