From b725cc91aed9036d4e0bd6d5681f57687c4dd8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Fri, 30 Aug 2024 11:51:11 +0200 Subject: [PATCH 1/5] Bind WEB_SERVER container to ipv6 loopback too This also requires us to switch to python 3.11, as support for this got added in Python 3.8 (but Leap's python3 is 3.6 :-/) --- tests/images.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/images.py b/tests/images.py index bececf2..7980af0 100644 --- a/tests/images.py +++ b/tests/images.py @@ -15,8 +15,8 @@ WEB_SERVER = DerivedContainer( base=LEAP, containerfile=""" -RUN zypper -n in python3 curl && echo "Hello Green World!" > index.html -ENTRYPOINT ["/usr/bin/python3", "-m", "http.server"] +RUN zypper -n in python311 curl && echo "Hello Green World!" > index.html +ENTRYPOINT ["/usr/bin/python3.11", "-m", "http.server", "--bind", "::"] HEALTHCHECK --interval=5s --timeout=1s CMD curl --fail http://0.0.0.0:8000 EXPOSE 8000 """, From f91332a6b3afb7a2f5b542de5a3b9f9427b02e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Fri, 30 Aug 2024 11:52:15 +0200 Subject: [PATCH 2/5] Switch WEB_SERVER image_format to Docker, so that HEALTHCHECK works --- tests/images.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/images.py b/tests/images.py index 7980af0..a719453 100644 --- a/tests/images.py +++ b/tests/images.py @@ -20,6 +20,7 @@ HEALTHCHECK --interval=5s --timeout=1s CMD curl --fail http://0.0.0.0:8000 EXPOSE 8000 """, + image_format=ImageFormat.DOCKER, forwarded_ports=[PortForwarding(container_port=8000)], ) From a0621efaac07c25288078a4e0ba7aea92796438e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Fri, 30 Aug 2024 11:56:21 +0200 Subject: [PATCH 3/5] Use check_output instead of run_expect --- tests/test_port_forwarding.py | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/tests/test_port_forwarding.py b/tests/test_port_forwarding.py index 3db2136..22ca9cf 100644 --- a/tests/test_port_forwarding.py +++ b/tests/test_port_forwarding.py @@ -128,10 +128,9 @@ def test_port_forward_set_up(auto_container: ContainerData, host): ), "host port must be set" assert ( - host.run_expect( - [0], + host.check_output( f"{_CURL} localhost:{auto_container.forwarded_ports[0].host_port}", - ).stdout.strip() + ).strip() == "Hello Green World!" ) @@ -161,23 +160,16 @@ def test_multiple_open_ports(container: ContainerData, number: int, host): container.forwarded_ports[0].protocol == NetworkProtocol.TCP and container.forwarded_ports[0].container_port == 80 ) - assert ( - f"Test page {number}" - in host.run_expect( - [0], f"{_CURL} localhost:{container.forwarded_ports[0].host_port}" - ).stdout + assert f"Test page {number}" in host.check_output( + f"{_CURL} localhost:{container.forwarded_ports[0].host_port}" ) assert ( container.forwarded_ports[1].protocol == NetworkProtocol.TCP and container.forwarded_ports[1].container_port == 443 ) - assert ( - f"Test page {number}" - in host.run_expect( - [0], - f"curl --insecure https://localhost:{container.forwarded_ports[1].host_port}", - ).stdout + assert f"Test page {number}" in host.check_output( + f"curl --insecure https://localhost:{container.forwarded_ports[1].host_port}", ) @@ -216,10 +208,7 @@ def test_bind_to_address(addr: str, container: ContainerData, host) -> None: for host_addr in _ADDRESSES: cmd = f"{_CURL} http://{host_addr}:{container.forwarded_ports[0].host_port}" if addr == host_addr: - assert ( - host.run_expect([0], cmd).stdout.strip() - == "Hello Green World!" - ) + assert host.check_output(cmd).strip() == "Hello Green World!" else: assert host.run_expect([7], cmd) @@ -249,9 +238,7 @@ def test_container_bind_to_host_port( assert launcher.container_data.forwarded_ports[0].host_port == PORT assert ( - host.run_expect( - [0], f"{_CURL} http://localhost:{PORT}" - ).stdout.strip() + host.check_output(f"{_CURL} http://localhost:{PORT}").strip() == "Hello Green World!" ) @@ -281,8 +268,6 @@ def test_pod_bind_to_host_port( assert launcher.pod_data.forwarded_ports[0].host_port == PORT assert ( - host.run_expect( - [0], f"{_CURL} http://localhost:{PORT}" - ).stdout.strip() + host.check_output(f"{_CURL} http://localhost:{PORT}").strip() == "Hello Green World!" ) From a83379335880c88beaf178b4590c134751251552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Fri, 30 Aug 2024 12:06:17 +0200 Subject: [PATCH 4/5] Fix curl call to work with IPv6 addresses --- tests/test_port_forwarding.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_port_forwarding.py b/tests/test_port_forwarding.py index 22ca9cf..ffeb015 100644 --- a/tests/test_port_forwarding.py +++ b/tests/test_port_forwarding.py @@ -206,7 +206,10 @@ def test_multiple_open_ports(container: ContainerData, number: int, host): def test_bind_to_address(addr: str, container: ContainerData, host) -> None: """address""" for host_addr in _ADDRESSES: - cmd = f"{_CURL} http://{host_addr}:{container.forwarded_ports[0].host_port}" + # need to surround a ipv6 address in [] so that it can be distinguished + # from a port + formated_ip = f"[{host_addr}]" if ":" in host_addr else host_addr + cmd = f"{_CURL} http://{formated_ip}:{container.forwarded_ports[0].host_port}" if addr == host_addr: assert host.check_output(cmd).strip() == "Hello Green World!" else: From c7fd6668b30b563058dc04c3f59a3649e977dcb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Fri, 30 Aug 2024 12:11:52 +0200 Subject: [PATCH 5/5] nginx-test container: listen on IPv6 too --- tests/files/nginx.default.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/files/nginx.default.conf b/tests/files/nginx.default.conf index f394eab..b163551 100644 --- a/tests/files/nginx.default.conf +++ b/tests/files/nginx.default.conf @@ -3,6 +3,7 @@ ssl_certificate_key /root/certs/foobar.key; server { listen 80; + listen [::]:80; server_name localhost; location / {