diff options
| -rw-r--r-- | tests/conftest.py | 2 | ||||
| -rw-r--r-- | tests/test_vdkr.py | 69 |
2 files changed, 67 insertions, 4 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 49958879..712700ee 100644 --- a/tests/conftest.py +++ b/tests/conftest.py | |||
| @@ -97,7 +97,7 @@ signal.signal(signal.SIGTERM, _signal_handler) | |||
| 97 | 97 | ||
| 98 | 98 | ||
| 99 | # Ports used by tests that need to be free | 99 | # Ports used by tests that need to be free |
| 100 | TEST_PORTS = [8080, 8081, 8888, 8001, 8002, 9999, 7777, 6666] | 100 | TEST_PORTS = [8080, 8081, 8082, 8888, 8001, 8002, 9999, 7777, 6666] |
| 101 | 101 | ||
| 102 | 102 | ||
| 103 | def _cleanup_orphan_qemu_on_ports(): | 103 | def _cleanup_orphan_qemu_on_ports(): |
diff --git a/tests/test_vdkr.py b/tests/test_vdkr.py index 33744107..bee261fb 100644 --- a/tests/test_vdkr.py +++ b/tests/test_vdkr.py | |||
| @@ -88,11 +88,11 @@ class TestPortForwarding: | |||
| 88 | @pytest.mark.network | 88 | @pytest.mark.network |
| 89 | @pytest.mark.slow | 89 | @pytest.mark.slow |
| 90 | def test_port_forward_nginx(self, vdkr): | 90 | def test_port_forward_nginx(self, vdkr): |
| 91 | """Test port forwarding with nginx. | 91 | """Test port forwarding with nginx using bridge networking. |
| 92 | 92 | ||
| 93 | This test: | 93 | This test: |
| 94 | 1. Starts memres with port forward 8080:80 | 94 | 1. Starts memres (no static port forwards needed) |
| 95 | 2. Runs nginx (--network=host is the default) | 95 | 2. Runs nginx with -p 8080:80 (Docker bridge + iptables NAT) |
| 96 | 3. Verifies nginx is accessible from host via curl | 96 | 3. Verifies nginx is accessible from host via curl |
| 97 | """ | 97 | """ |
| 98 | import subprocess | 98 | import subprocess |
| @@ -203,6 +203,69 @@ class TestPortForwarding: | |||
| 203 | vdkr.run("rm", "-f", "nginx2", check=False) | 203 | vdkr.run("rm", "-f", "nginx2", check=False) |
| 204 | vdkr.memres_stop() | 204 | vdkr.memres_stop() |
| 205 | 205 | ||
| 206 | @pytest.mark.network | ||
| 207 | @pytest.mark.slow | ||
| 208 | def test_network_host_backward_compat(self, vdkr): | ||
| 209 | """Test --network=host backward compatibility. | ||
| 210 | |||
| 211 | This tests that the old host networking mode still works when explicitly | ||
| 212 | specified. With --network=host, containers share the VM's network stack | ||
| 213 | (10.0.2.15), so static port forwarding at memres start is required. | ||
| 214 | |||
| 215 | Note: With bridge networking as default, static port forwards now map | ||
| 216 | host_port -> host_port on VM (Docker -p handles container port mapping). | ||
| 217 | For --network=host, use matching ports (e.g., 8082:8082) since the | ||
| 218 | container binds directly to VM ports. | ||
| 219 | """ | ||
| 220 | import subprocess | ||
| 221 | import time | ||
| 222 | |||
| 223 | # Stop any running memres first | ||
| 224 | vdkr.memres_stop() | ||
| 225 | |||
| 226 | # Start memres with static port forward (required for --network=host) | ||
| 227 | # Use matching ports since container binds directly to VM network | ||
| 228 | result = vdkr.memres_start(timeout=180, port_forwards=["8082:8082"]) | ||
| 229 | assert result.returncode == 0, f"memres start failed: {result.stderr}" | ||
| 230 | |||
| 231 | try: | ||
| 232 | # Use busybox httpd (configurable port) instead of nginx (fixed port 80) | ||
| 233 | vdkr.run("pull", "busybox:latest", timeout=300, check=False) | ||
| 234 | |||
| 235 | # Run httpd with --network=host on port 8082 | ||
| 236 | # With host networking, httpd binds directly to VM:8082 | ||
| 237 | # Static forward maps host:8082 -> VM:8082 | ||
| 238 | result = vdkr.run("run", "-d", "--rm", "--name", "httpd-host", | ||
| 239 | "--network=host", "busybox:latest", | ||
| 240 | "httpd", "-f", "-p", "8082", timeout=60) | ||
| 241 | assert result.returncode == 0, f"httpd run failed: {result.stderr}" | ||
| 242 | |||
| 243 | # Give httpd time to start | ||
| 244 | time.sleep(2) | ||
| 245 | |||
| 246 | # Test access from host via static port forward | ||
| 247 | # Note: busybox httpd returns 404 for /, but that's still a valid HTTP response | ||
| 248 | curl_result = subprocess.run( | ||
| 249 | ["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}", | ||
| 250 | "http://localhost:8082/"], | ||
| 251 | capture_output=True, | ||
| 252 | text=True, | ||
| 253 | timeout=10 | ||
| 254 | ) | ||
| 255 | # Accept 200, 404, or other HTTP codes - we just need connectivity | ||
| 256 | http_code = curl_result.stdout | ||
| 257 | assert http_code.isdigit() and int(http_code) > 0, \ | ||
| 258 | f"Expected HTTP response, got {http_code}" | ||
| 259 | |||
| 260 | finally: | ||
| 261 | # Clean up | ||
| 262 | ps_result = vdkr.run("ps", "-q", check=False) | ||
| 263 | if ps_result.stdout.strip(): | ||
| 264 | for container_id in ps_result.stdout.strip().split('\n'): | ||
| 265 | if container_id.strip(): | ||
| 266 | vdkr.run("stop", container_id, timeout=10, check=False) | ||
| 267 | vdkr.memres_stop() | ||
| 268 | |||
| 206 | 269 | ||
| 207 | class TestImages: | 270 | class TestImages: |
| 208 | """Test image management commands.""" | 271 | """Test image management commands.""" |
