Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit c51fb62

Browse files
committed
tests: update to template 1.0.0
1 parent 7363064 commit c51fb62

16 files changed

+290
-114
lines changed

.ansible-lint

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
exclude_paths:
3+
- .git
4+
- __pycache__
5+
- .venv
6+
7+
parseable: true
8+
9+
# E204: Ansible is not a programming language and using (global) variables
10+
# to make things beautiful may have consequences
11+
# E503: if /.changed/ is used, even if you loop on a registered variable
12+
# and happens to check item.changed, which cannot be converted in to
13+
# a handler, this rule is not clever enough to understand
14+
# E602: https://github.com/ansible/ansible-lint/issues/457
15+
# https://github.com/ansible/ansible/pull/51030
16+
skip_list:
17+
- '204'
18+
- '403'
19+
- '405'
20+
- '503'
21+
- '602'
22+
- '702'
23+

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[flake8]
22
ignore = E126,E131,E501,E303,E302,W391
3+
exclude =
4+
.git,
5+
__pycache__,
6+
.venv
37

.yamllint

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
---
12
extends: default
23

4+
ignore: |
5+
.git
6+
__pycache__
7+
.venv
8+
39
rules:
410
braces:
511
max-spaces-inside: 1

molecule/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
__pycache__
22
*.pyc
3+
pytestdebug.log

molecule/_resources/Dockerfile.j2

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,5 @@ FROM {{ item.registry.url }}/{{ item.image }}
66
FROM {{ item.image }}
77
{% endif %}
88

9-
# on Red Hat systems using dnf, Python 3 is already installed
10-
# the package is versioned and there is no 'python3' dependency package, so better do nothing
11-
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; \
12-
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install sudo python3-devel python3-dnf bash && dnf clean all; \
13-
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; \
14-
elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \
15-
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; fi
9+
RUN {{ image_setup }}
10+
File renamed without changes.

molecule/_resources/create-docker.yml

Lines changed: 102 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
hosts: localhost
44
connection: local
55
gather_facts: false
6-
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
6+
no_log: "{{ molecule_no_log }}"
7+
vars:
8+
molecule_labels:
9+
owner: molecule
710
tasks:
811
- name: Apply global default parameters
912
set_fact:
10-
final_platforms: "{{ final_platforms | default([]) | union([platform_base.docker|combine(item)]) }}"
13+
final_platforms: "{{ final_platforms | default([]) | union([hostvars[item.name].platform_base.docker|combine(item)]) }}"
1114
loop: "{{ molecule_yml.platforms }}"
1215

1316
- name: Log into a Docker registry
@@ -17,75 +20,157 @@
1720
email: "{{ item.registry.credentials.email | default(omit) }}"
1821
registry: "{{ item.registry.url }}"
1922
docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
23+
cacert_path: "{{ item.cacert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/ca.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
24+
cert_path: "{{ item.cert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/cert.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
25+
key_path: "{{ item.key_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/key.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
26+
tls_verify: "{{ item.tls_verify | default(lookup('env', 'DOCKER_TLS_VERIFY')) or false }}"
2027
with_items: "{{ final_platforms }}"
2128
when:
2229
- item.registry is defined
2330
- item.registry.credentials is defined
2431
- item.registry.credentials.username is defined
2532

