Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Commit

Permalink
chore(travis): use docker to run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienElet committed Feb 23, 2017
1 parent 4f1732f commit bb54cc1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 34 deletions.
41 changes: 8 additions & 33 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,16 @@
---
language: python
python: "2.7"
services:
- docker

sudo: true
env:
matrix:
- DOCKER_IMAGE=sebastienelet/docker-ubuntu1404-ansible DOCKER_INIT=/sbin/init

# Install ansible
addons:
apt:
packages:
- python-pip

install:
# Install ansible
- pip install ansible

# Check ansible version
- ansible --version

# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg

# Install dependencies
- ansible-galaxy install SimpliField.transparent-huge-pages
before_install:
- make docker-pull

script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
# Run the role/playbook with ansible-playbook.
- ansible-playbook -i tests/inventory tests/test.yml --connection=local --sudo
# Run the role/playbook again, checking to make sure it's idempotent.
- >
ansible-playbook -i tests/inventory tests/test.yml --connection=local --sudo
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Test if /usr/local/bin/mongobackup.sh is present
- ls -lah /usr/bin/mongod
- make test

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
DOCKER_IMAGE?="sebastienelet/docker-debian8-ansible"
DOCKER_INIT?=/lib/systemd/systemd
docker-container-id:=$(shell mktemp)
idempotence:=$(shell mktemp)

test: docker-run docker-test docker-stop

docker-pull:
docker pull $(DOCKER_IMAGE)

docker-run: docker-pull
docker run --detach \
--volume="${PWD}":/etc/ansible/roles/role_under_test:ro \
--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro \
$(DOCKER_IMAGE) \
$(DOCKER_INIT) > $(docker-container-id)

docker-stop:
docker stop $(shell cat ${docker-container-id})

docker-test: docker-requirements docker-test-syntax docker-test-role docker-test-role-idempotence

docker-requirements:
docker exec "$(shell cat ${docker-container-id})" ansible-galaxy install SimpliField.transparent-huge-pages
docker-test-syntax:
docker exec --tty "$(shell cat ${docker-container-id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check
docker-test-role:
docker exec "$(shell cat ${docker-container-id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml -e "$(ROLE_OPTIONS)"
docker-test-role-idempotence:
docker exec "$(shell cat ${docker-container-id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml -e "$(ROLE_OPTIONS)" | tee -a $(idempotence)
tail $(idempotence) \
| grep -q 'changed=0.*failed=0' \
&& (echo 'Idempotence test: pass' && exit 0) \
|| (echo 'Idempotence test: fail' && exit 1)
2 changes: 1 addition & 1 deletion tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
- hosts: localhost
remote_user: root
roles:
- ansible-mongo
- role_under_test

0 comments on commit bb54cc1

Please sign in to comment.