Skip to content

Commit

Permalink
add tests in molecule and travis
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfantom committed Jan 15, 2018
1 parent 7408416 commit 14e89e8
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
.vagrant
*.retry
.molecule
**__pycache__**
45 changes: 15 additions & 30 deletions .travis.yml
@@ -1,35 +1,20 @@
---
sudo: required
language: python
python: "2.7"

sudo: true

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

cache: pip
services:
- docker
env:
- ANSIBLE=2.2.3
- ANSIBLE=2.3.2
- ANSIBLE=2.4.2
install:
# Install ansible
- pip install ansible

# Check ansible version
- ansible --version

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

- pip install ansible==${ANSIBLE} ansible-lint>=3.4.15 molecule==1.25.0 docker git-semver testinfra>=1.7.0
before_script:
- ansible-lint tests/playbook.yml
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
- ansible-playbook tests/test.yml -i tests/inventory --connection=local
- ansible-playbook tests/test.yml -i tests/inventory --connection=local
- >
ansible-playbook tests/test.yml -i tests/inventory --connection=local
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
- molecule test
branches:
only:
- master
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
7 changes: 7 additions & 0 deletions .travis/images.sh
@@ -0,0 +1,7 @@
#!/bin/bash
for i in ubuntu-molecule:16.04 debian-molecule:9 debian-molecule:8 centos-molecule:7 fedora-molecule:27
do
docker pull paulfantom/$i &
done

wait
43 changes: 43 additions & 0 deletions molecule.yml
@@ -0,0 +1,43 @@
---
ansible:
playbook: tests/playbook.yml
driver:
name: docker
verifier:
name: testinfra
dependency:
name: shell
command: ./.travis/images.sh
docker:
build_image: False
containers:
- name: xenial
image: paulfantom/ubuntu-molecule
image_version: 16.04
privileged: true
volume_mounts:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: stretch
image: paulfantom/debian-molecule
image_version: 9
privileged: true
volume_mounts:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: jessie
image: paulfantom/debian-molecule
image_version: 8
privileged: true
volume_mounts:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: centos7
image: paulfantom/centos-molecule
image_version: 7
privileged: true
volume_mounts:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: fedora
image: paulfantom/fedora-molecule
image_version: 27
privileged: true
volume_mounts:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
File renamed without changes.
37 changes: 37 additions & 0 deletions tests/test_default.py
@@ -0,0 +1,37 @@
from testinfra.utils.ansible_runner import AnsibleRunner

testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')


def test_files(host):
dirs = [
"/etc/caddy",
"/opt/node_exporter"
]
for dir in dirs:
d = host.file(dir)
assert d.exists
assert d.is_directory


def test_packages(host)
pkgs = [
"git"
]
for p in pkgs:
assert host.package(p).is_installed


def test_service(host):
s = host.service("caddy")
assert s.is_enabled
assert s.is_running


def test_socket(host):
sockets = [
"tcp://localhost:2020"
]
for socket in sockets:
s = host.socket(socket)
assert s.is_listening

0 comments on commit 14e89e8

Please sign in to comment.