Skip to content

Commit

Permalink
provider//passt: add changes for multiarch
Browse files Browse the repository at this point in the history
'passt.avx2' is a specialization only for x86_64.
On other architectures the process might just be "passt".

Change the regular expression to match any process containing
"passt".

`check_vm_ip` calculated the guest interface name for x86_64
for other architectures allow for configuration of this value.

Remove zone index when comparing routes as they might differ
between host and guest (e.g. if the interfaces are named differently).

Check gateways by confirming that routes in guest are available on
host instead of confirming they must be exactly the same on both ends.

Pass the target interface name to the check_connection function to
allow for the correct selection of the gateway. When a host
has two interfaces the function used a list and failed.

Signed-off-by: Sebastian Mitterle <[email protected]>
  • Loading branch information
smitterl committed Dec 22, 2023
1 parent 2de0330 commit 4114363
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions provider/virtual_network/passt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import re
import random
from socket import socket

Expand Down Expand Up @@ -169,15 +170,17 @@ def check_proc(target):
raise exceptions.TestFail(';'.join(failed_check))


def check_vm_ip(iface_attrs, session, host_iface):
def check_vm_ip(iface_attrs, session, host_iface, vm_iface=None):
"""
Check if vm ip and prefix meet expectation
:param iface_attrs: attributes of interface
:param session: shell session instance of vm
:param host_iface: host interface
:param vm_iface: VM interface, can be omitted on x86_64
"""
vm_iface = 'eno' + iface_attrs.get('acpi', {'index': '1'})['index']
if not vm_iface:
vm_iface = 'eno' + iface_attrs.get('acpi', {'index': '1'})['index']
vm_ip, prefix = get_iface_ip_and_prefix(vm_iface, session=session)
LOG.debug(f'VM ip and prefix: {vm_ip}, {prefix}')
if 'ips' in iface_attrs:
Expand Down Expand Up @@ -232,21 +235,24 @@ def check_vm_mtu(session, iface, mtu):

def check_default_gw(session):
"""
Check whether default host gateways of host and guest are consistent
Check whether default host gateways of host and guest are consistent,
i.e. the guest's gateways are available on the host.
:param session: vm shell session instance
"""
host_gw = utils_net.get_default_gateway(force_dhcp=True)
vm_gw = utils_net.get_default_gateway(session=session, force_dhcp=True)
host_gw = utils_net.get_default_gateway(force_dhcp=True).split()
vm_gw = utils_net.get_default_gateway(session=session,
force_dhcp=True).split()
LOG.debug(f'Host and vm default ipv4 gateway: {host_gw}, {vm_gw}')
host_gw_v6 = utils_net.get_default_gateway(ip_ver='ipv6')
vm_gw_v6 = utils_net.get_default_gateway(session=session, ip_ver='ipv6')
host_gw_v6 = utils_net.get_default_gateway(ip_ver='ipv6').split()
vm_gw_v6 = utils_net.get_default_gateway(session=session,
ip_ver='ipv6').split()
LOG.debug(f'Host and vm default ipv6 gateway: {host_gw_v6}, {vm_gw_v6}')

if host_gw != vm_gw:
if [x for x in vm_gw if x not in host_gw]:
raise exceptions.TestFail(
'Host default ipv4 gateway not consistent with vm.')
if host_gw_v6 != vm_gw_v6:
if [x for x in vm_gw_v6 if x not in host_gw_v6]:
raise exceptions.TestFail(
'Host default ipv6 gateway not consistent with vm.')

Expand All @@ -258,8 +264,11 @@ def check_nameserver(session):
:param session: vm shell session instance
"""
get_cmd = 'cat /etc/resolv.conf|grep -vE "#|;"'
on_host = process.run(get_cmd, shell=True).stdout_text.strip()
on_vm = session.cmd_output(get_cmd).strip()
on_host = process.run(get_cmd, shell=True).stdout_text.strip().split()
on_vm = session.cmd_output(get_cmd).strip().split()
# remove zone index
on_host = [re.sub(r'%.*', '', x) for x in on_host]
on_vm = [re.sub(r'%.*', '', x) for x in on_vm]
if on_host == on_vm:
LOG.debug(f'Nameserver on vm is consistent with host:\n{on_host}')
else:
Expand Down Expand Up @@ -320,16 +329,20 @@ def check_protocol_connection(src_sess, tar_sess, protocol, addr,
f'actually is {conneted}')


def check_connection(vm, vm_iface, protocols):
def check_connection(vm, vm_iface, protocols, host_iface=None):
"""
Check connection of vm and host
:param vm: vm instance
:param vm_iface: interface of vm
:param protocols: protocols to check
:param host_iface: host interface to get default gw for
if ommitted all default routes are returned
"""
default_gw = utils_net.get_default_gateway(force_dhcp=True)
default_gw_v6 = utils_net.get_default_gateway(ip_ver='ipv6')
default_gw = utils_net.get_default_gateway(force_dhcp=True,
target_iface=host_iface)
default_gw_v6 = utils_net.get_default_gateway(ip_ver='ipv6',
target_iface=host_iface)
for protocol in protocols:
host_sess = aexpect.ShellSession('su')
vm_sess = vm.wait_for_serial_login(timeout=60)
Expand Down Expand Up @@ -379,7 +392,7 @@ def check_port_listen(ports, protocol, host_ip=None):
"""
if protocol.lower() not in ('tcp', 'udp'):
raise exceptions.TestError(f'Unsupported protocol: {protocol}')
cmd_listen = process.run(f"ss -{protocol[0].lower()}lpn|egrep 'passt.avx2'",
cmd_listen = process.run(f"ss -{protocol[0].lower()}lpn|egrep 'passt'",
shell=True).stdout_text
for item in ports:
if item in cmd_listen:
Expand Down

0 comments on commit 4114363

Please sign in to comment.