33+
- name: Check presence of custom Dockerfiles
34+
stat:
35+
path: "{{ molecule_scenario_directory + '/' + (item.dockerfile | default( 'Dockerfile.j2')) }}"
36+
loop: "{{ final_platforms }}"
37+
register: dockerfile_stats
38+
2639
- name: Create Dockerfiles from image names
40+
vars:
41+
# TODO(ssbarnea): expose module dir so it can also be used by plugins
42+
molecule_module_directory: "{{ playbook_dir + '/../../../..' }}"
2743
template:
28-
# use a common recipe
29-
src: "{{ molecule_scenario_directory }}/../_resources/Dockerfile.j2"
44+
src: >-
45+
{%- if dockerfile_stats.results[i].stat.exists -%}
46+
{{ molecule_scenario_directory + '/' + (item.dockerfile | default( 'Dockerfile.j2')) }}
47+
{%- else -%}
48+
{{ molecule_module_directory + '/data/Dockerfile.j2' }}
49+
{%- endif -%}
3050
dest: "{{ molecule_ephemeral_directory }}/Dockerfile_{{ item.image | regex_replace('[^a-zA-Z0-9_]', '_') }}"
31-
with_items: "{{ final_platforms }}"
51+
loop: "{{ final_platforms }}"
52+
loop_control:
53+
index_var: i
3254
when: not item.pre_build_image | default(false)
3355
register: platforms
3456

3557
- name: Discover local Docker images
36-
docker_image_facts:
58+
docker_image_info:
3759
name: "molecule_local/{{ item.item.name }}"
3860
docker_host: "{{ item.item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
61+
cacert_path: "{{ item.cacert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/ca.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
62+
cert_path: "{{ item.cert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/cert.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
63+
key_path: "{{ item.key_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/key.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
64+
tls_verify: "{{ item.tls_verify | default(lookup('env', 'DOCKER_TLS_VERIFY')) or false }}"
3965
with_items: "{{ platforms.results }}"
40-
when: not item.pre_build_image | default(false)
66+
when:
67+
- not item.pre_build_image | default(false)
4168
register: docker_images
4269

43-
- name: Build an Ansible compatible image
70+
- name: Build an Ansible compatible image (new)
71+
when:
72+
- platforms.changed or docker_images.results | map(attribute='images') | select('equalto', []) | list | count >= 0
73+
- not item.item.pre_build_image | default(false)
4474
docker_image:
45-
path: "{{ molecule_ephemeral_directory }}"
75+
build:
76+
path: "{{ molecule_ephemeral_directory }}"
77+
dockerfile: "{{ item.invocation.module_args.dest }}"
78+
pull: "{{ item.item.pull | default(true) }}"
79+
network: "{{ item.item.network_mode | default(omit) }}"
80+
args: "{{ item.item.buildargs | default(omit) }}"
4681
name: "molecule_local/{{ item.item.image }}"
4782
docker_host: "{{ item.item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
48-
dockerfile: "{{ item.item.dockerfile | default(item.invocation.module_args.dest) }}"
49-
force: "{{ item.item.force | default(true) }}"
50-
pull: "{{ item.item.pull | default(omit) }}"
83+
cacert_path: "{{ item.cacert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/ca.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
84+
cert_path: "{{ item.cert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/cert.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
85+
key_path: "{{ item.key_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/key.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
86+
tls_verify: "{{ item.tls_verify | default(lookup('env', 'DOCKER_TLS_VERIFY')) or false }}"
87+
force_source: "{{ item.item.force | default(true) }}"
88+
source: build
5189
with_items: "{{ platforms.results }}"
52-
when:
53-
- platforms.changed or docker_images.results | map(attribute='images') | select('equalto', []) | list | count >= 0
54-
- not item.item.pre_build_image | default(false)
90+
loop_control:
91+
label: "molecule_local/{{ item.item.image }}"
92+
no_log: false
93+
register: result
94+
until: result is not failed
95+
retries: 3
96+
delay: 30
5597

