docker_api connection plugin (#40)

* Add basic docker_api connection test.

* Split AnsibleDockerClient into module-independent and module-specific part.

* Mention new connection plugin.

* Fix tests.

* Add first version of docker_api connection plugin.

* Linting.

* Fix references.

* Improve connection tests.

* Fix put_file for all Python versions.

* Fix fetch_file.

* Linting.

* Update plugins/connection/docker_api.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Move potential common code to module_utils / plugin_utils.

* Move socket_handler to plugin_utils.

* Fix typo.

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
This commit is contained in:
Felix Fontein
2020-12-15 21:07:55 +01:00
committed by GitHub
parent ebafa17b02
commit 8bd33b06c4
13 changed files with 882 additions and 137 deletions
@@ -0,0 +1,3 @@
shippable/posix/group4
skip/docker # coverage does not work if we're inside a docker container, since we cannot access this container's /tmp dir from the new container
destructive
@@ -0,0 +1,3 @@
---
dependencies:
- setup_docker
@@ -0,0 +1 @@
../connection_posix/test.sh
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/env bash
# If you use another image, you possibly also need to adjust
# ansible_python_interpreter in test_connection.inventory.
source ../setup_docker/vars/main.env
IMAGE="${DOCKER_TEST_IMAGE_PYTHON3}"
# Setup phase
echo "Setup"
ANSIBLE_ROLES_PATH=.. ansible-playbook setup.yml
# If docker wasn't installed, don't run the tests
if [ "$(command -v docker)" == "" ]; then
exit
fi
# Test phase
CONTAINER_SUFFIX=-${RANDOM}
DOCKER_CONTAINERS="docker-connection-test-container${CONTAINER_SUFFIX}"
[[ -n "$DEBUG" || -n "$ANSIBLE_DEBUG" ]] && set -x
set -euo pipefail
cleanup() {
echo "Cleanup"
docker rm -f ${DOCKER_CONTAINERS}
echo "Shutdown"
ANSIBLE_ROLES_PATH=.. ansible-playbook shutdown.yml
echo "Done"
exit 0
}
trap cleanup INT TERM EXIT
echo "Start containers"
for CONTAINER in ${DOCKER_CONTAINERS}; do
if [ "${ANSIBLE_TEST_COVERAGE:-}" == "" ]; then
docker run --rm --name ${CONTAINER} --detach "${IMAGE}" /bin/sh -c 'sleep 10m'
else
docker run --rm --name ${CONTAINER} --detach -v /tmp:/tmp "${IMAGE}" /bin/sh -c 'sleep 10m'
docker exec ${CONTAINER} pip3 install coverage
fi
echo ${CONTAINER}
done
cat > test_connection.inventory << EOF
[docker_api]
docker_api-no-pipelining ansible_pipelining=false
docker_api-pipelining ansible_pipelining=true
[docker_api:vars]
ansible_host=docker-connection-test-container${CONTAINER_SUFFIX}
ansible_connection=community.docker.docker_api
ansible_python_interpreter=/usr/local/bin/python3
EOF
echo "Run tests"
./runme-connection.sh "$@"
@@ -0,0 +1,10 @@
---
- hosts: localhost
connection: local
vars:
docker_skip_cleanup: yes
tasks:
- name: Setup docker
import_role:
name: setup_docker
@@ -0,0 +1,15 @@
---
- hosts: localhost
connection: local
vars:
docker_skip_cleanup: yes
tasks:
- name: Remove docker packages
action: "{{ ansible_facts.pkg_mgr }}"
args:
name:
- docker
- docker-ce
- docker-ce-cli
state: absent