summaryrefslogtreecommitdiffstats
path: root/tests/test_vdkr.py
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2026-01-05 14:24:37 +0000
committerBruce Ashfield <bruce.ashfield@gmail.com>2026-02-09 03:32:52 +0000
commitf9f8e294e5d870f28dd65f13ddb43c224be958fc (patch)
tree1da13e95dbb2fc3f5ef9388b0484b84d299b6961 /tests/test_vdkr.py
parent1165c61f5ab8ada644c7def03e991890c4d380ca (diff)
downloadmeta-virtualization-f9f8e294e5d870f28dd65f13ddb43c224be958fc.tar.gz
tests: add port forwarding test for vdkr
Add TestPortForwarding class with test_port_forward_nginx that: - Starts memres with port forwarding (-p 8080:80) - Runs nginx with --network=host - Verifies accessibility from host via curl Also adds port_forwards parameter to memres_start() in both VdkrRunner and VpdmnRunner helper classes. Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'tests/test_vdkr.py')
-rw-r--r--tests/test_vdkr.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/test_vdkr.py b/tests/test_vdkr.py
index 07715a66..6ce19036 100644
--- a/tests/test_vdkr.py
+++ b/tests/test_vdkr.py
@@ -76,6 +76,66 @@ class TestMemresBasic:
76 assert vdkr.is_memres_running() 76 assert vdkr.is_memres_running()
77 77
78 78
79class TestPortForwarding:
80 """Test port forwarding with memres.
81
82 Port forwarding allows access to services running in containers from the host.
83 Containers must use --network=host because Docker bridge networking is not
84 available inside the QEMU VM.
85 """
86
87 @pytest.mark.network
88 @pytest.mark.slow
89 def test_port_forward_nginx(self, vdkr):
90 """Test port forwarding with nginx.
91
92 This test:
93 1. Starts memres with port forward 8080:80
94 2. Runs nginx with --network=host
95 3. Verifies nginx is accessible from host via curl
96 """
97 import subprocess
98 import time
99
100 # Stop any running memres first
101 vdkr.memres_stop()
102
103 # Start memres with port forwarding
104 result = vdkr.memres_start(timeout=180, port_forwards=["8080:80"])
105 assert result.returncode == 0, f"memres start failed: {result.stderr}"
106
107 try:
108 # Pull nginx:alpine if not present
109 vdkr.run("pull", "nginx:alpine", timeout=300)
110
111 # Run nginx with host networking
112 result = vdkr.run("run", "-d", "--rm", "--network=host", "nginx:alpine", timeout=60)
113 assert result.returncode == 0, f"nginx run failed: {result.stderr}"
114
115 # Give nginx time to start
116 time.sleep(3)
117
118 # Test access from host
119 curl_result = subprocess.run(
120 ["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}", "http://localhost:8080"],
121 capture_output=True,
122 text=True,
123 timeout=10
124 )
125 assert curl_result.stdout == "200", f"Expected HTTP 200, got {curl_result.stdout}"
126
127 finally:
128 # Clean up: stop all containers
129 vdkr.run("ps", "-q", check=False)
130 ps_result = vdkr.run("ps", "-q", check=False)
131 if ps_result.stdout.strip():
132 for container_id in ps_result.stdout.strip().split('\n'):
133 vdkr.run("stop", container_id, timeout=10, check=False)
134
135 # Stop memres
136 vdkr.memres_stop()
137
138
79class TestImages: 139class TestImages:
80 """Test image management commands.""" 140 """Test image management commands."""
81 141