5698
- name: Create docker network(s)
5799
docker_network:
58100
name: "{{ item }}"
59101
docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
102+
cacert_path: "{{ item.cacert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/ca.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
103+
cert_path: "{{ item.cert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/cert.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
104+
key_path: "{{ item.key_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/key.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
105+
tls_verify: "{{ item.tls_verify | default(lookup('env', 'DOCKER_TLS_VERIFY')) or false }}"
106+
labels: "{{ molecule_labels | combine(item.labels | default({})) }}"
60107
state: present
108+
# Duck: we need IPv6
109+
enable_ipv6: True
110+
ipam_config:
111+
# RFC 4193
112+
- subnet: fdd1:0:0:0::/64
61113
with_items: "{{ final_platforms | molecule_get_docker_networks }}"
114+
loop_control:
115+
label: "{{ item }}"
116+
no_log: false
117+
118+
- name: Determine the CMD directives
119+
set_fact:
120+
command_directives_dict: >-
121+
{{ command_directives_dict | default({}) |
122+
combine({ item.name: item.command | default('bash -c "while true; do sleep 10000; done"') })
123+
}}
124+
with_items: "{{ final_platforms }}"
125+
when: item.override_command | default(true)
62126

63127
- name: Create molecule instance(s)
64128
docker_container:
65129
name: "{{ item.name }}"
66130
docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
67-
hostname: "{{ item.hostname | default(item.name) }}"
131+
cacert_path: "{{ item.cacert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/ca.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
132+
cert_path: "{{ item.cert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/cert.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
133+
key_path: "{{ item.key_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/key.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
134+
tls_verify: "{{ item.tls_verify | default(lookup('env', 'DOCKER_TLS_VERIFY')) or false }}"
135+
hostname: "{{ item.hostname | default(item.name) | replace('@NAME@', item.name) }}"
68136
image: "{{ item.pre_build_image | default(false) | ternary('', 'molecule_local/') }}{{ item.image }}"
137+
pull: "{{ item.pull | default(omit) }}"
138+
memory: "{{ item.memory | default(omit) }}"
69139
state: started
70140
recreate: false
71141
log_driver: json-file
72-
command: "{{ item.command | default('bash -c \"while true; do sleep 10000; done\"') }}"
142+
command: "{{ (command_directives_dict | default({}))[item.name] | default(omit) }}"
143+
user: "{{ item.user | default(omit) }}"
144+
pid_mode: "{{ item.pid_mode | default(omit) }}"
73145
privileged: "{{ item.privileged | default(omit) }}"
74146
security_opts: "{{ item.security_opts | default(omit) }}"
147+
devices: "{{ item.devices | default(omit) }}"
75148
volumes: "{{ item.volumes | default(omit) }}"
76149
tmpfs: "{{ item.tmpfs | default(omit) }}"
77150
capabilities: "{{ item.capabilities | default(omit) }}"
151+
sysctls: "{{ item.sysctls | default(omit) }}"
78152
exposed_ports: "{{ item.exposed_ports | default(omit) }}"
79153
published_ports: "{{ item.published_ports | default(omit) }}"
80154
ulimits: "{{ item.ulimits | default(omit) }}"
81155
networks: "{{ item.networks | default(omit) }}"
82156
network_mode: "{{ item.network_mode | default(omit) }}"
157+
networks_cli_compatible: "{{ item.networks_cli_compatible | default(true) }}"
158+
purge_networks: "{{ item.purge_networks | default(omit) }}"
83159
dns_servers: "{{ item.dns_servers | default(omit) }}"
160+
etc_hosts: "{{ item.etc_hosts | default(omit) }}"
84161
env: "{{ item.env | default(omit) }}"
85162
restart_policy: "{{ item.restart_policy | default(omit) }}"
86163
restart_retries: "{{ item.restart_retries | default(omit) }}"
164+
tty: "{{ item.tty | default(omit) }}"
165+
labels: "{{ molecule_labels | combine(item.labels | default({})) }}"
166+
container_default_behavior: "{{ item.container_default_behavior | default('compatibility' if ansible_version.full is version_compare('2.10', '>=') else omit) }}"
167+
# Duck: missing parameters
168+
dns_search_domains: "{{ item.dns_search_domains | default(omit) }}"
87169
register: server
88170
with_items: "{{ final_platforms }}"
171+
loop_control:
172+
label: "{{ item.name }}"
173+
no_log: false
89174
async: 7200
90175
poll: 0
91176

