Skip to content

Commit bd7f6b9

Browse files
committed
Improve testing against distro and podman-next
1. Split upstream into distro/pnext test runs A new CI run targets tests that are exclusive for podman-next. /upstream plans are now split into /distro and /pnext to be explicit against which podman version is used in the tests. Also, python version used are now called base_python and all_python, to be more self explainatory. 2. Add pytest marker `pnext` to filter tests Tests that should run against podman-next are now skipped by default in tox runs. They can be enabled with --pnext and filtered in using `-m pnext`. These two options should be used together since `pnext` and `non-pnext` tests are thought to be incompatible. 3. Split `test_container_mounts` to test a breaking change and update docs The scenario `test_container_mounts` was split to demonstrates the usage of the marker against an upstream breaking change. CONTRIBUTING.md now reflects the new feature and explains how to use tox locally to leverage on this feature. 4. Add manual trigger on packit Since the tests cover a corner case and serve the purpose of testing unreleased features of libpod (which is slightly out of the scope of podman-py) the testing jobs are optional and should run for certain PRs only. The command to run the pnext tests is the following. /packit test --labels {pnext,podman_next} Fixes: containers#547 Signed-off-by: Nicola Sella <[email protected]>
1 parent c4aad1b commit bd7f6b9

File tree

7 files changed

+168
-25
lines changed

7 files changed

+168
-25
lines changed

.packit.yaml

+23-9
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,13 @@ jobs:
102102
dist_git_branches:
103103
- fedora-branched # rawhide updates are created automatically
104104

105+
105106
# Test linting on the codebase
106107
# This test might break based on the OS and lint used, so we follow fedora-latest as a reference
107108
- job: tests
108109
trigger: pull_request
109-
identifier: upstream-sanity
110-
tmt_plan: /upstream/sanity
110+
identifier: distro-sanity
111+
tmt_plan: /distro/sanity
111112
packages: [python-podman-fedora]
112113
targets:
113114
- fedora-latest-stable
@@ -118,7 +119,7 @@ jobs:
118119
- job: tests
119120
trigger: pull_request
120121
identifier: unittest-coverage
121-
tmt_plan: /upstream/unittest_coverage
122+
tmt_plan: /distro/unittest_coverage
122123
packages: [python-podman-fedora]
123124
targets:
124125
- fedora-latest-stable
@@ -130,30 +131,43 @@ jobs:
130131
# run all tests for all python versions on all fedoras
131132
- job: tests
132133
trigger: pull_request
133-
identifier: upstream-all-fedora
134-
tmt_plan: /upstream/all
134+
identifier: distro-fedora-all
135+
tmt_plan: /distro/all_python
135136
packages: [python-podman-fedora]
136137
targets:
137138
- fedora-all
139+
140+
# run tests for the rawhide python version using podman-next packages
141+
- job: tests
142+
trigger: pull_request
143+
identifier: podman-next-fedora-base
144+
tmt_plan: /pnext/base_python
145+
packages: [python-podman-fedora]
146+
targets:
147+
- fedora-rawhide
138148
tf_extra_params:
139149
environments:
140150
- artifacts:
141151
- type: repository-file
142152
id: https://copr.fedorainfracloud.org/coprs/rhcontainerbot/podman-next/repo/fedora-$releasever/rhcontainerbot-podman-next-fedora-$releasever.repo
153+
# TODO: uncomment after pass # manual_trigger: true
154+
labels:
155+
- pnext
156+
- podman-next
143157

144158
- job: tests
145159
trigger: pull_request
146-
identifier: upstream-base-centos
147-
tmt_plan: /upstream/base
160+
identifier: distro-centos-base
161+
tmt_plan: /distro/base_python
148162
packages: [python-podman-centos]
149163
targets:
150164
- centos-stream-9
151165
- centos-stream-10
152166

153167
- job: tests
154168
trigger: pull_request
155-
identifier: upstream-base-rhel
156-
tmt_plan: /upstream/base
169+
identifier: distro-rhel-base
170+
tmt_plan: /distro/base_python
157171
packages: [python-podman-rhel]
158172
targets:
159173
- epel-9

CONTRIBUTING.md

