Fixes #30: Switch tests to use Molecule.

This commit is contained in:
Jeff Geerling 2018-09-25 20:24:48 -05:00
parent b98cfe46ca
commit ad911a67f2
11 changed files with 82 additions and 31 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.retry
tests/test.sh
*/__pycache__
*.pyc

View File

@ -1,19 +1,21 @@
---
language: python
services: docker
env:
- distro: centos7
# - distro: ubuntu1604
- distro: ubuntu1404
- distro: ubuntu1204
- MOLECULE_DISTRO: centos7
MOLECULE_DOCKER_COMMAND: /usr/lib/systemd/systemd
- MOLECULE_DISTRO: centos6
- MOLECULE_DISTRO: ubuntu1804
- MOLECULE_DISTRO: ubuntu1604
install:
# Install test dependencies.
- pip install molecule docker
script:
# Download test shim.
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
- chmod +x ${PWD}/tests/test.sh
# Run tests.
- ${PWD}/tests/test.sh
- molecule test
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@ -16,6 +16,11 @@ Available variables are listed below, along with default values (see `defaults/m
A list of exports which will be placed in the `/etc/exports` file. See Ubuntu's simple [Network File System (NFS)](https://help.ubuntu.com/14.04/serverguide/network-file-system.html) guide for more info and examples. (Simple example: `nfs_exports: [ "/home/public *(rw,sync,no_root_squash)" ]`).
nfs_rpcbind_state: started
nfs_rpcbind_enabled: true
(RedHat/CentOS/Fedora only) The state of the `rpcbind` service, and whether it should be enabled at system boot.
## Dependencies
None.

View File

@ -1,2 +1,5 @@
---
nfs_exports: []
nfs_rpcbind_state: started
nfs_rpcbind_enabled: true

View File

@ -10,15 +10,20 @@ galaxy_info:
platforms:
- name: EL
versions:
- all
- all
- name: Fedora
versions:
- all
- all
- name: Debian
versions:
- all
- all
- name: Ubuntu
versions:
- all
- all
galaxy_tags:
- system
- nfs
- filesystem
- share
- nfsv4
- efs

View File

@ -0,0 +1,23 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: instance
image: geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible
command: ${MOLECULE_DOCKER_COMMAND:-"sleep infinity"}
privileged: true
pre_build_image: true
provisioner:
name: ansible
lint:
name: ansible-lint
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8

View File

@ -1,5 +1,7 @@
---
- hosts: all
- name: Converge
hosts: all
become: true
pre_tasks:
- name: Update apt cache.
@ -8,4 +10,4 @@
changed_when: false
roles:
- role_under_test
- role: geerlingguy.nfs

View File

@ -0,0 +1,14 @@
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_hosts_file(host):
f = host.file('/etc/hosts')
assert f.exists
assert f.user == 'root'
assert f.group == 'root'

View File

@ -5,11 +5,15 @@
- name: Include overrides specific to RHEL 7.
include_vars: RedHat-7.yml
when: ansible_os_family == 'RedHat' and ansible_distribution_major_version == "7"
when:
- ansible_os_family == 'RedHat'
- ansible_distribution_major_version == "7"
- name: Include overrides specific to Fedora.
include_vars: Fedora.yml
when: ansible_os_family == 'RedHat' and ansible_distribution == "Fedora"
when:
- ansible_os_family == 'RedHat'
- ansible_distribution == "Fedora"
# Setup/install tasks.
- include_tasks: setup-RedHat.yml

View File

@ -2,5 +2,8 @@
- name: Ensure NFS utilities are installed.
package: name=nfs-utils state=present
- name: Ensure rpcbind is running.
service: name=rpcbind state=started enabled=yes
- name: Ensure rpcbind is running as configured.
service:
name: rpcbind
state: "{{ nfs_rpcbind_state }}"
enabled: "{{ nfs_rpcbind_enabled }}"

View File

@ -1,11 +0,0 @@
# Ansible Role tests
To run the test playbook(s) in this directory:
1. Install and start Docker.
1. Download the test shim (see .travis.yml file for the URL) into `tests/test.sh`:
- `wget -O tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/`
1. Make the test shim executable: `chmod +x tests/test.sh`.
1. Run (from the role root directory) `distro=[distro] playbook=[playbook] ./tests/test.sh`
If you don't want the container to be automatically deleted after the test playbook is run, add the following environment variables: `cleanup=false container_id=$(date +%s)`