Skip to content

Instantly share code, notes, and snippets.

@cvoltz
Last active May 31, 2022 21:46
Show Gist options
  • Save cvoltz/ddc14eddb55e59dcdc196092ec67f52d to your computer and use it in GitHub Desktop.
Save cvoltz/ddc14eddb55e59dcdc196092ec67f52d to your computer and use it in GitHub Desktop.
Running Ansible module tests in a container
# © Copyright 2022 Hewlett Packard Enterprise Development LP
# All rights reserved.
#
# Used to run the tests for the Ansible modules included as part of the
# installer. To use, run:
# cd ~/ece-installer/ansible/library
# docker-compose up --build
services:
test-mmmount:
build: ./
command:
bash -c '
source venv/bin/activate &&
source hacking/env-setup &&
python3.9 -m unittest test/units/modules/test_mmmount.py
'
volumes:
- type: bind
source: $PWD/tests/test_mmmount.py
target: /test/ansible/test/units/modules/test_mmmount.py
- type: bind
source: $PWD/tests/mmmount_stub.py
target: /test/ansible/test/units/modules/mmmount_stub.py
- type: bind
source: $PWD/mmmount.py
target: /test/ansible/lib/ansible/modules/mmmount.py
# © Copyright 2022 Hewlett Packard Enterprise Development LP
# All rights reserved.
#
# Creates the Docker image used for testing Ansible modules.
FROM rockylinux:8.5
RUN \
dnf module reset -y python36 && \
dnf module enable -y python39 && \
dnf install -y \
findutils \
git \
man-db \
python3-virtualenv \
python39
WORKDIR /test
RUN \
git clone https://github.com/ansible/ansible.git && \
cd ansible && \
virtualenv venv --python=/usr/bin/python3.9 && \
source venv/bin/activate && \
pip3 install -r requirements.txt && \
source hacking/env-setup
WORKDIR /test/ansible
@cvoltz
Copy link
Author

cvoltz commented May 31, 2022

Put both files into ansible/library and run docker-compose up --build from that directory to run the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment