Skip to content

Commit 16f21c5

Browse files
authored
Optimise testing and fix CentOS GeoIP module (#185)
* Use slim Debian images for testing * Update `volume_mounts` to `volumes` * Update and move default Dockerfile * Use normal centos image * Add epel-release prerequisite to CentOS modules * Separate module and template tests
1 parent 3778113 commit 16f21c5

File tree

17 files changed

+178
-84
lines changed

17 files changed

+178
-84
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ services:
55
- docker
66
env:
77
- scenario: default
8+
- scenario: module
89
- scenario: stable_push
9-
- scenario: template_module
10+
- scenario: template
1011
- scenario: unit
1112
before_install:
1213
- sudo apt-get -qq update

molecule/common/Dockerfile.j2

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
{% if item.env is defined %}
10+
{% for var, value in item.env.items() %}
11+
{% if value %}
12+
ENV {{ var }} {{ value }}
13+
{% endif %}
14+
{% endfor %}
15+
{% endif %}
16+
17+
RUN \
18+
if [ $(command -v apt-get) ]; then \
19+
apt-get update \
20+
&& apt-get install -y python sudo bash ca-certificates iproute2 curl \
21+
&& apt-get clean; \
22+
elif [ $(command -v dnf) ]; then \
23+
dnf makecache \
24+
&& dnf --assumeyes install python sudo python-devel python*-dnf bash iproute \
25+
&& dnf clean all; \
26+
elif [ $(command -v yum) ]; then \
27+
yum makecache fast \
28+
&& yum install -y python sudo yum-plugin-ovl bash iproute \
29+
&& sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf \
30+
&& yum clean all; \
31+
elif [ $(command -v zypper) ]; then \
32+
zypper refresh \
33+
&& zypper install -y python sudo bash python-xml iproute2 \
34+
&& zypper clean -a; \
35+
elif [ $(command -v apk) ]; then \
36+
apk update \
37+
&& apk add --no-cache python sudo bash ca-certificates; \
38+
elif [ $(command -v xbps-install) ]; then \
39+
xbps-install -Syu \
40+
&& xbps-install -y python sudo bash ca-certificates iproute2 \
41+
&& xbps-remove -O; \
42+
fi

molecule/default/Dockerfile.j2

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

molecule/default/molecule.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,27 @@ lint:
66
platforms:
77
- name: centos-6
88
image: centos:6
9+
dockerfile: ../common/Dockerfile.j2
910
- name: centos-7
10-
image: centos/systemd
11+
image: centos:7
12+
dockerfile: ../common/Dockerfile.j2
1113
privileged: True
12-
volume_mounts:
14+
volumes:
1315
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
1416
command: "/usr/sbin/init"
17+
tty: True
1518
- name: debian-stretch
16-
image: debian:stretch
19+
image: debian:stretch-slim
20+
dockerfile: ../common/Dockerfile.j2
1721
- name: debian-buster
18-
image: debian:buster
22+
image: debian:buster-slim
23+
dockerfile: ../common/Dockerfile.j2
1924
- name: ubuntu-xenial
2025
image: ubuntu:xenial
26+
dockerfile: ../common/Dockerfile.j2
2127
- name: ubuntu-bionic
2228
image: ubuntu:bionic
29+
dockerfile: ../common/Dockerfile.j2
2330
provisioner:
2431
name: ansible
2532
lint:

molecule/default/playbook.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
pre_tasks:
55
- name: "Set repo if Debian"
66
set_fact:
7-
version: "=1.17.4-1~{{ ansible_distribution_release }}"
7+
version: "=1.17.6-1~{{ ansible_distribution_release }}"
88
when: ansible_os_family == "Debian"
99
- name: "Set repo if RedHat"
1010
set_fact:
11-
version: "-1.17.4-1.el{{ ansible_distribution_major_version }}.ngx"
11+
version: "-1.17.6-1.el{{ ansible_distribution_major_version }}.ngx"
1212
when: ansible_os_family == "RedHat"
1313
roles:
1414
- role: ansible-role-nginx

molecule/module/molecule.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
driver:
3+
name: docker
4+
lint:
5+
name: yamllint
6+
platforms:
7+
- name: centos-6
8+
image: centos:6
9+
dockerfile: ../common/Dockerfile.j2
10+
- name: centos-7
11+
image: centos:7
12+
dockerfile: ../common/Dockerfile.j2
13+
privileged: True
14+
volumes:
15+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
16+
command: "/usr/sbin/init"
17+
tty: True
18+
- name: debian-stretch
19+
image: debian:stretch-slim
20+
dockerfile: ../common/Dockerfile.j2
21+
- name: debian-buster
22+
image: debian:buster-slim
23+
dockerfile: ../common/Dockerfile.j2
24+
- name: ubuntu-xenial
25+
image: ubuntu:xenial
26+
dockerfile: ../common/Dockerfile.j2
27+
- name: ubuntu-bionic
28+
image: ubuntu:bionic
29+
dockerfile: ../common/Dockerfile.j2
30+
provisioner:
31+
name: ansible
32+
lint:
33+
name: ansible-lint
34+
verifier:
35+
name: testinfra
36+
lint:
37+
name: flake8

molecule/module/playbook.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
roles:
5+
- role: ansible-role-nginx
6+
vars:
7+
nginx_debug_output: true
8+
9+
nginx_modules:
10+
njs: true
11+
perl: true
12+
waf: false
13+
geoip: true
14+
image_filter: true
15+
rtmp: true
16+
xslt: true

molecule/module/tests/test_default.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
3+
import testinfra.utils.ansible_runner
4+
5+
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') # noqa E501
6+
7+
8+
def test_nginx_is_installed(host):
9+
ngx = host.package("nginx")
10+
assert ngx.is_installed
11+
12+
13+
def test_nginx_running_and_enabled(host):
14+
ngx = host.service("nginx")
15+
assert ngx.is_running
16+
assert ngx.is_enabled
17+
18+
19+
def test_hosts_file(host):
20+
ngx = host.file('/etc/hosts')
21+
assert ngx.exists
22+
assert ngx.user == 'root'
23+
assert ngx.group == 'root'
24+
25+
26+
def test_endpoint(host):
27+
command = """curl -I http://localhost/"""
28+
cmd = host.run(command)
29+
assert '200 OK' in cmd.stdout

molecule/stable_push/Dockerfile.j2

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

molecule/stable_push/molecule.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,27 @@ lint:
99
platforms:
1010
- name: centos-6
1111
image: centos:6
12+
dockerfile: ../common/Dockerfile.j2
1213
- name: centos-7
13-
image: centos/systemd
14+
image: centos:7
15+
dockerfile: ../common/Dockerfile.j2
1416
privileged: True
15-
volume_mounts:
17+
volumes:
1618
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
1719
command: "/usr/sbin/init"
20+
tty: True
1821
- name: debian-stretch
19-
image: debian:stretch
22+
image: debian:stretch-slim
23+
dockerfile: ../common/Dockerfile.j2
2024
- name: debian-buster
21-
image: debian:buster
25+
image: debian:buster-slim
26+
dockerfile: ../common/Dockerfile.j2
2227
- name: ubuntu-xenial
2328
image: ubuntu:xenial
29+
dockerfile: ../common/Dockerfile.j2
2430
- name: ubuntu-bionic
2531
image: ubuntu:bionic
32+
dockerfile: ../common/Dockerfile.j2
2633
provisioner:
2734
name: ansible
2835
lint:

0 commit comments

Comments
 (0)