From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson To: passt-dev@passt.top Subject: [PATCH 05/18] tests: More robust parsing of resolv.conf for DHCP tests Date: Fri, 15 Jul 2022 15:21:28 +1000 Message-ID: <20220715052141.890703-6-david@gibson.dropbear.id.au> In-Reply-To: <20220715052141.890703-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0751074575986257061==" --===============0751074575986257061== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To check publishing of DNS information via DHCP, we need to extract a list of nameservers and/or search domains from resolv.conf in the test script. The current version (usually) leaves the result with a trailing ','. That's usually ok because it happens on both guest and host sides. However it's kind of confusing, and might stop working if the host had a resolv.conf without a trailing \n on the last line. It also makes some later changes we'll need more difficult. So, normalize the output from resolv.conf a bit further, removing any trailing ','. It turns out we can do this with a slightly less complex sed expression than the one we already have. Signed-off-by: David Gibson --- test/dhcp/passt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/dhcp/passt b/test/dhcp/passt index 00047a9..a5491bc 100644 --- a/test/dhcp/passt +++ b/test/dhcp/passt @@ -35,15 +35,15 @@ gout MTU ip -j link show | jq -rM '.[] | select(.ifname = =3D=3D "__IFNAME__").mtu' check [ __MTU__ =3D 65520 ] =20 test DHCP: DNS -gout DNS sed -n 's/^nameserver \([0-9]*\.\)\(.*\)/\1\2/p' /etc/resolv.conf |= tr '\n' ',' | sed 's/\(.*\)/\1\n/g' -hout HOST_DNS sed -n 's/^nameserver \([0-9]*\.\)\(.*\)/\1\2/p' /etc/resolv.c= onf | head -n3 | tr '\n' ',' | sed 's/\(.*\)/\1\n/g' +gout DNS sed -n 's/^nameserver \([0-9]*\.\)\(.*\)/\1\2/p' /etc/resolv.conf |= tr '\n' ',' | sed 's/,$//;s/$/\n/' +hout HOST_DNS sed -n 's/^nameserver \([0-9]*\.\)\(.*\)/\1\2/p' /etc/resolv.c= onf | head -n3 | tr '\n' ',' | sed 's/,$//;s/$/\n/' check [ "__DNS__" =3D "__HOST_DNS__" ] =20 # FQDNs should be terminated by dots, but the guest DHCP client might omit t= hem: # strip them first test DHCP: search list -gout SEARCH sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n 's/^s= earch \(.*\)/\1/p' | tr ' \n' ',' | sed 's/\(.*\)/\1\n/g' -hout HOST_SEARCH sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n = 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/\(.*\)/\1\n/g' +gout SEARCH sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n 's/^s= earch \(.*\)/\1/p' | tr ' \n' ',' | sed 's/,$//;s/$/\n/' +hout HOST_SEARCH sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n = 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/,$//;s/$/\n/' check [ "__SEARCH__" =3D "__HOST_SEARCH__" ] =20 test DHCPv6: address @@ -59,11 +59,11 @@ check [ "__GW6__" =3D "__HOST_GW6__" ] =20 # Strip interface specifier: interface names might differ between host and g= uest test DHCPv6: DNS -gout DNS6 sed -n 's/^nameserver \([^:]*:\)\([^%]*\).*/\1\2/p' /etc/resolv.co= nf | tr '\n' ',' | sed 's/\(.*\)/\1\n/g' -hout HOST_DNS6 sed -n 's/^nameserver \([^:]*:\)\([^%]*\).*/\1\2/p' /etc/reso= lv.conf | tr '\n' ',' | sed 's/\(.*\)/\1\n/g' +gout DNS6 sed -n 's/^nameserver \([^:]*:\)\([^%]*\).*/\1\2/p' /etc/resolv.co= nf | tr '\n' ',' | sed 's/,$//;s/$/\n/' +hout HOST_DNS6 sed -n 's/^nameserver \([^:]*:\)\([^%]*\).*/\1\2/p' /etc/reso= lv.conf | tr '\n' ',' | sed 's/,$//;s/$/\n/' check [ "__DNS6__" =3D "__HOST_DNS6__" ] =20 test DHCPv6: search list -gout SEARCH6 sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n 's/^= search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/\(.*\)/\1\n/g' -hout HOST_SEARCH6 sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n= 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/\(.*\)/\1\n/g' +gout SEARCH6 sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n 's/^= search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/,$//;s/$/\n/' +hout HOST_SEARCH6 sed 's/\. / /g' /etc/resolv.conf | sed 's/\.$//g' | sed -n= 's/^search \(.*\)/\1/p' | tr ' \n' ',' | sed 's/,$//;s/$/\n/' check [ "__SEARCH6__" =3D "__HOST_SEARCH6__" ] --=20 2.36.1 --===============0751074575986257061==--