This repository has been archived by the owner on Nov 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(travis): use docker to run tests
- Loading branch information
1 parent
4f1732f
commit bb54cc1
Showing
3 changed files
with
43 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
- hosts: localhost | ||
remote_user: root | ||
roles: | ||
- ansible-mongo | ||
- role_under_test |