11import logging
22import os
33import shutil
4+ import time
45from avocado .utils import process
56
67import 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