mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
Let's drop the leading IETF or Infix prefixes from tests. Initially the idea was to mimnic the YANG models, but it's difficult to navigate and does not provide any real benefit to developers or end-users. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
76 lines
2.4 KiB
Python
Executable File
76 lines
2.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Container Basic
|
|
|
|
Verify that a simple web server container can be configured to run
|
|
with host networking, on port 80. Operation is verified using a
|
|
simple GET request for index.html and checking for a key phrase.
|
|
|
|
The RPC actions: stop + start, and restart are also verified.
|
|
"""
|
|
import infamy
|
|
from infamy.util import until, curl
|
|
|
|
|
|
def _verify(server):
|
|
# TODO: Should really use mDNS here....
|
|
url = f"http://[{server}]:91/index.html"
|
|
response = curl(url)
|
|
return response is not None and "It works" in response
|
|
|
|
|
|
with infamy.Test() as test:
|
|
NAME = "web"
|
|
|
|
with test.step("Set up topology and attach to target DUT"):
|
|
env = infamy.Env()
|
|
target = env.attach("target", "mgmt")
|
|
addr = target.get_mgmt_ip()
|
|
|
|
if not target.has_model("infix-containers"):
|
|
test.skip()
|
|
|
|
with test.step("Set hostname to 'container-host'"):
|
|
target.put_config_dict("ietf-system", {
|
|
"system": {
|
|
"hostname": "container-host"
|
|
}
|
|
})
|
|
|
|
with test.step("Create container 'web' from bundled OCI image"):
|
|
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": {
|
|
"host": True
|
|
}
|
|
}
|
|
]
|
|
}
|
|
})
|
|
|
|
with test.step("Verify container 'web' has started"):
|
|
c = infamy.Container(target)
|
|
until(lambda: c.running(NAME), attempts=60)
|
|
|
|
with test.step("Verify container 'web' is reachable on http://container-host.local:91"):
|
|
until(lambda: _verify(addr), attempts=10)
|
|
|
|
with test.step("Stop container 'web'"):
|
|
c = infamy.Container(target)
|
|
c.action(NAME, "stop")
|
|
|
|
with test.step("Verify container 'web' is stopped"):
|
|
until(lambda: not c.running(NAME), attempts=30)
|
|
|
|
with test.step("Restart container 'web'"):
|
|
c.action(NAME, "restart")
|
|
|
|
with test.step("Verify container 'web' is reachable on http://container-host.local:91"):
|
|
# Wait for it to restart and respond, or fail
|
|
until(lambda: _verify(addr), attempts=60)
|
|
test.succeed()
|