From 5836e6f07f251915aedf0e5a18a09b44fe1e8abd Mon Sep 17 00:00:00 2001 From: Haijiao Zhao Date: Wed, 23 Oct 2024 06:49:50 -0400 Subject: [PATCH] Update case of connectivity check of ethernet interface - VIRT-296218 - [ethernet] Check connectivity for ethernet type interface with managed='no' Signed-off-by: Haijiao Zhao --- .../connectivity_check_ethernet_interface.cfg | 16 +++++- .../connectivity_check_ethernet_interface.py | 49 ++++++++++++++++++- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/libvirt/tests/cfg/virtual_network/connectivity/connectivity_check_ethernet_interface.cfg b/libvirt/tests/cfg/virtual_network/connectivity/connectivity_check_ethernet_interface.cfg index ff057c59d0..9602523eb8 100644 --- a/libvirt/tests/cfg/virtual_network/connectivity/connectivity_check_ethernet_interface.cfg +++ b/libvirt/tests/cfg/virtual_network/connectivity/connectivity_check_ethernet_interface.cfg @@ -4,11 +4,11 @@ timeout = 240 outside_ip = 'www.redhat.com' host_iface = + extra_attrs = {} variants user_type: - non_root_user: test_user = USER.EXAMPLE test_passwd = PASSWORD.EXAMPLE - user_id = unpr_vm_name = UNPRIVILEGED_VM.EXAMPLE variants: - positive_test: @@ -24,14 +24,26 @@ tap_mtu = 1400 iface_mtu = 1200 mtu_attrs = {'mtu': {'size': ${iface_mtu}}} + - smaller_mtu_multi_ifaces: + only two_ifaces + tap_mtu = 1400 + iface_mtu = 1200 + iface_mtu_2 = 1150 + mtu_attrs = {'mtu': {'size': ${iface_mtu}}} variants tap_type: - tap: vm_ping_outside = pass vm_ping_host_public = pass + variants iface_amount: + - one_iface: + - two_ifaces: + only smaller_mtu_multi_ifaces + extra_attrs = {'rom': {'enabled': 'no'}} + iface_attrs_2 = {'type_name': 'ethernet', 'target': {'dev': tap_name_2, 'managed': 'no'}, 'model': 'virtio', 'mtu': {'size': '${iface_mtu_2}'}, 'driver': {'driver_attr': {'name': 'vhost'}}, 'rom': {'enabled': 'no'}} - macvtap: vm_ping_outside = pass vm_ping_host_public = fail - iface_attrs = {'target': {'dev': tap_name, 'managed': 'no'}, 'model': 'virtio', 'type_name': 'ethernet', **${mtu_attrs}} + iface_attrs = {'target': {'dev': tap_name, 'managed': 'no'}, 'model': 'virtio', 'type_name': 'ethernet', **${mtu_attrs}, **${extra_attrs}} - negative_test: status_error = yes variants: diff --git a/libvirt/tests/src/virtual_network/connectivity/connectivity_check_ethernet_interface.py b/libvirt/tests/src/virtual_network/connectivity/connectivity_check_ethernet_interface.py index 6b5e683fdd..7f0d5b5fd4 100644 --- a/libvirt/tests/src/virtual_network/connectivity/connectivity_check_ethernet_interface.py +++ b/libvirt/tests/src/virtual_network/connectivity/connectivity_check_ethernet_interface.py @@ -1,6 +1,7 @@ import logging import aexpect +from avocado.utils import process from virttest import libvirt_version from virttest import remote from virttest import utils_misc @@ -49,9 +50,13 @@ def run(test, params, env): bridge_name = 'br_' + rand_id tap_type = params.get('tap_type', '') tap_name = tap_type + '_' + rand_id + tap_name_2 = tap_name + '_2' tap_mtu = params.get('tap_mtu') iface_mtu = params.get('iface_mtu') + iface_mtu_2 = params.get('iface_mtu_2') iface_attrs = eval(params.get('iface_attrs')) + iface_attrs_2 = eval(params.get('iface_attrs_2')) + iface_amount = params.get('iface_amount') outside_ip = params.get('outside_ip') host_iface = params.get('host_iface') host_iface = host_iface if host_iface else utils_net.get_default_gateway( @@ -70,11 +75,17 @@ def run(test, params, env): if tap_type == 'tap': utils_net.create_linux_bridge_tmux(bridge_name, host_iface) network_base.create_tap(tap_name, bridge_name, test_user) + if iface_amount == 'two_ifaces': + network_base.create_tap(tap_name_2, 'virbr0', test_user) elif tap_type == 'macvtap': mac_addr = network_base.create_macvtap(tap_name, host_iface, test_user) if tap_mtu: network_base.set_tap_mtu(tap_name, tap_mtu) + if iface_amount == 'two_ifaces': + network_base.set_tap_mtu(tap_name_2, tap_mtu) + + process.run('ip a') iface_attrs['mac_address'] = mac_addr vmxml = vm_xml.VMXML.new_from_inactive_dumpxml( @@ -82,6 +93,14 @@ def run(test, params, env): vmxml.del_device('interface', by_tag=True) libvirt_vmxml.modify_vm_device(vmxml, 'interface', iface_attrs, virsh_instance=virsh_ins) + if iface_attrs_2: + mac_addr_2 = utils_net.generate_mac_address_simple() + iface_attrs_2['mac_address'] = mac_addr_2 + LOG.debug('Adding a 2nd interface to vm xml') + libvirt_vmxml.modify_vm_device(vmxml, 'interface', iface_attrs_2, 1, + virsh_instance=virsh_ins) + + LOG.debug(f'VMxml is:\n{virsh_ins.dumpxml(vm_name).stdout_text}') start_result = virsh.start(vm_name, debug=True, uri=uri) libvirt.check_exit_status(start_result, status_error) @@ -97,7 +116,33 @@ def run(test, params, env): 'outside_ip': outside_ip, 'host_public_ip': host_ip, } - network_base.ping_check(params, ips, session, force_ipv4=True) + vm_default_gw = utils_net.get_default_gateway(session=session) + + if iface_amount == 'two_ifaces': + ping_params = { + mac_addr: + {'vm_ping_outside': params.get('vm_ping_outside'), + 'vm_ping_host_public': params.get('vm_ping_host_public'), }, + mac_addr_2: + {'vm_ping_outside': params.get('vm_ping_outside')} + } + ips_2 = { + mac_addr: ips, + mac_addr_2: {'outside_ip': vm_default_gw} + } + for mac in (mac_addr, mac_addr_2): + iface_vm_info = utils_net.get_linux_iface_info( + mac=mac, session=session) + iface_vm = iface_vm_info['ifname'] + LOG.debug(f'Check connetivity of iface {iface_vm}({mac})') + ping_args = { + 'vm_ping_outside': {'interface': iface_vm}, + 'vm_ping_host_public': {'interface': iface_vm}, + } + network_base.ping_check(ping_params[mac], ips_2[mac], session, + force_ipv4=True, **ping_args) + else: + network_base.ping_check(params, ips, session, force_ipv4=True) if iface_mtu: # Check mtu of live vmxml @@ -139,5 +184,7 @@ def run(test, params, env): del virsh_ins if tap_type: network_base.delete_tap(tap_name) + if iface_amount == 'two_ifaces': + network_base.delete_tap(tap_name_2) if tap_type == 'tap': utils_net.delete_linux_bridge_tmux(bridge_name, host_iface)