Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
expected_xpath = [{'element_attrs': ["//interface/driver[@queues='${iface_queues}']"]}]
check_network_accessibility_after_mig = "yes"
host_iface =
remote_host_iface =
variants:
- linux_bridge:
bridge_type = "linux"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def check_multiqueue_in_guest(vm_session):
test.log.info("Checking multiqueue configuration in guest")
guest_iface_info = vm_session.cmd_output("ip --color=never l").strip()
iface_matches = re.findall(
r"^\d+: (\S+?)[@:].*state UP.*$", guest_iface_info, re.MULTILINE)
r"^\d+: (\S+?)[@:].*state UP.*$", guest_iface_info, re.MULTILINE
)
if not iface_matches:
test.fail("Failed to get network interface name in guest")
iface_name = iface_matches[0]
Expand All @@ -68,18 +69,19 @@ def setup_vm_interface():
Setup VM interface according to configuration
"""
vm_xml = VMXML.new_from_inactive_dumpxml(vm_name)
vm_xml.remove_all_device_by_type('interface')
vm_xml.remove_all_device_by_type("interface")
vm_xml.sync()
if interface_timing == "hotplug":
if not vm.is_alive():
vm.start()
iface = libvirt_vmxml.create_vm_device_by_type('interface', iface_dict)
virsh.attach_device(vm_name, iface.xml, flagstr="--config",
debug=True, ignore_status=False)
iface = libvirt_vmxml.create_vm_device_by_type("interface", iface_dict)
virsh.attach_device(
vm_name, iface.xml, flagstr="--config", debug=True, ignore_status=False
)
else:
libvirt_vmxml.modify_vm_device(
VMXML.new_from_inactive_dumpxml(vm_name), 'interface',
iface_dict)
VMXML.new_from_inactive_dumpxml(vm_name), "interface", iface_dict
)
vm.start()
vm.wait_for_serial_login().close()
test.log.debug("Guest xml:\n%s", VMXML.new_from_dumpxml(vm_name))
Expand All @@ -103,19 +105,24 @@ def setup_test():

if bridge_type == "linux":
utils_net.create_linux_bridge_tmux(bridge_name, iface_name=host_iface)

remote_host_iface = utils_net.get_default_gateway(
iface_name=True, session=remote_session, force_dhcp=False, json=True)
params.update({"remote_host_iface": remote_host_iface})
utils_net.create_linux_bridge_tmux(
bridge_name, iface_name=remote_host_iface, session=remote_session)
bridge_name, iface_name=remote_host_iface, session=remote_session
)

elif bridge_type == "ovs":
utils_net.create_ovs_bridge(ovs_bridge_name, ip_options='-color=never')

utils_net.create_ovs_bridge(ovs_bridge_name, session=remote_session,
ip_options='-color=never')
libvirt_network.create_or_del_network(network_dict, remote_args=remote_virsh_dargs)
utils_net.create_ovs_bridge(
ovs_bridge_name, ip_options="-color=never", iface_name=host_iface
)

utils_net.create_ovs_bridge(
ovs_bridge_name,
session=remote_session,
ip_options="-color=never",
iface_name=remote_host_iface,
)
libvirt_network.create_or_del_network(
network_dict, remote_args=remote_virsh_dargs
)
libvirt_network.create_or_del_network(network_dict)

if vm.is_alive():
Expand Down Expand Up @@ -143,15 +150,16 @@ def run_test():
vm_session_after_mig.cmd("dhclient -r; dhclient", timeout=120)

test.log.info("TEST_STEP: Testing guest ping to outside")
ips = {'outside_ip': outside_ip}
ips = {"outside_ip": outside_ip}
network_base.ping_check(params, ips, vm_session_after_mig)

test.log.info("TEST_STEP: Checking multiqueue")
check_multiqueue_in_guest(vm_session_after_mig)
virsh_obj = virsh.VirshPersistent(uri=dest_uri)
libvirt_vmxml.check_guest_xml_by_xpaths(
VMXML.new_from_dumpxml(vm_name, virsh_instance=virsh_obj),
expected_xpath)
expected_xpath,
)

if migrate_vm_back:
test.log.info("TEST_STEP: Migrating VM back to source host")
Expand All @@ -165,14 +173,25 @@ def teardown_test():
if bridge_type == "linux":
utils_net.delete_linux_bridge_tmux(bridge_name, iface_name=host_iface)
utils_net.delete_linux_bridge_tmux(
bridge_name, iface_name=params.get("remote_host_iface"),
session=remote_session)
bridge_name,
iface_name=params.get("remote_host_iface"),
session=remote_session,
)

elif bridge_type == "ovs":
utils_net.delete_ovs_bridge(ovs_bridge_name, ip_options='-color=never')
utils_net.delete_ovs_bridge(ovs_bridge_name, session=remote_session, ip_options='-color=never')

libvirt_network.create_or_del_network(network_dict, is_del=True, remote_args=remote_virsh_dargs)
utils_net.delete_ovs_bridge(
ovs_bridge_name, ip_options="-color=never", iface_name=host_iface
)
utils_net.delete_ovs_bridge(
ovs_bridge_name,
session=remote_session,
ip_options="-color=never",
iface_name=remote_host_iface,
)

libvirt_network.create_or_del_network(
network_dict, is_del=True, remote_args=remote_virsh_dargs
)
libvirt_network.create_or_del_network(network_dict, is_del=True)
migration_obj.cleanup_connection()

Expand All @@ -190,25 +209,38 @@ def teardown_test():
migrate_vm_back = params.get_boolean("migrate_vm_back")
cancel_migration = params.get_boolean("cancel_migration")

remote_virsh_dargs = {'remote_ip': server_ip, 'remote_user': server_user,
'remote_pwd': server_pwd, 'unprivileged_user': params.get("unprivileged_user"),
'ssh_remote_auth': params.get("ssh_remote_auth")}
remote_virsh_dargs = {
"remote_ip": server_ip,
"remote_user": server_user,
"remote_pwd": server_pwd,
"unprivileged_user": params.get("unprivileged_user"),
"ssh_remote_auth": params.get("ssh_remote_auth"),
}

src_uri = params.get("virsh_migrate_connect_uri")
dest_uri = params.get("virsh_migrate_desturi")
expected_xpath = eval(params.get("expected_xpath"))
iface_dict = eval(params.get("iface_dict", "{}"))
host_iface = params.get('host_iface')
host_iface = host_iface if host_iface else utils_net.get_default_gateway(
iface_name=True, force_dhcp=False, json=True)
host_iface = params.get("host_iface")
host_iface = (
host_iface
if host_iface
else utils_net.get_default_gateway(iface_name=True, force_dhcp=False, json=True)
)

vm_name = guest_os.get_vm(params)
vm = env.get_vm(vm_name)
new_xml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)

remote_session = aexpect.remote.remote_login("ssh", server_ip, "22",
server_user, server_pwd,
r'[$#%]')
remote_session = aexpect.remote.remote_login(
"ssh", server_ip, "22", server_user, server_pwd, r"[$#%]"
)
remote_host_iface = params.get("remote_host_iface")
if not remote_host_iface:
remote_host_iface = utils_net.get_default_gateway(
iface_name=True, session=remote_session, force_dhcp=False, json=True
)
params.update({"remote_host_iface": remote_host_iface})
Comment on lines +235 to +243
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Search for get_default_gateway function definition
ast-grep --pattern 'def get_default_gateway($$$)'

Repository: autotest/tp-libvirt

Length of output: 182


🏁 Script executed:

# Also search with rg for broader context
rg "def get_default_gateway" -A 15

Repository: autotest/tp-libvirt

Length of output: 182


🌐 Web query:

utils_net.get_default_gateway session parameter autotest libvirt

💡 Result:

There is no utils_net.get_default_gateway that takes a session. Use virttest.utils_net.get_host_default_gateway() (host default gateway — no session param). For guest-side lookups use virttest.utils_net.get_guest_ip_addr(session, mac_addr, ...), which does accept a session. [1][2]

Sources:

  • virttest.utils_net API (get_host_default_gateway, get_guest_ip_addr). [1]
  • virttest documentation index showing utils_net functions. [2]

Fix incorrect API call: get_default_gateway does not support the session parameter.

The code at lines 235-242 calls utils_net.get_default_gateway() with a session parameter for remote execution, but this function does not accept a session parameter. For remote gateway resolution, use utils_net.get_guest_ip_addr(session, mac_addr, ...) instead, which is designed to work with session objects. Alternatively, if you need the host default gateway on the remote machine, you may need to execute the appropriate command directly over the remote session.

🤖 Prompt for AI Agents
In
libvirt/tests/src/virtual_network/migrate/migrate_with_bridge_type_interface.py
around lines 235-243, the call to utils_net.get_default_gateway(...,
session=remote_session, ...) is invalid because get_default_gateway does not
accept a session; replace this with a remote-capable call: either call
utils_net.get_guest_ip_addr(remote_session, mac_addr, ...) (provide the
appropriate mac_addr from test params or obtained from the VM) to resolve the
remote address, or run the host command over remote_session to extract the
default gateway (e.g., parse `ip route` / `route -n`) and assign that result to
remote_host_iface; finally update params with the obtained value and remove the
invalid session argument from get_default_gateway usage.

migration_obj = base_steps.MigrationBase(test, vm, params)

try:
Expand Down