Skip to content

Commit c7a4182

Browse files
committed
passt: Cover the passt attribute hostname and fqdn
Cover the bug https://issues.redhat.com/browse/RHEL-79806. Since it needs to captures the DHCP packets via tshark in the guest, wireshark-cli should be installed when preparing the guest image. Signed-off-by: Han Han <[email protected]>
1 parent c84b049 commit c7a4182

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

libvirt/tests/cfg/virtual_network/passt/passt_function.cfg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,12 @@
8686
- vhostuser:
8787
vhostuser = yes
8888
func_supported_since_libvirt_ver = (10, 10, 0)
89+
variants:
90+
- no_domain_name_opts:
91+
use_domain_name_opts = no
92+
- domain_name_opts:
93+
use_domain_name_opts = yes
94+
func_supported_since_libvirt_ver = (11, 8, 0)
95+
hostname = 'test1'
96+
fqdn = 'test2.libvirt.passt'
97+
proc_checks = ['--hostname ${hostname}', '--fqdn ${fqdn}']

libvirt/tests/src/virtual_network/passt/passt_function.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
33
import shutil
4+
import time
45
from avocado.utils import process
56

67
import aexpect
@@ -73,6 +74,7 @@ def run(test, params, env):
7374
multiple_nexthops = 'yes' == params.get('multiple_nexthops', 'no')
7475
libvirtd_debug_file = params.get('libvirtd_debug_file')
7576
warning_check = params.get('warning_check')
77+
use_domain_name_opts = 'yes' == params.get('use_domain_name_opts')
7678

7779
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name,
7880
virsh_instance=virsh_ins)
@@ -100,6 +102,13 @@ def run(test, params, env):
100102
virtqemud_config = VirtQemudConfig()
101103
virtqemud_config.log_outputs = "1:file:{0}".format(libvirtd_debug_file)
102104
utils_libvirtd.Libvirtd('virtqemud').restart()
105+
106+
if use_domain_name_opts:
107+
hostname = params.get('hostname')
108+
fqdn = params.get('fqdn')
109+
iface_attrs['backend']['hostname'] = hostname
110+
iface_attrs['backend']['fqdn'] = fqdn
111+
103112
libvirt_vmxml.modify_vm_device(vmxml, 'interface', iface_attrs,
104113
virsh_instance=virsh_ins)
105114
LOG.debug(virsh_ins.dumpxml(vm_name).stdout_text)
@@ -119,6 +128,31 @@ def run(test, params, env):
119128
passt.check_vm_mtu(session, vm_iface, mtu)
120129
passt.check_default_gw(session, host_iface, multiple_nexthops)
121130
passt.check_nameserver(session)
131+
if use_domain_name_opts:
132+
session.cmd(
133+
'tshark -f "udp port 67 or 68 or 546 or 547" -T json -e dhcp.fqdn.name -e dhcpv6.client_domain -e dhcp.option.hostname > dhcp.json &')
134+
session.cmd('systemctl restart NetworkManager')
135+
time.sleep(5)
136+
session.cmd('killall tshark')
137+
for dhcp_opt_key in ['dhcp.option.hostname', 'dhcp.fqdn.name', 'dhcpv6.client_domain']:
138+
jq_query = '''jq '[.[] | ._source.layers."{0}"[]?] | unique[]' dhcp.json'''.format(dhcp_opt_key)
139+
status, dhcp_opt_val = session.cmd_status_output(jq_query)
140+
if status:
141+
test.fail("Fail to run the jq cmd in guest: {0}".format(jq_query))
142+
if len(dhcp_opt_val.split()) != 1:
143+
test.fail(
144+
'Expect to get only 1 value from dhcp option {0} but failed'.format(dhcp_opt_key))
145+
if dhcp_opt_key == 'dhcp.option.hostname':
146+
if hostname not in dhcp_opt_val:
147+
test.fail('The hostname={0} in domain XML does not match the result {1}={2} in tshark'.format(
148+
hostname, dhcp_opt_key, dhcp_opt_val))
149+
else:
150+
# Note: the fqdn with trailing dot will cause this check fail. It is a wireshark dissectors issue
151+
# E.g: fqdn=xxx.xxx. , wireshark will represent it like dhcp_fqdn_name=xxx.xxx
152+
# see also https://bugs.passt.top/show_bug.cgi?id=170
153+
if fqdn not in dhcp_opt_val:
154+
test.fail('The dhcp fqdn={0} in domain XML does not match the result {1}={2} in tshark'.format(
155+
fqdn, dhcp_opt_key, dhcp_opt_val))
122156

123157
ips = {
124158
'outside_ip': outside_ip,

0 commit comments

Comments
 (0)