Skip to content

Commit

Permalink
Merge pull request #5957 from chloerh/2-tap
Browse files Browse the repository at this point in the history
Update case of connectivity check of ethernet interface
  • Loading branch information
Yingshun authored Oct 25, 2024
2 parents a3d659f + 5836e6f commit 88bafdb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -70,18 +75,32 @@ 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(
vm_name, virsh_instance=virsh_ins)
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)
Expand All @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 88bafdb

Please sign in to comment.