Skip to content

Commit 1e69608

Browse files
committed
tox & molecule2
1 parent a25f625 commit 1e69608

File tree

10 files changed

+283
-28
lines changed

10 files changed

+283
-28
lines changed

.gitignore

Lines changed: 99 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,102 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
15

2-
# Binaries for programs and plugins
3-
# Output of the go coverage tool, specifically when used with LiteIDE
4-
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
5-
# Test binary, build with `go test -c`
6-
*.dll
7-
*.dylib
8-
*.exe
9-
*.out
6+
# C extensions
107
*.so
11-
*.test
12-
.DS_Store
13-
.glide/
8+
149
.molecule
10+
# Distribution / packaging
11+
.Python
12+
env/
13+
build/
14+
develop-eggs/
15+
dist/
16+
downloads/
17+
eggs/
18+
.eggs/
19+
lib/
20+
lib64/
21+
parts/
22+
sdist/
23+
var/
24+
wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*.cover
48+
.hypothesis/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
58+
# Flask stuff:
59+
instance/
60+
.webassets-cache
61+
62+
# Scrapy stuff:
63+
.scrapy
64+
65+
# Sphinx documentation
66+
docs/_build/
67+
68+
# PyBuilder
69+
target/
70+
71+
# Jupyter Notebook
72+
.ipynb_checkpoints
73+
74+
# pyenv
75+
.python-version
76+
77+
# celery beat schedule file
78+
celerybeat-schedule
79+
80+
# SageMath parsed files
81+
*.sage.py
82+
83+
# dotenv
84+
.env
85+
86+
# virtualenv
87+
.venv
88+
venv/
89+
ENV/
90+
91+
# Spyder project settings
92+
.spyderproject
93+
.spyproject
94+
95+
# Rope project settings
96+
.ropeproject
97+
98+
# mkdocs documentation
99+
/site
100+
101+
# mypy
102+
.mypy_cache/

molecule.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

molecule/default/Dockerfile.j2

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Molecule managed
2+
3+
{% if item.registry is defined %}
4+
FROM {{ item.registry.url }}/{{ item.image }}
5+
{% else %}
6+
FROM {{ item.image }}
7+
{% endif %}
8+
9+
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
10+
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \
11+
elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
12+
elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \
13+
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
14+
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi

molecule/default/INSTALL.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
*******
2+
Docker driver installation guide
3+
*******
4+
5+
Requirements
6+
============
7+
8+
* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html)
9+
* Docker Engine
10+
* docker-py
11+
* docker
12+
13+
Install
14+
=======
15+
16+
Ansible < 2.6
17+
18+
.. code-block:: bash
19+
20+
$ sudo pip install docker-py
21+
22+
Ansible >= 2.6
23+
24+
.. code-block:: bash
25+
26+
$ sudo pip install docker

molecule/default/molecule.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
requirements_file: requirements.yml
5+
driver:
6+
name: docker
7+
lint:
8+
name: yamllint
9+
platforms:
10+
- name: base-goss-centos
11+
image: centos:7
12+
privileged: True
13+
- name: base-goss-ubuntu
14+
image: ubuntu
15+
privileged: True
16+
provisioner:
17+
name: ansible
18+
config_options:
19+
defaults:
20+
remote_tmp: /tmp
21+
playbooks:
22+
converge: playbook.yml
23+
lint:
24+
name: ansible-lint
25+
scenario:
26+
name: default
File renamed without changes.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This is an example playbook to execute goss tests.
2+
# Tests need distributed to the appropriate ansible host/groups
3+
# prior to execution by `goss validate`.
4+
#
5+
# The goss ansible module is installed with molecule. The ANSIBLE_LIBRARY
6+
# path is updated appropriately on `molecule verify`.
7+
8+
# Details about ansible module:
9+
# - https://github.com/indusbox/goss-ansible
10+
11+
- name: Testing prerequisites
12+
hosts: all
13+
gather_facts: yes
14+
15+
vars_files:
16+
- ../defaults/main.yml
17+
- ../vars/main.yml
18+
tasks:
19+
- name: Copy tests to remote
20+
template:
21+
src: "{{ playbook_dir }}/../templates/goss.yaml"
22+
dest: "/root/goss.yaml"
23+
no_log: yes
24+
25+
- name: Execute goss tests
26+
hosts: all
27+
gather_facts: no
28+
29+
vars:
30+
goss_results: goss_results
31+
32+
tasks:
33+
- name: Create foler for goss result files
34+
file:
35+
path: "{{ goss_results }}"
36+
state: directory
37+
mode: 0700
38+
39+
- name: Test goss file
40+
goss:
41+
path: "/root/goss.yaml"
42+
format: documentation
43+
output_file: "{{ goss_results }}/goss.txt"
44+
45+
- name: Display details about goss results
46+
debug:
47+
msg: "Goss test results are in folder: {{ goss_results }}"

molecule/default/verify.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
# This is an example playbook to execute goss tests.
3+
# Tests need distributed to the appropriate ansible host/groups
4+
# prior to execution by `goss validate`.
5+
6+
- name: Verify
7+
hosts: all
8+
become: true
9+
vars:
10+
goss_version: v0.3.2
11+
goss_arch: amd64
12+
goss_dst: /usr/local/bin/goss
13+
goss_sha256sum: 2f6727375db2ea0f81bee36e2c5be78ab5ab8d5981f632f761b25e4003e190ec
14+
goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"
15+
goss_test_directory: /tmp
16+
goss_format: documentation
17+
tasks:
18+
- name: Download and install Goss
19+
get_url:
20+
url: "{{ goss_url }}"
21+
dest: "{{ goss_dst }}"
22+
sha256sum: "{{ goss_sha256sum }}"
23+
mode: 0755
24+
register: download_goss
25+
until: download_goss is succeeded
26+
retries: 3
27+
28+
- name: Copy Goss tests to remote
29+
copy:
30+
src: "{{ item }}"
31+
dest: "{{ goss_test_directory }}/{{ item | basename }}"
32+
with_fileglob:
33+
- "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_*.yml"
34+
35+
- name: Register test files
36+
shell: "ls {{ goss_test_directory }}/test_*.yml"
37+
register: test_files
38+
39+
- name: Execute Goss tests
40+
command: "{{ goss_dst }} -g {{ item }} validate --format {{ goss_format }}"
41+
register: test_results
42+
with_items: "{{ test_files.stdout_lines }}"
43+
44+
- name: Display details about the Goss results
45+
debug:
46+
msg: "{{ item.stdout_lines }}"
47+
with_items: "{{ test_results.results }}"
48+
49+
- name: Fail when tests fail
50+
fail:
51+
msg: "Goss failed to validate"
52+
when: item.rc != 0
53+
with_items: "{{ test_results.results }}"

requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1+
tox
2+
molecule
13
docker
2-
ansible==2.3.1.0
3-
yamllint==1.8.1
4-
molecule==1.25.1

tox.ini

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tox]
2+
minversion = 1.8
3+
envlist = py{27}-ansible{24,25},molecule,yamllint
4+
skipsdist = true
5+
6+
[testenv]
7+
# ansible only supports python3 in versions >= 2.5
8+
basepython = python2.7
9+
passenv = *
10+
deps =
11+
-rrequirements.txt
12+
ansible24: ansible>=2.4,<2.5
13+
ansible25: ansible>=2.5,<2.6
14+
commands =
15+
pip list
16+
molecule test

0 commit comments

Comments
 (0)