Add basic docker_compose tests (#150)

* Add basic docker_compose tests.

* Add more constraints for Py 2.

* Try to install docker-compose from system packages.

* Another try.

* Some more tries.

* One more.

* Move task into block.

* Clean up constraints file.

* More adjustments.

* TEMP: add debug output
This commit is contained in:
Felix Fontein 2021-06-07 06:42:31 +02:00 committed by GitHub
parent 2bf67b5a2a
commit 4d0637e178
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 270 additions and 43 deletions

View File

@ -0,0 +1,2 @@
shippable/posix/group4
destructive

View File

@ -0,0 +1,3 @@
---
dependencies:
- setup_docker_compose

View File

@ -0,0 +1,43 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Create random name prefix (for containers, networks, ...)
- name: Create random container name prefix
set_fact:
cname_prefix: "{{ 'ansible-test-%0x' % ((2**32) | random) }}"
cnames: []
dnetworks: []
- debug:
msg: "Using container name prefix {{ cname_prefix }}"
# Run the tests
- block:
- include_tasks: run-test.yml
with_fileglob:
- "tests/*.yml"
always:
- name: "Make sure all containers are removed"
docker_container:
name: "{{ item }}"
state: absent
force_kill: yes
with_items: "{{ cnames }}"
diff: no
- name: "Make sure all networks are removed"
docker_network:
name: "{{ item }}"
state: absent
force: yes
with_items: "{{ dnetworks }}"
when: docker_py_version is version('1.10.0', '>=')
diff: no
when: has_docker_compose and docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')
- fail: msg="Too old docker / docker-py version to run all docker_container tests!"
when: has_docker_compose and not(docker_py_version is version('3.5.0', '>=') and docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

View File

@ -0,0 +1,3 @@
---
- name: "Loading tasks from {{ item }}"
include_tasks: "{{ item }}"

View File

@ -0,0 +1,100 @@
---
- name: Registering container name
set_fact:
pname: "{{ cname_prefix }}"
cname: "{{ cname_prefix ~ '-hi' }}"
- name: Registering container name
set_fact:
cnames: "{{ cnames + [pname ~ '-' ~ cname] }}"
dnetworks: "{{ dnetworks + [pname ~ '_default'] }}"
- name: Define service
set_fact:
test_service: |
version: '2'
services:
{{ cname }}:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
####################################################################
## Present #########################################################
####################################################################
- name: Present (check)
docker_compose:
project_name: "{{ pname }}"
state: present
definition: "{{ test_service | from_yaml }}"
check_mode: yes
register: present_1
- name: Present
docker_compose:
project_name: "{{ pname }}"
state: present
definition: "{{ test_service | from_yaml }}"
register: present_2
- name: Present (idempotent)
docker_compose:
project_name: "{{ pname }}"
state: present
definition: "{{ test_service | from_yaml }}"
register: present_3
- name: Present (idempotent check)
docker_compose:
project_name: "{{ pname }}"
state: present
definition: "{{ test_service | from_yaml }}"
check_mode: yes
register: present_4
- assert:
that:
- present_1 is changed
- present_2 is changed
- present_3 is not changed
- present_4 is not changed
####################################################################
## Absent ##########################################################
####################################################################
- name: Absent (check)
docker_compose:
project_name: "{{ pname }}"
state: absent
definition: "{{ test_service | from_yaml }}"
check_mode: yes
register: absent_1
- name: Absent
docker_compose:
project_name: "{{ pname }}"
state: absent
definition: "{{ test_service | from_yaml }}"
register: absent_2
- name: Absent (idempotent)
docker_compose:
project_name: "{{ pname }}"
state: absent
definition: "{{ test_service | from_yaml }}"
register: absent_3
- name: Absent (idempotent check)
docker_compose:
project_name: "{{ pname }}"
state: absent
definition: "{{ test_service | from_yaml }}"
check_mode: yes
register: absent_4
- assert:
that:
- absent_1 is changed
- absent_2 is changed
- absent_3 is not changed
- absent_4 is not changed

View File

@ -83,6 +83,8 @@
- block:
# Cleanup docker daemon
- command: 'docker ps --no-trunc --format {% raw %}"{{.Names}}"{% endraw %}'
- name: "Remove all ansible-test-* docker containers"
shell: 'docker ps --no-trunc --format {% raw %}"{{.Names}}"{% endraw %} | grep "^ansible-test-" | xargs -r docker rm -f'
register: docker_containers

View File

@ -0,0 +1,6 @@
---
skip_docker_compose: false
docker_compose_packages:
- docker-compose
docker_compose_pip_packages:
- docker-compose

View File

@ -0,0 +1,3 @@
dependencies:
- setup_docker
- setup_remote_constraints

View File

@ -0,0 +1,5 @@
---
- name: Install docker-compose as system package
apt:
name: "{{ docker_compose_packages }}"
state: present

View File

@ -0,0 +1,6 @@
---
- name: Install docker-compose as system package
dnf:
name: "{{ docker_compose_packages }}"
state: present
enablerepo: docker-ce-test

View File

@ -0,0 +1,5 @@
---
- name: Install docker-compose as system package
yum:
name: "{{ docker_compose_packages }}"
state: present

View File

@ -0,0 +1,5 @@
---
- name: Install docker-compose as system package
dnf:
name: "{{ docker_compose_packages }}"
state: present

View File

@ -0,0 +1,8 @@
---
- name: Install docker-compose as system package
community.general.zypper:
name: "{{ docker_compose_packages }}"
force: yes
disable_gpg_check: yes
update_cache: yes
notify: cleanup docker

View File

@ -0,0 +1,12 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
- set_fact:
has_docker_compose: false
- when: ansible_facts.distribution ~ ansible_facts.distribution_major_version not in ['CentOS6', 'RedHat6']
include_tasks:
file: setup.yml

View File

@ -0,0 +1,46 @@
---
- name: Include distribution specific variables
include_vars: "{{ lookup('first_found', params) }}"
vars:
params:
files:
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}-py{{ ansible_python.version.major }}.yml"
- "{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}-py{{ ansible_python.version.major }}.yml"
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml"
- "{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml"
- "{{ ansible_facts.distribution }}-py{{ ansible_python.version.major }}.yml"
- "{{ ansible_facts.os_family }}-py{{ ansible_python.version.major }}.yml"
- "{{ ansible_facts.distribution }}.yml"
- "{{ ansible_facts.os_family }}.yml"
- default.yml
paths:
- "{{ role_path }}/vars"
- block:
- name: Include distribution specific tasks
include_tasks: "{{ lookup('first_found', params) }}"
vars:
params:
files:
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}-py{{ ansible_python.version.major }}.yml"
- "{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}-py{{ ansible_python.version.major }}.yml"
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml"
- "{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml"
- "{{ ansible_facts.distribution }}-py{{ ansible_python.version.major }}.yml"
- "{{ ansible_facts.os_family }}-py{{ ansible_python.version.major }}.yml"
- "{{ ansible_facts.distribution }}.yml"
- "{{ ansible_facts.os_family }}.yml"
paths:
- "{{ role_path }}/tasks"
- name: Install docker-compose
pip:
state: present
name: "{{ docker_compose_pip_packages }}"
extra_args: "-c {{ remote_constraints }}"
- name: Declare docker-compose as existing
set_fact:
has_docker_compose: true
when: not skip_docker_compose

