Skip to content

Commit de177ec

Browse files
committed
test: add container suite cleanup case
Persistent podman storage on test hardware can hold containers from earlier deployments or test runs, completely unrelated to the current suite. Those stale containers still appear in operational data. Add a new 'Container Cleanup' case as the first entry of the container suite. It SSHes into the target and wipes all containers and volumes via 'podman rm -af' / 'podman volume prune -af', then verifies 'podman ps -aq' is empty, guaranteeing a known clean state before the rest of the suite runs. Signed-off-by: Richard Alpe <richard@bit42.se>
1 parent e8e8fab commit de177ec

9 files changed

Lines changed: 105 additions & 6 deletions

File tree

test/case/containers/Readme.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
Tests verifying link:https://opencontainers.org/[OCI container] support:
55

6+
- Cleanup of any stale containers/volumes before the suite runs
67
- Basic web server container running in host network mode
78
- Container enable/disable functionality via configuration
89
- Container environment variable configuration and access
@@ -13,6 +14,10 @@ Tests verifying link:https://opencontainers.org/[OCI container] support:
1314
- Container upgrade using RPC with cleanup of old image
1415
- Firewall container running in host network mode with full privileges
1516

17+
include::cleanup/Readme.adoc[]
18+
19+
<<<
20+
1621
include::basic/Readme.adoc[]
1722

1823
<<<

test/case/containers/all.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
---
22

3+
- name: Container Cleanup
4+
case: cleanup/test.py
5+
36
- name: Container Basic
47
case: basic/test.py
58

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.adoc
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== Container Cleanup
2+
3+
ifdef::topdoc[:imagesdir: {topdoc}../../test/case/containers/cleanup]
4+
5+
==== Description
6+
7+
Remove all containers and volumes from the target before running other
8+
container tests. Persistent podman storage on test hardware can hold
9+
stale containers from earlier deployments or test runs, which then
10+
appear in operational data and may trip YANG validation -- making
11+
unrelated tests look flaky.
12+
13+
This test runs first in the container suite to guarantee a known-empty
14+
podman state.
15+
16+
==== Topology
17+
18+
image::topology.svg[Container Cleanup topology, align=center, scaledwidth=75%]
19+
20+
==== Sequence
21+
22+
. Set up topology and attach to target DUT
23+
. Remove all containers and volumes via podman
24+
. Verify no containers remain
25+
26+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
"""Container Cleanup
3+
4+
Remove all containers and volumes from the target before running other
5+
container tests. Persistent podman storage on test hardware can hold
6+
stale containers from earlier deployments or test runs, which then
7+
appear in operational data and may trip YANG validation -- making
8+
unrelated tests look flaky.
9+
10+
This test runs first in the container suite to guarantee a known-empty
11+
podman state.
12+
"""
13+
import infamy
14+
import infamy.ssh as ssh
15+
16+
17+
with infamy.Test() as test:
18+
with test.step("Set up topology and attach to target DUT"):
19+
env = infamy.Env()
20+
target = env.attach("target", "mgmt")
21+
tgtssh = env.attach("target", "mgmt", "ssh")
22+
23+
if not target.has_model("infix-containers"):
24+
test.skip()
25+
26+
with test.step("Remove all containers and volumes via podman"):
27+
tgtssh.runsh("sudo podman rm -af")
28+
tgtssh.runsh("sudo podman volume prune -af")
29+
30+
with test.step("Verify no containers remain"):
31+
out = tgtssh.runsh("sudo podman ps -aq").stdout.strip()
32+
if out:
33+
print(f"Containers still present: {out!r}")
34+
test.fail()
35+
36+
test.succeed()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../infamy/topologies/1x1.dot
Lines changed: 33 additions & 0 deletions
Loading

test/case/statd/containers/infix-containers.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"running": true,
1010
"status": "Up About a minute",
1111
"cmdline": "/usr/bin/tini -- /usr/sbin/httpd -f -v",
12-
"command": "/usr/sbin/httpd -f -v",
1312
"network": {
1413
"interface": [
1514
{
@@ -30,7 +29,6 @@
3029
"running": true,
3130
"status": "Up About a minute",
3231
"cmdline": "/usr/bin/tini -- /usr/sbin/httpd -f -v -p 91",
33-
"command": "/usr/sbin/httpd -f -v -p 91",
3432
"network": {
3533
"interface": [
3634
{
@@ -53,7 +51,6 @@
5351
"running": true,
5452
"status": "Up About a minute",
5553
"cmdline": "/usr/bin/tini -- /usr/sbin/nft-helper /etc/nftables.conf",
56-
"command": "/usr/sbin/nft-helper /etc/nftables.conf",
5754
"network": {
5855
"host": true
5956
}

test/case/statd/containers/operational.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,6 @@
11881188
"container": [
11891189
{
11901190
"cmdline": "/usr/bin/tini -- /usr/sbin/httpd -f -v",
1191-
"command": "/usr/sbin/httpd -f -v",
11921191
"id": "78d28082c2e5d494c82aa181c95118ce498e25930ad9e288ba010257ca336378",
11931192
"image": "localhost/curios-httpd-oci-amd64-v24.11.0:latest",
11941193
"image-id": "d6930d60a73be9980f8e19b4b4f63586a6d3492178e20bea962e4e9b8c654033",
@@ -1209,7 +1208,6 @@
12091208
},
12101209
{
12111210
"cmdline": "/usr/bin/tini -- /usr/sbin/httpd -f -v -p 91",
1212-
"command": "/usr/sbin/httpd -f -v -p 91",
12131211
"id": "3451cfceca4eee1091c1dfedece2faee99bc8a729e781799d9c0b4368a31d86d",
12141212
"image": "localhost/curios-httpd-oci-amd64-v24.11.0:latest",
12151213
"image-id": "d6930d60a73be9980f8e19b4b4f63586a6d3492178e20bea962e4e9b8c654033",
@@ -1232,7 +1230,6 @@
12321230
},
12331231
{
12341232
"cmdline": "/usr/bin/tini -- /usr/sbin/nft-helper /etc/nftables.conf",
1235-
"command": "/usr/sbin/nft-helper /etc/nftables.conf",
12361233
"id": "4e7c3daeba15546e7640014b9ee46e389737ed36583e5cb2f8b75a07a82e8523",
12371234
"image": "localhost/curios-nftables-oci-amd64-v24.11.0:latest",
12381235
"image-id": "7a3cc502436250357a6664100a600f306334b4d7203890b85b7ea9b8da6b5665",

0 commit comments

Comments
 (0)