Files
infix/test/case/infix_containers/container_phys/test.py
T
Joachim Wiberg fc7e1d0745 test/case/infix_containers: extend retry for containers
For a heavily loaded system, 10 seconds/retries is not enough time to
expect containers to have started up.  Particularly after the changes
done recently to do prune before and after a container is started.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-09-02 10:53:49 +02:00

94 lines
3.0 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Container with physical interface
Verify connectivity with a simple web server container that's been
given a physical interface instead of an end of a VETH pair.
"""
import infamy
from infamy.util import until, to_binary
with infamy.Test() as test:
NAME = "web-phys"
DUTIP = "10.0.0.2"
OURIP = "10.0.0.1"
MESG = "Kilroy was here"
BODY = f"<html><body><p>{MESG}</p></body></html>"
URL = f"http://{DUTIP}:91/index.html"
with test.step("Set up topology and attach to target DUT"):
env = infamy.Env()
target = env.attach("target", "mgmt")
if not target.has_model("infix-containers"):
test.skip()
with test.step("Create httpd container from bundled OCI image"):
_, ifname = env.ltop.xlate("target", "data")
target.put_config_dict("ietf-interfaces", {
"interfaces": {
"interface": [{
"name": f"{ifname}",
"ipv4": {
"address": [{
"ip": f"{DUTIP}",
"prefix-length": 24
}]
},
"container-network": {}
}]
}
})
target.put_config_dict("infix-containers", {
"containers": {
"container": [{
"name": f"{NAME}",
"image": f"oci-archive:{infamy.Container.HTTPD_IMAGE}",
"command": "/usr/sbin/httpd -f -v -p 91",
"network": {
"interface": [
{"name": f"{ifname}"}
]
}
}]
}
})
with test.step("Verify container has started"):
c = infamy.Container(target)
until(lambda: c.running(NAME), attempts=60)
_, hport = env.ltop.xlate("host", "data")
url = infamy.Furl(URL)
with infamy.IsolatedMacVlan(hport) as ns:
ns.addip(OURIP)
with test.step("Verify host:data can ping 10.0.0.2"):
ns.must_reach(DUTIP)
with test.step("Verify container is reachable on http://10.0.0.2:91"):
until(lambda: url.nscheck(ns, "It works"), attempts=10)
with test.step("Add a content mount, overriding index.html"):
# Verify modifying a running container takes, issue #930
data = to_binary(BODY)
target.put_config_dict("infix-containers", {
"containers": {
"container": [{
"name": f"{NAME}",
"mount": [{
"name": "index.html",
"content": f"{data}",
"target": "/var/www/index.html"
}]
}]
}
})
with test.step("Verify server is restarted and returns new content"):
until(lambda: url.nscheck(ns, MESG), attempts=60)
test.succeed()