Skip to content

Commit 9d8e6bf

Browse files
committed
tests: Add integration test for resetting a net device
1 parent 6d80734 commit 9d8e6bf

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/integration_tests/functional/test_net.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,38 @@ def test_tap_offload(uvm_any):
127127
with attempt:
128128
ret = vm.ssh.check_output(f"sync; cat {out_filename}")
129129
assert ret.stdout == message, f"{ret.stdout=} {ret.stderr=}"
130+
131+
def test_reset(uvm_plain_any):
132+
"""
133+
Verify that we can reset a net device in the guest
134+
"""
135+
vm = uvm_plain_any
136+
vm.spawn()
137+
vm.basic_config()
138+
139+
# eth0/virtio1
140+
vm.add_net_iface()
141+
# eth1/virtio2
142+
vm.add_net_iface()
143+
guest_ip_eth1 = vm.iface["eth1"]["iface"].guest_ip
144+
145+
vm.start()
146+
147+
# Check eth1
148+
vm.ssh.check_output("ping -I eth1 192.168.0.1 -c 1 -W 1")
149+
150+
# Trigger reset of eth1 in the guest
151+
vm.ssh.check_output("echo virtio2 > /sys/bus/virtio/devices/virtio2/driver/unbind")
152+
153+
exitcode, _, _ = vm.ssh.run("ping -I eth1 192.168.0.1 -c 1 -W 1")
154+
assert exitcode != 0, "Ping should fail after resetting the net device"
155+
156+
# Bring eth1 back up
157+
vm.ssh.check_output(f"""
158+
echo virtio2 > /sys/bus/virtio/drivers/virtio_net/bind;
159+
ip addr add {guest_ip_eth1}/30 dev eth1;
160+
ip link set eth1 up;
161+
ip route add default via 192.168.0.1;
162+
""")
163+
164+
vm.ssh.check_output("ping -I eth1 192.168.0.1 -c 1 -W 1")

0 commit comments

Comments
 (0)