molecule/_resources/create-lxd.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
tasks:
88
- name: Apply global default parameters
99
set_fact:
10-
final_platforms: "{{ final_platforms | default([]) | union([platform_base.docker|combine(item)]) }}"
10+
final_platforms: "{{ final_platforms | default([]) | union([hostvars[item.name].platform_base.lxd|combine(item)]) }}"
1111
loop: "{{ molecule_yml.platforms }}"
1212

1313
- name: Create default source variable
@@ -33,3 +33,10 @@
3333
wait_for_ipv4_addresses: true
3434
timeout: 600
3535
with_items: "{{ final_platforms }}"
36+
37+
- hosts: all
38+
gather_facts: False
39+
tasks:
40+
- name: "Setup Image"
41+
raw: "{{ image_setup }}"
42+
changed_when: True

molecule/_resources/destroy-docker.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,30 @@
33
hosts: localhost
44
connection: local
55
gather_facts: false
6-
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
6+
no_log: "{{ molecule_no_log }}"
77
tasks:
88
- name: Apply global default parameters
99
set_fact:
10-
final_platforms: "{{ final_platforms | default([]) | union([platform_base.docker|combine(item)]) }}"
10+
final_platforms: "{{ final_platforms | default([]) | union([hostvars[item.name].platform_base.docker|combine(item)]) }}"
1111
loop: "{{ molecule_yml.platforms }}"
1212

1313
- name: Destroy molecule instance(s)
1414
docker_container:
1515
name: "{{ item.name }}"
1616
docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
17+
cacert_path: "{{ item.cacert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/ca.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
18+
cert_path: "{{ item.cert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/cert.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
19+
key_path: "{{ item.key_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/key.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
20+
tls_verify: "{{ item.tls_verify | default(lookup('env', 'DOCKER_TLS_VERIFY')) or false }}"
1721
state: absent
1822
force_kill: "{{ item.force_kill | default(true) }}"
23+
keep_volumes: "{{ item.keep_volumes | default(true) }}"
24+
container_default_behavior: "{{ item.container_default_behavior | default('compatibility' if ansible_version.full is version_compare('2.10', '>=') else omit) }}"
1925
register: server
2026
with_items: "{{ final_platforms }}"
27+
loop_control:
28+
label: "{{ item.name }}"
29+
no_log: false
2130
async: 7200
2231
poll: 0
2332

@@ -33,5 +42,12 @@
3342
docker_network:
3443
name: "{{ item }}"
3544
docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}"
45+
cacert_path: "{{ item.cacert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/ca.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
46+
cert_path: "{{ item.cert_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/cert.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
47+
key_path: "{{ item.key_path | default((lookup('env', 'DOCKER_CERT_PATH') + '/key.pem') if lookup('env', 'DOCKER_CERT_PATH') else omit) }}"
48+
tls_verify: "{{ item.tls_verify | default(lookup('env', 'DOCKER_TLS_VERIFY')) or false }}"
3649
state: absent
3750
with_items: "{{ final_platforms | molecule_get_docker_networks }}"
51+
loop_control:
52+
label: "{{ item }}"
53+
no_log: false

molecule/_resources/destroy-lxd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
tasks:
88
- name: Apply global default parameters
99
set_fact:
10-
final_platforms: "{{ final_platforms | default([]) | union([platform_base.docker|combine(item)]) }}"
10+
final_platforms: "{{ final_platforms | default([]) | union([hostvars[item.name].platform_base.lxd|combine(item)]) }}"
1111
loop: "{{ molecule_yml.platforms }}"
1212

1313
- name: Destroy molecule instance(s)
1414
lxd_container:
15-
url: "{{ item.url | default(omit)}}"
15+
url: "{{ item.url | default(omit) }}"
1616
cert_file: "{{ item.cert_file | default(omit) }}"
1717
key_file: "{{ item.key_file | default(omit) }}"
1818
trust_password: "{{ item.trust_password | default(omit) }}"

0 commit comments

Comments
 (0)