Skip to content

Commit

Permalink
Merge pull request #384 from mikebonnet/podman
Browse files Browse the repository at this point in the history
enable testing with podman
  • Loading branch information
jasonrbriggs authored Jul 9, 2022
2 parents 9057959 + 937e301 commit 3558745
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
29 changes: 27 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PLATFORM := $(shell uname)
VERSION :=$(shell poetry version | sed 's/stomp.py\s*//g' | sed 's/\./, /g')
SHELL=/bin/bash
ARTEMIS_VERSION=2.22.0
TEST_CMD := $(shell podman network exists stomptest &> /dev/null && echo "podman unshare --rootless-netns poetry" || echo "poetry")

all: test install

Expand All @@ -28,11 +29,11 @@ install: updateversion test


test:
poetry run pytest tests/ --cov=stomp --log-cli-level=DEBUG -v -ra --full-trace --cov-report=html:../stomppy-docs/htmlcov/ --html=tmp/report.html
$(TEST_CMD) run pytest tests/ --cov=stomp --log-cli-level=DEBUG -v -ra --full-trace --cov-report=html:../stomppy-docs/htmlcov/ --html=tmp/report.html


testsingle:
poetry run pytest tests/${TEST} --log-cli-level=DEBUG -v -ra --full-trace
$(TEST_CMD) run pytest tests/${TEST} --log-cli-level=DEBUG -v -ra --full-trace


clean:
Expand Down Expand Up @@ -91,3 +92,27 @@ remove-docker:


docker: remove-docker docker-image run-docker


podman-image: docker/tmp/activemq-artemis-bin.tar.gz ssl-setup
podman build --build-arg ARTEMIS_VERSION=${ARTEMIS_VERSION} -t stomppy docker/


run-podman:
podman network create --ipv6 --subnet 172.17.0.0/24 --subnet fddf:aaaa:bbbb:cccc::/64 stomptest
podman run --network stomptest:ip=172.17.0.2 --add-host="my.example.com:127.0.0.1" --add-host="my.example.org:127.0.0.1" --add-host="my.example.net:127.0.0.1" -d -p 61613:61613 -p 62613:62613 -p 62614:62614 -p 63613:63613 -p 64613:64613 --name stomppy -it stomppy
podman ps
podman exec -it stomppy /bin/sh -c "/etc/init.d/activemq start"
podman exec -it stomppy /bin/sh -c "/etc/init.d/stompserver start"
podman exec -it stomppy /bin/sh -c "/etc/init.d/rabbitmq-server start"
podman exec -it stomppy /bin/sh -c "start-stop-daemon --start --background --exec /usr/sbin/haproxy -- -f /etc/haproxy/haproxy.cfg"
podman exec -it stomppy /bin/sh -c "testbroker/bin/artemis-service start"


remove-podman:
podman stop -i stomppy
podman rm -vi stomppy
podman network exists stomptest && podman network rm stomptest || :


podman: remove-podman podman-image run-podman
22 changes: 15 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,30 @@ stomp.py has been perfunctorily tested on:
- Apache ActiveMQ `Artemis`_ (`test_artemis.py <https://github.com/jasonrbriggs/stomp.py/blob/dev/tests/test_artemis.py>`_)
- `stompserver`_ (`test_stompserver.py <https://github.com/jasonrbriggs/stomp.py/blob/dev/tests/test_stompserver.py>`_)

For testing locally, you'll need to install docker. Once installed:
For testing locally, you'll need to install docker (or `podman`_). Once installed:

#. Install dependencies:
poetry install
#. Create the docker image:
make docker-image
``poetry install``
#. Create the docker (or podman) image:
``make docker-image`` (or ``make podman-image``)
#. Run the container:
make run-docker
``make run-docker`` (or ``make run-podman``)
#. Run stomp.py unit tests:
make test
``make test``
#. Cleanup the container afterwards if you don't need it any more:
make remove-docker
``make remove-docker`` (or ``make remove-podman``)

If you want to connect to the test services locally (other than from the included tests), you'll want to add test domain names to your hosts file like so:
| 172.17.0.2 my.example.com
| 172.17.0.2 my.example.org
| 172.17.0.2 my.example.net
If you're using `podman`_ and you want to access services via their private IP addresses, you'll want to run your commands with::

podman unshare --rootless-netns <command>

so that <command> has access to the private container network. Service ports are also exposed to the host and can be accessed directly.


.. _`STOMP`: http://stomp.github.io
.. _`STOMP v1.0`: http://stomp.github.io/stomp-specification-1.0.html
Expand Down Expand Up @@ -110,3 +116,5 @@ If you want to connect to the test services locally (other than from the include
.. _`buy me a coffee`: https://www.paypal.me/jasonrbriggs

.. _`semantic versioning`: https://semver.org/

.. _`podman`: https://podman.io/
7 changes: 6 additions & 1 deletion tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from configparser import RawConfigParser
import json
import os
import sys
import time
from subprocess import run, PIPE
Expand Down Expand Up @@ -53,6 +54,10 @@ def get_default_password():
def get_ipv6_host():
if config.has_option("ipv6", "host"):
host = config.get("ipv6", "host")
elif os.environ.get('CONTAINERS_RUNROOT'):
# Running under "podman unshare"
result = run(["podman", "inspect", "stomppy", "-f", "{{.NetworkSettings.Networks.stomptest.GlobalIPv6Address}}"], stdout=PIPE)
host = result.stdout.decode("utf-8").strip()
else:
result = run(["docker", "ps", "-f", "name=stomppy", "--format", "{{.ID}}"], stdout=PIPE)
container_id = result.stdout.decode("utf-8").rstrip()
Expand Down Expand Up @@ -248,4 +253,4 @@ def next_free_port(port=1024, max_port=65535):
return port
except OSError:
port += 1
raise IOError("no free ports")
raise IOError("no free ports")

0 comments on commit 3558745

Please sign in to comment.