mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-30 04:33:00 +02:00
When a veth pair has one end in a container and the other in the host
namespace, removing it failed: the container end's teardown deleted the
whole pair, so the host end's own delete then failed ("Cannot find
device") and aborted the teardown, leaving the interface behind.
The host-namespace delete added for the both-ends-in-container case was
emitted for every container veth end. Restrict it to the primary end,
which for a host/container pair is the host end that already deletes the
pair itself.
Extend the container veth tests to remove the pair and verify it is gone,
covering both the single-end (regression) and both-ends teardown paths.
Fixes: #1546
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
129 lines
4.7 KiB
Python
Executable File
129 lines
4.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
r"""
|
|
Container with VETH pair
|
|
|
|
Verify connectivity with a simple web server container from behind a
|
|
regular bridge, a VETH pair connects the container to the bridge.
|
|
|
|
....
|
|
.-------------. .---------------. .--------.
|
|
| | mgmt |---------| mgmt | | | web- |
|
|
| host | data |---------| data | target | | server |
|
|
'-------------' '---------------' '--------'
|
|
| /
|
|
br0 /
|
|
`----- veth0 -----'
|
|
....
|
|
|
|
"""
|
|
import base64
|
|
import infamy
|
|
from infamy.util import until, curl
|
|
|
|
with infamy.Test() as test:
|
|
NAME = "web-br0-veth"
|
|
DUTIP = "10.0.0.2"
|
|
OURIP = "10.0.0.1"
|
|
URL = f"http://{DUTIP}:91/index.html"
|
|
MESG = "It works"
|
|
|
|
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 'web-br0-veth' container from bundled OCI image"):
|
|
_, ifname = env.ltop.xlate("target", "data")
|
|
target.put_config_dicts({
|
|
"ietf-interfaces": {
|
|
"interfaces": {
|
|
"interface": [
|
|
{
|
|
"name": f"{ifname}",
|
|
"infix-interfaces:bridge-port": {
|
|
"bridge": "br0"
|
|
}
|
|
},
|
|
{
|
|
"name": "br0",
|
|
"type": "infix-if-type:bridge"
|
|
},
|
|
{
|
|
"name": f"{NAME}",
|
|
"type": "infix-if-type:veth",
|
|
"infix-interfaces:veth": {
|
|
"peer": "veth0b"
|
|
},
|
|
"ipv4": {
|
|
"address": [{
|
|
"ip": f"{DUTIP}",
|
|
"prefix-length": 24
|
|
}]
|
|
},
|
|
"container-network": {}
|
|
},
|
|
{
|
|
"name": "veth0b",
|
|
"type": "infix-if-type:veth",
|
|
"infix-interfaces:veth": {
|
|
"peer": f"{NAME}"
|
|
},
|
|
"infix-interfaces:bridge-port": {
|
|
"bridge": "br0"
|
|
}
|
|
},
|
|
]
|
|
}
|
|
},
|
|
"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"{NAME}" }
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
})
|
|
|
|
with test.step("Verify container 'web-br0-veth' has started"):
|
|
c = infamy.Container(target)
|
|
until(lambda: c.running(NAME), attempts=60)
|
|
|
|
_, hport = env.ltop.xlate("host", "data")
|
|
|
|
with infamy.IsolatedMacVlan(hport) as ns:
|
|
ns.addip(OURIP)
|
|
with test.step("Verify basic DUT connectivity, host:data can ping DUT 10.0.0.2"):
|
|
ns.must_reach(DUTIP)
|
|
with test.step("Verify container 'web-br0-veth' is reachable on http://10.0.0.2:91"):
|
|
until(lambda: MESG in ns.call(lambda: curl(URL)), attempts=10)
|
|
|
|
with test.step("Remove container and VETH pair, verify clean teardown"):
|
|
# Regression test for #941/#1546: removing a veth pair with one end
|
|
# in a container must tear the pair down cleanly, leaving nothing
|
|
# behind in the host namespace.
|
|
target.delete_xpaths([
|
|
f"/infix-containers:containers/container[name='{NAME}']",
|
|
f"/ietf-interfaces:interfaces/interface[name='{NAME}']",
|
|
"/ietf-interfaces:interfaces/interface[name='veth0b']",
|
|
])
|
|
|
|
def removed():
|
|
ifaces = target.get_data("/ietf-interfaces:interfaces")["interfaces"]["interface"]
|
|
names = [iface["name"] for iface in ifaces]
|
|
return NAME not in names and "veth0b" not in names
|
|
|
|
until(removed, attempts=30)
|
|
|
|
test.succeed()
|