View File

@ -0,0 +1,2 @@
---
skip_docker_compose: true

View File

@ -0,0 +1,2 @@
---
skip_docker_compose: true

View File

@ -0,0 +1,2 @@
---
docker_compose_packages: []

View File

@ -0,0 +1,2 @@
---
skip_docker_compose: true

View File

@ -0,0 +1,2 @@
---
docker_compose_pip_packages: []

View File

@ -0,0 +1,2 @@
---
skip_docker_compose: true

View File

@ -0,0 +1,2 @@
---
skip_docker_compose: true

View File

@ -0,0 +1,2 @@
---
docker_compose_pip_packages: []

View File

@ -0,0 +1 @@
---

View File

@ -1,57 +1,18 @@
bcrypt < 3.2.0 ; python_version <= '3.6'
cffi >= 1.14.2, != 1.14.3 # Yanked version which older versions of pip will still install
coverage >= 4.2, < 5.0.0, != 4.3.2 ; python_version <= '3.7' # features in 4.2+ required, avoid known bug in 4.3.2 on python 2.6, coverage 5.0+ incompatible
coverage >= 4.5.4, < 5.0.0 ; python_version > '3.7' # coverage had a bug in < 4.5.4 that would cause unit tests to hang in Python 3.8, coverage 5.0+ incompatible
cryptography >= 1.3.0, < 2.2 ; python_version < '2.7' # cryptography 2.2 drops support for python 2.6
cryptography >= 1.3.0, < 3.4 ; python_version < '3.6' # cryptography 3.4 drops support for python 2.7
deepdiff < 4.0.0 ; python_version < '3' # deepdiff 4.0.0 and later require python 3
jinja2 < 2.11 ; python_version < '2.7' # jinja2 2.11 and later require python 2.7 or later
urllib3 < 1.24 ; python_version < '2.7' # urllib3 1.24 and later require python 2.7 or later
pywinrm >= 0.3.0 # message encryption support
sphinx < 1.6 ; python_version < '2.7' # sphinx 1.6 and later require python 2.7 or later
sphinx < 1.8 ; python_version >= '2.7' # sphinx 1.8 and later are currently incompatible with rstcheck 3.3
pygments >= 2.4.0 # Pygments 2.4.0 includes bugfixes for YAML and YAML+Jinja lexers
wheel < 0.30.0 ; python_version < '2.7' # wheel 0.30.0 and later require python 2.7 or later
yamllint != 1.8.0, < 1.14.0 ; python_version < '2.7' # yamllint 1.8.0 and 1.14.0+ require python 2.7+
pycrypto >= 2.6 # Need features found in 2.6 and greater
ncclient >= 0.5.2 # Need features added in 0.5.2 and greater
idna < 2.6, >= 2.5 # linode requires idna < 2.9, >= 2.5, requests requires idna < 2.6, but cryptography will cause the latest version to be installed instead
paramiko < 2.4.0 ; python_version < '2.7' # paramiko 2.4.0 drops support for python 2.6
pytest < 3.3.0 ; python_version < '2.7' # pytest 3.3.0 drops support for python 2.6
pytest < 5.0.0 ; python_version == '2.7' # pytest 5.0.0 and later will no longer support python 2.7
pytest-forked < 1.0.2 ; python_version < '2.7' # pytest-forked 1.0.2 and later require python 2.7 or later
pytest-forked >= 1.0.2 ; python_version >= '2.7' # pytest-forked before 1.0.2 does not work with pytest 4.2.0+ (which requires python 2.7+)
ntlm-auth >= 1.3.0 # message encryption support using cryptography
requests < 2.20.0 ; python_version < '2.7' # requests 2.20.0 drops support for python 2.6
requests-ntlm >= 1.1.0 # message encryption support
requests-credssp >= 0.1.0 # message encryption support
voluptuous >= 0.11.0 # Schema recursion via Self
openshift >= 0.6.2, < 0.9.0 # merge_type support
virtualenv < 16.0.0 ; python_version < '2.7' # virtualenv 16.0.0 and later require python 2.7 or later
pathspec < 0.6.0 ; python_version < '2.7' # pathspec 0.6.0 and later require python 2.7 or later
pyopenssl < 18.0.0 ; python_version < '2.7' # pyOpenSSL 18.0.0 and later require python 2.7 or later
pyfmg == 0.6.1 # newer versions do not pass current unit tests
pyyaml < 5.1 ; python_version < '2.7' # pyyaml 5.1 and later require python 2.7 or later
pycparser < 2.19 ; python_version < '2.7' # pycparser 2.19 and later require python 2.7 or later
mock >= 2.0.0 # needed for features backported from Python 3.6 unittest.mock (assert_called, assert_called_once...)
pytest-mock >= 1.4.0 # needed for mock_use_standalone_module pytest option
xmltodict < 0.12.0 ; python_version < '2.7' # xmltodict 0.12.0 and later require python 2.7 or later
lxml < 4.3.0 ; python_version < '2.7' # lxml 4.3.0 and later require python 2.7 or later
pyvmomi < 6.0.0 ; python_version < '2.7' # pyvmomi 6.0.0 and later require python 2.7 or later
pyone == 1.1.9 # newer versions do not pass current integration tests
boto3 < 1.11 ; python_version < '2.7' # boto3 1.11 drops Python 2.6 support
botocore >= 1.10.0, < 1.14 ; python_version < '2.7' # adds support for the following AWS services: secretsmanager, fms, and acm-pca; botocore 1.14 drops Python 2.6 support
botocore >= 1.10.0 ; python_version >= '2.7' # adds support for the following AWS services: secretsmanager, fms, and acm-pca
setuptools < 45 ; python_version <= '2.7' # setuptools 45 and later require python 3.5 or later
cffi >= 1.14.2, != 1.14.3 # Yanked version which older versions of pip will still install:
# freeze pylint and its requirements for consistent test results
astroid == 2.2.5
isort == 4.3.15
lazy-object-proxy == 1.3.1
mccabe == 0.6.1
pylint == 2.3.1
typed-ast == 1.4.0 # 1.4.0 is required to compile on Python 3.8
wrapt == 1.11.1
websocket-client < 1.0.0 ; python_version <= '3.6'
# Restrict docker versions depending on Python version
docker < 5.0.0 ; python_version <= '3.6'
websocket-client < 1.0.0 ; python_version <= '3.6'
docker-compose < 1.25.0 ; python_version <= '3.6'