Skip to content

Commit

Permalink
FIXUP use pytest_container from git main
Browse files Browse the repository at this point in the history
This avoids a few nasty workarounds. Let's keep this until 1.0 gets
released.
  • Loading branch information
martinpitt committed Mar 20, 2024
1 parent 3fd6ed6 commit d14efe9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ jobs:
- name: Install test dependencies
run: |
sudo apt-get update
sudo apt-get install -y make python3-pip python3-pytest
sudo apt-get install -y make python3-pip
# Ubuntu 22.04's pytest is too old for current pytest_container
sudo pip install pytest
# `pip install .[test]` does not work properly on Ubuntu 22.04
sudo pip install pytest_container
# use that when 1.0 is released: https://github.com/dcermak/pytest_container/issues/182
# sudo pip install pytest_container
# and in the meantime, install from git to avoid some nasty workarounds
sudo pip install git+https://github.com/dcermak/pytest_container
# HACK: Ubuntu 22.04 has podman 3.4, which isn't compatible with podman-remote 4 in our tasks container
# This PPA is a backport of podman 4.3 from Debian 12; drop this when moving `runs-on:` to ubuntu-24.04
Expand Down
28 changes: 4 additions & 24 deletions test/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import pytest
import yaml
from pytest_container import Container, PortForwarding
from pytest_container.container import BindMount, EntrypointSelection, VolumeFlag
from pytest_container.container import BindMount, VolumeFlag
from pytest_container.pod import Pod, PodData, PodLauncher
from testinfra.host import Host

Expand Down Expand Up @@ -128,9 +128,7 @@ def pod(config: Config, pytestconfig) -> PodData:
containers.append(Container(
url='quay.io/minio/minio',
extra_launch_args=[*COMMON_LAUNCH_ARGS, '--name', f'cockpituous-s3-{TEST_INSTANCE}'],
# that's what we want, but not in latest release yet: https://github.com/dcermak/pytest_container/issues/182
# extra_entrypoint_args=['server', '/data', '--console-address', ':9001'],
entry_point=EntrypointSelection.BASH,
extra_entrypoint_args=['server', '/data', '--console-address', ':9001'],
extra_environment_variables={
'MINIO_ROOT_USER': 'minioadmin',
'MINIO_ROOT_PASSWORD': 'minioadmin',
Expand Down Expand Up @@ -191,8 +189,7 @@ def pod(config: Config, pytestconfig) -> PodData:
containers.append(Container(
url=TASKS_IMAGE,
extra_launch_args=[*COMMON_LAUNCH_ARGS, '--name', f'cockpituous-webhook-{TEST_INSTANCE}'],
# that's what we want, but https://github.com/dcermak/pytest_container/issues/182
# extra_entrypoint_args=['webhook'],
extra_entrypoint_args=['webhook'],
volume_mounts=[
BindMount('/run/secrets/webhook', host_path=config.webhook, flags=[VolumeFlag.READ_ONLY]),
],
Expand All @@ -206,33 +203,16 @@ def pod(config: Config, pytestconfig) -> PodData:
pod_cockpituous = Pod(
containers=containers,
forwarded_ports=[
# BUG: host_port= would be nice to make S3 log URLs work; but it has no effect:
# https://github.com/dcermak/pytest_container/issues/190; but also, we want to keep the test
# parallel-friendly
# you can set host_port=9000 to make S3 log URLs work; but it breaks parallel tests
PortForwarding(container_port=9000), # S3
PortForwarding(container_port=9001), # minio console
]
)

# HACK: avoid always pulling images: https://github.com/dcermak/pytest_container/issues/187
# Make this compatible with the future upstream solution
if not bool(int(os.getenv('PULL_ALWAYS', '1'))):
for c in containers:
c._is_local = True

with PodLauncher(pod_cockpituous, rootdir=pytestconfig.rootpath,
pod_name=f'cockpituous-{TEST_INSTANCE}') as launcher:
launcher.launch_pod()

# run minio in lieu of extra_entrypoint_args
launcher.pod_data.container_data[1].connection.run_expect(
[0], '(nohup minio server /data --console-address :9001 </dev/null >/tmp/minio.log 2>&1 &)')

# run webhook in lieu of extra_entrypoint_args
if have_webhook_container:
launcher.pod_data.container_data[4].connection.run_expect(
[0], '(nohup webhook </dev/null >/tmp/webhook.log 2>&1 &)')

# wait until S3 started, create bucket
(s3user, s3key) = (config.tasks / 's3-keys/localhost.localdomain').read_text().strip().split()
launcher.pod_data.container_data[2].connection.run_expect([0], f'''
Expand Down

0 comments on commit d14efe9

Please sign in to comment.