Skip to content

Commit 950a6ef

Browse files
committed
test/case/infix_containers: new test, verify environment
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 7f829cf commit 950a6ef

File tree

7 files changed

+228
-0
lines changed

7 files changed

+228
-0
lines changed

test/case/infix_containers/Readme.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
Verifies Infix Docker container support:
55

66
- Basic web server container running in host network mode
7+
- Container enable/disable functionality via configuration
8+
- Container environment variable configuration and access
79
- Common setup with a docker0 bridge, automatic VETH pairs to container(s)
810
- Connecting a container with a VETH pair to a standard Linux bridge
911
- Assigning a physical Ethernet interface to a container
@@ -16,6 +18,8 @@ include::container_basic/Readme.adoc[]
1618

1719
include::container_enabled/Readme.adoc[]
1820

21+
include::container_environment/Readme.adoc[]
22+
1923
include::container_bridge/Readme.adoc[]
2024

2125
include::container_phys/Readme.adoc[]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
container_environment.adoc
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
=== Container environment variables
2+
==== Description
3+
Verify that environment variables can be set in container configuration
4+
and are available inside the running container. Tests the 'env' list
5+
functionality by:
6+
7+
1. Creating a container with multiple environment variables
8+
2. Using a custom script to extract env vars and serve them via HTTP
9+
3. Fetching the served content to verify environment variables are set correctly
10+
11+
Uses the nftables container image with custom rc.local script.
12+
13+
==== Topology
14+
ifdef::topdoc[]
15+
image::{topdoc}../../test/case/infix_containers/container_environment/topology.svg[Container environment variables topology]
16+
endif::topdoc[]
17+
ifndef::topdoc[]
18+
ifdef::testgroup[]
19+
image::container_environment/topology.svg[Container environment variables topology]
20+
endif::testgroup[]
21+
ifndef::testgroup[]
22+
image::topology.svg[Container environment variables topology]
23+
endif::testgroup[]
24+
endif::topdoc[]
25+
==== Test sequence
26+
. Set up topology and attach to target DUT
27+
. Configure data interface with static IPv4
28+
. Create container with environment variables
29+
. Verify container has started
30+
. Verify environment variables are available via HTTP
31+
. Verify basic connectivity to data interface
32+
. Verify environment variables in HTTP response
33+
34+
35+
<<<
36+
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Container environment variables
4+
5+
Verify that environment variables can be set in container configuration
6+
and are available inside the running container. Tests the 'env' list
7+
functionality by:
8+
9+
1. Creating a container with multiple environment variables
10+
2. Using a custom script to extract env vars and serve them via HTTP
11+
3. Fetching the served content to verify environment variables are set correctly
12+
13+
Uses the nftables container image with custom rc.local script.
14+
"""
15+
import infamy
16+
from infamy.util import until, to_binary
17+
18+
19+
with infamy.Test() as test:
20+
NAME = "web-env"
21+
DUTIP = "10.0.0.2"
22+
OURIP = "10.0.0.1"
23+
24+
with test.step("Set up topology and attach to target DUT"):
25+
env = infamy.Env()
26+
target = env.attach("target", "mgmt")
27+
28+
if not target.has_model("infix-containers"):
29+
test.skip()
30+
31+
with test.step("Configure data interface with static IPv4"):
32+
_, ifname = env.ltop.xlate("target", "data")
33+
target.put_config_dict("ietf-interfaces", {
34+
"interfaces": {
35+
"interface": [{
36+
"name": f"{ifname}",
37+
"ipv4": {
38+
"address": [{
39+
"ip": f"{DUTIP}",
40+
"prefix-length": 24
41+
}]
42+
}
43+
}]
44+
}
45+
})
46+
47+
with test.step("Create container with environment variables"):
48+
script = to_binary("""#!/bin/sh
49+
# Create HTTP response with environment variables
50+
printf "HTTP/1.1 200 OK\\r\\n" > /var/www/response.txt
51+
printf "Content-Type: text/plain\\r\\n" >> /var/www/response.txt
52+
printf "Connection: close\\r\\n\\r\\n" >> /var/www/response.txt
53+
54+
# Add environment variables using printf to control encoding
55+
printf "TEST_VAR=\\"%s\\"\\n" "$TEST_VAR" >> /var/www/response.txt
56+
printf "APP_PORT=%s\\n" "$APP_PORT" >> /var/www/response.txt
57+
printf "DEBUG_MODE=\\"%s\\"\\n" "$DEBUG_MODE" >> /var/www/response.txt
58+
printf "PATH_WITH_SPACES=\\"%s\\"\\n" "$PATH_WITH_SPACES" >> /var/www/response.txt
59+
60+
while true; do
61+
nc -l -p 8080 < /var/www/response.txt 2>>/var/www/debug.log || sleep 1
62+
done
63+
""")
64+
65+
target.put_config_dict("infix-containers", {
66+
"containers": {
67+
"container": [
68+
{
69+
"name": f"{NAME}",
70+
"image": f"oci-archive:{infamy.Container.NFTABLES_IMAGE}",
71+
"env": [
72+
{"key": "TEST_VAR", "value": "hello-world"},
73+
{"key": "APP_PORT", "value": "8080"},
74+
{"key": "DEBUG_MODE", "value": "true"},
75+
{"key": "PATH_WITH_SPACES", "value": "/path with spaces/test"}
76+
],
77+
"network": {
78+
"host": True
79+
},
80+
"mount": [
81+
{
82+
"name": "rc.local",
83+
"content": script,
84+
"target": "/etc/rc.local",
85+
"mode": "0755"
86+
}
87+
],
88+
"volume": [{
89+
"name": "www",
90+
"target": "/var/www"
91+
}]
92+
}
93+
]
94+
}
95+
})
96+
97+
with test.step("Verify container has started"):
98+
c = infamy.Container(target)
99+
until(lambda: c.running(NAME), attempts=60)
100+
101+
with test.step("Verify environment variables are available via HTTP"):
102+
_, hport = env.ltop.xlate("host", "data")
103+
url = infamy.Furl(f"http://{DUTIP}:8080/env.html")
104+
105+
with infamy.IsolatedMacVlan(hport) as ns:
106+
ns.addip(OURIP)
107+
108+
with test.step("Verify basic connectivity to data interface"):
109+
ns.must_reach(DUTIP)
110+
111+
with test.step("Verify environment variables in HTTP response"):
112+
until(lambda: url.nscheck(ns, "TEST_VAR=\"hello-world\""), attempts=10)
113+
until(lambda: url.nscheck(ns, "APP_PORT=8080"), attempts=10)
114+
until(lambda: url.nscheck(ns, "DEBUG_MODE=\"true\""), attempts=10)
115+
until(lambda: url.nscheck(ns, "PATH_WITH_SPACES=\"/path with spaces/test\""), attempts=10)
116+
117+
test.succeed()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
graph "1x2" {
2+
layout="neato";
3+
overlap="false";
4+
esep="+80";
5+
6+
node [shape=record, fontname="DejaVu Sans Mono, Book"];
7+
edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"];
8+
9+
host [
10+
label="host | { <mgmt> mgmt | <data> data }",
11+
pos="0,12!",
12+
requires="controller",
13+
];
14+
15+
target [
16+
label="{ <mgmt> mgmt | <data> data } | target",
17+
pos="10,12!",
18+
19+
requires="infix",
20+
];
21+
22+
host:mgmt -- target:mgmt [requires="mgmt", color=lightgrey]
23+
host:data -- target:data [color=black]
24+
}
Lines changed: 42 additions & 0 deletions
Loading

test/case/infix_containers/infix_containers.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
- name: container_enabled
77
case: container_enabled/test.py
88

9+
# Disabled for v25.08, new/unstable
10+
# - name: container_environment
11+
# case: container_environment/test.py
12+
913
- name: container_bridge
1014
case: container_bridge/test.py
1115

0 commit comments

Comments
 (0)