mirror of
https://github.com/Maks1mS/ansible-role-docker.git
synced 2024-12-24 00:33:04 +03:00
Switch tests to use Molecule.
This commit is contained in:
parent
bac7157eda
commit
41f9315a49
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
*.retry
|
||||
tests/test.sh
|
||||
*/__pycache__
|
||||
*.pyc
|
||||
|
40
.travis.yml
40
.travis.yml
@ -1,28 +1,32 @@
|
||||
---
|
||||
language: python
|
||||
services: docker
|
||||
|
||||
env:
|
||||
- distro: centos7
|
||||
- distro: ubuntu1804
|
||||
- distro: ubuntu1604
|
||||
- distro: ubuntu1404
|
||||
- distro: debian9
|
||||
- distro: fedora27
|
||||
global:
|
||||
- ROLE_NAME: docker
|
||||
matrix:
|
||||
- MOLECULE_DISTRO: centos7
|
||||
MOLECULE_DOCKER_COMMAND: /usr/lib/systemd/systemd
|
||||
- MOLECULE_DISTRO: ubuntu1804
|
||||
- MOLECULE_DISTRO: ubuntu1604
|
||||
- MOLECULE_DISTRO: ubuntu1404
|
||||
- MOLECULE_DISTRO: debian9
|
||||
- MOLECULE_DISTRO: fedora27
|
||||
|
||||
install:
|
||||
# Install test dependencies.
|
||||
- pip install molecule docker
|
||||
|
||||
before_script:
|
||||
# Use actual Ansible Galaxy role name for the project directory.
|
||||
- cd ../
|
||||
- mv ansible-role-$ROLE_NAME geerlingguy.$ROLE_NAME
|
||||
- cd geerlingguy.$ROLE_NAME
|
||||
|
||||
script:
|
||||
# Configure test script so we can run extra tests after playbook is run.
|
||||
- export container_id=$(date +%s)
|
||||
- export cleanup=false
|
||||
|
||||
# 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
|
||||
|
||||
# Test whether Docker is running correctly (Dockerception!).
|
||||
- docker exec --tty ${container_id} docker run hello-world
|
||||
- molecule test
|
||||
|
||||
notifications:
|
||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
||||
|
@ -6,11 +6,11 @@ docker_package_state: present
|
||||
|
||||
# Service options.
|
||||
docker_service_state: started
|
||||
docker_service_enabled: yes
|
||||
docker_service_enabled: true
|
||||
docker_restart_handler_state: restarted
|
||||
|
||||
# Docker Compose options.
|
||||
docker_install_compose: True
|
||||
docker_install_compose: true
|
||||
docker_compose_version: "1.22.0"
|
||||
docker_compose_path: /usr/local/bin/docker-compose
|
||||
|
||||
@ -18,7 +18,7 @@ docker_compose_path: /usr/local/bin/docker-compose
|
||||
docker_apt_release_channel: stable
|
||||
docker_apt_arch: amd64
|
||||
docker_apt_repository: "deb [arch={{ docker_apt_arch }}] https://download.docker.com/linux/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}"
|
||||
docker_apt_ignore_key_error: True
|
||||
docker_apt_ignore_key_error: true
|
||||
|
||||
# Used only for RedHat/CentOS/Fedora.
|
||||
docker_yum_repo_url: https://download.docker.com/linux/{{ (ansible_distribution == "Fedora") | ternary("fedora","centos") }}/docker-{{ docker_edition }}.repo
|
||||
|
@ -18,6 +18,7 @@ galaxy_info:
|
||||
- name: Debian
|
||||
versions:
|
||||
- jessie
|
||||
- stretch
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- trusty
|
||||
|
27
molecule/default/molecule.yml
Normal file
27
molecule/default/molecule.yml
Normal file
@ -0,0 +1,27 @@
|
||||
---
|
||||
dependency:
|
||||
name: galaxy
|
||||
driver:
|
||||
name: docker
|
||||
lint:
|
||||
name: yamllint
|
||||
options:
|
||||
config-file: molecule/default/yaml-lint.yml
|
||||
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
|
||||
playbooks:
|
||||
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
|
||||
scenario:
|
||||
name: default
|
||||
verifier:
|
||||
name: testinfra
|
||||
lint:
|
||||
name: flake8
|
@ -1,13 +1,12 @@
|
||||
---
|
||||
- hosts: all
|
||||
- name: Converge
|
||||
hosts: all
|
||||
become: true
|
||||
|
||||
pre_tasks:
|
||||
- name: Update apt cache.
|
||||
apt: update_cache=yes cache_valid_time=600
|
||||
when: ansible_os_family == 'Debian'
|
||||
|
||||
- name: Install test dependencies.
|
||||
package: name=curl state=present
|
||||
|
||||
roles:
|
||||
- role_under_test
|
||||
- role: geerlingguy.docker
|
14
molecule/default/tests/test_default.py
Normal file
14
molecule/default/tests/test_default.py
Normal 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'
|
6
molecule/default/yaml-lint.yml
Normal file
6
molecule/default/yaml-lint.yml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
extends: default
|
||||
rules:
|
||||
line-length:
|
||||
max: 200
|
||||
level: warning
|
@ -3,5 +3,5 @@
|
||||
user:
|
||||
name: "{{ item }}"
|
||||
groups: docker
|
||||
append: yes
|
||||
append: true
|
||||
with_items: "{{ docker_users }}"
|
||||
|
@ -29,11 +29,11 @@
|
||||
- name: Add Docker apt key (alternative for older systems without SNI).
|
||||
shell: "curl -sSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -"
|
||||
args:
|
||||
warn: no
|
||||
warn: false
|
||||
when: add_repository_key is failed
|
||||
|
||||
- name: Add Docker repository.
|
||||
apt_repository:
|
||||
repo: "{{ docker_apt_repository }}"
|
||||
state: present
|
||||
update_cache: yes
|
||||
update_cache: true
|
||||
|
@ -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)`
|
Loading…
Reference in New Issue
Block a user