+39
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,45 @@ pip install tox
4545
tox -e coverage
4646
```
4747

48+
#### Advanced testing
49+
50+
Always prefer to run `tox` directly, even when you want to run a specific test or scenario.
51+
Instead of running `pytest` directly, you should run:
52+
53+
```
54+
tox -e py -- podman/tests/integration/test_container_create.py -k test_container_directory_volume_mount
55+
```
56+
57+
If you'd like to test against a specific `tox` environment you can do:
58+
59+
```
60+
tox -e py12 -- podman/tests/integration/test_container_create.py -k test_container_directory_volume_mount
61+
```
62+
63+
Pass pytest options after `--`.
64+
65+
#### Testing future features
66+
67+
Since `podman-py` follows stable releases of `podman`, tests are thought to be run against
68+
libpod's versions that are commonly installed in the distributions. Tests can be versioned,
69+
but preferably they should not. Occasionally, upstream can have diverge and have features that
70+
are not included in a specific version of libpod, or that will be included eventually.
71+
To run a test against such changes, you need to have
72+
[podman-next](https://copr.fedorainfracloud.org/coprs/rhcontainerbot/podman-next) installed.
73+
Then, you need to mark the test as `@pytest.mark.pnext`. Marked tests willbe excluded from the
74+
runs, unless you pass `--pnext` as a cli option.
75+
Preferably, this should be a rare case and it's better to use this marker as a temporary solution,
76+
with the goal of removing the marker within few PRs.
77+
78+
To run these tests use:
79+
80+
```
81+
tox -e py -- --pnext -m pnext podman/tests/integration/test_container_create.py -k test_container_mounts_without_rw_as_default
82+
```
83+
84+
The option `--pnext` **enables** the tests with the `pnext` pytest marker, and `-m pnext` will run
85+
the marked tests **only**.
86+
4887
## Submitting changes
4988

5089
- Create a github pull request (PR)

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ tests: tox
2626
# see tox.ini for environment variable settings
2727
$(PYTHON) -m tox -e coverage,py39,py310,py311,py312,py313
2828

29+
.PHONY: tests-ci-base-python-podman-next
30+
tests-ci-base-python-podman-next:
31+
$(PYTHON) -m tox -e coverage,py -- --pnext -m -pnext
32+
2933
.PHONY: tests-ci-base-python
3034
tests-ci-base-python:
3135
$(PYTHON) -m tox -e coverage,py

plans/main.fmf

+35-16
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ prepare:
1212
- python3-pip
1313
- podman
1414

15-
- name: enable rhcontainerbot/podman-next update podman
16-
when: initiator == packit
17-
how: shell
18-
script: |
19-
COPR_REPO_FILE="/etc/yum.repos.d/*podman-next*.repo"
20-
if compgen -G $COPR_REPO_FILE > /dev/null; then
21-
sed -i -n '/^priority=/!p;$apriority=1' $COPR_REPO_FILE
22-
fi
23-
dnf -y upgrade --allowerasing
24-
2515
- name: pip dependencies
2616
how: shell
2717
script:
@@ -34,20 +24,46 @@ prepare:
3424
- cp /root/.ssh/authorized_keys /root/.ssh/authorized_keys%
3525
- cat /root/.ssh/id_ecdsa.pub >>/root/.ssh/authorized_keys
3626

37-
/upstream:
27+
# Run tests agains Podman Next builds.
28+
# These tests should NOT overlap with the ones who run in the distro plan and should only include
29+
# tests against upcoming features or upstream tests that we need to run for reasons.
30+
/pnext:
31+
prepare+:
32+
- name: enable rhcontainerbot/podman-next update podman
33+
when: initiator == packit
34+
how: shell
35+
script: |
36+
COPR_REPO_FILE="/etc/yum.repos.d/*podman-next*.repo"
37+
if compgen -G $COPR_REPO_FILE > /dev/null; then
38+
sed -i -n '/^priority=/!p;$apriority=1' $COPR_REPO_FILE
39+
fi
40+
dnf -y upgrade --allowerasing
41+
42+
/base_python:
43+
summary: Run Tests Upstream PRs for base Python
44+
discover+:
45+
filter: tag:pnext
46+
47+
adjust+:
48+
enabled: false
49+
when: initiator is not defined or initiator != packit
50+
51+
52+
# Run tests against Podman buids installed from the distribution.
53+
/distro:
3854
/sanity:
3955
summary: Run Sanity and Coverage checks on Python Podman
4056
discover+:
4157
# we want to change this to tag:stable once all the coverage tests are fixed
4258
filter: tag:lint
4359

44-
/base:
45-
summary: Run Python Podman Tests on Upstream PRs for base Python
60+
/base_python:
61+
summary: Run Tests Upstream for base Python
4662
discover+:
4763
filter: tag:base
4864

49-
/all:
50-
summary: Run Python Podman Tests on Upstream PRs for all Python versions
65+
/all_python:
66+
summary: Run Tests Upstream PRs for all Python versions
5167
prepare+:
5268
- name: install all python versions
5369
how: install
@@ -60,6 +76,7 @@ prepare:
6076
discover+:
6177
filter: tag:matrix
6278

79+
# TODO: replace with /coverage and include integration tests coverage
6380
/unittest_coverage:
6481
summary: Run Unit test coverage
6582
discover+:
@@ -69,9 +86,11 @@ prepare:
6986
enabled: false
7087
when: initiator is not defined or initiator != packit
7188

89+
# Run tests against downstream Podman. These tests should be the all_python only since the sanity
90+
# of code is tested in the distro environment
7291
/downstream:
7392
/all:
74-
summary: Run Python Podman Tests on bodhi / errata and dist-git PRs
93+
summary: Run Tests on bodhi / errata and dist-git PRs
7594
prepare+:
7695
- name: install all python versions
7796
how: install

podman/tests/conftest.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
3+
4+
def pytest_addoption(parser):
5+
parser.addoption(
6+
"--pnext", action="store_true", default=False, help="run tests against podman_next copr"
7+
)
8+
9+
10+
def pytest_configure(config):
11+
config.addinivalue_line("markers", "pnext: mark test as run against podman_next")
12+
13+
14+
def pytest_collection_modifyitems(config, items):
15+
if config.getoption("--pnext"):
16+
# --pnext given in cli: run tests marked as pnext
17+
return
18+
podman_next = pytest.mark.skip(reason="need --pnext option to run")
19+
for item in items:
20+
if "pnext" in item.keywords:
21+
item.add_marker(podman_next)

podman/tests/integration/test_container_create.py

+40
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import unittest
22

3+
import pytest
34
import re
45

56
import podman.tests.integration.base as base
@@ -311,6 +312,45 @@ def test_container_mounts(self):
311312

312313
self.assertEqual(container.attrs.get('State', dict()).get('ExitCode', 256), 0)
313314

315+
@pytest.mark.pnext
316+
# repeat this test against this upstream change
317+
# https://github.com/containers/podman/pull/25942
318+
def test_container_mounts_without_rw_as_default(self):
319+
"""Test passing mounts"""
320+
with self.subTest("Check bind mount"):
321+
mount = {
322+
"type": "bind",
323+
"source": "/etc/hosts",
324+
"target": "/test",
325+
"read_only": True,
326+
"relabel": "Z",
327+
}
328+
container = self.client.containers.create(
329+
self.alpine_image, command=["cat", "/test"], mounts=[mount]
330+
)
331+
self.containers.append(container)
332+
self.assertIn(
333+
f"{mount['source']}:{mount['target']}:ro,Z,rprivate,rbind",
334+
container.attrs.get('HostConfig', {}).get('Binds', list()),
335+
)
336+
337+
# check if container can be started and exits with EC == 0
338+
container.start()
339+
container.wait()
340+
341+
self.assertEqual(container.attrs.get('State', dict()).get('ExitCode', 256), 0)
342+
343+
with self.subTest("Check tmpfs mount"):
344+
mount = {"type": "tmpfs", "source": "tmpfs", "target": "/test", "size": "456k"}
345+
container = self.client.containers.create(
346+
self.alpine_image, command=["df", "-h"], mounts=[mount]
347+
)
348+
self.containers.append(container)
349+
self.assertEqual(
350+
container.attrs.get('HostConfig', {}).get('Tmpfs', {}).get(mount['target']),
351+
f"size={mount['size']},rprivate,nosuid,nodev,tmpcopyup",
352+
)
353+
314354
def test_container_devices(self):
315355
devices = ["/dev/null:/dev/foo", "/dev/zero:/dev/bar"]
316356
container = self.client.containers.create(

tests/main.fmf

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ require:
2424
test: cd .. && make tests-ci-base-python
2525
duration: 10m
2626

27+
/base_python_pnext:
28+
tag: [ pnext ]
29+
summary: Run all tests on the base python version and podman-next
30+
test: cd .. && make tests-ci-base-python-podman-next
31+
duration: 5m
32+
2733
/all_python:
2834
tag: [ matrix ]
2935
summary: Run all tests for all ptyhon versions available

0 commit comments

Comments
 (0)