diff mbox series

[autotest-client-tests] UBUNTU: SAUCE: ubuntu_fan_smoke_test: use resolvectl for parsing DNS server by default

Message ID 20220321114328.71526-1-po-hsu.lin@canonical.com
State New
Headers show
Series [autotest-client-tests] UBUNTU: SAUCE: ubuntu_fan_smoke_test: use resolvectl for parsing DNS server by default | expand

Commit Message

Po-Hsu Lin March 21, 2022, 11:43 a.m. UTC
Some SUT will have more than one DNS server, example below is the
output from node spitfire with Focal in Intel MAAS:
    Current DNS Server: 8.8.8.8
    DNS Servers: 192.168.102.22
                 8.8.8.8
    DNS Domain: maas

In this case, this script will get 192.168.102.22 for systems that
comes with systemd-resolve, but the test will fail with:
    Could not resolve 'security.ubuntu.com'

Using the Current DNS Server instead can solve this issue. But this
property does not exist before Focal. The solution is to use
resolvectl by default and parse for "Current DNS Server", while still
using the systemd-resolve to parse for "DNS Servers" in older release.

Patch tested with X/B/F/I on bare-metal MAAS, F/J on Intel MAAS

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 ubuntu_fan_smoke_test/smoke_test_old.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Sean Feole March 21, 2022, 1:13 p.m. UTC | #1
+1 from me, thanks sam!


Sean

On 3/21/22 7:43 AM, Po-Hsu Lin wrote:
> Some SUT will have more than one DNS server, example below is the
> output from node spitfire with Focal in Intel MAAS:
>      Current DNS Server: 8.8.8.8
>      DNS Servers: 192.168.102.22
>                   8.8.8.8
>      DNS Domain: maas
> 
> In this case, this script will get 192.168.102.22 for systems that
> comes with systemd-resolve, but the test will fail with:
>      Could not resolve 'security.ubuntu.com'
> 
> Using the Current DNS Server instead can solve this issue. But this
> property does not exist before Focal. The solution is to use
> resolvectl by default and parse for "Current DNS Server", while still
> using the systemd-resolve to parse for "DNS Servers" in older release.
> 
> Patch tested with X/B/F/I on bare-metal MAAS, F/J on Intel MAAS
> 
> Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
> ---
>   ubuntu_fan_smoke_test/smoke_test_old.sh | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/ubuntu_fan_smoke_test/smoke_test_old.sh b/ubuntu_fan_smoke_test/smoke_test_old.sh
> index 990a6804..8ad8ae54 100755
> --- a/ubuntu_fan_smoke_test/smoke_test_old.sh
> +++ b/ubuntu_fan_smoke_test/smoke_test_old.sh
> @@ -142,16 +142,16 @@ fanatic_docker_test()
>   	dns_opt=""
>   	dns1=$(awk '$1=="nameserver"{print $2; exit}' /etc/resolv.conf)
>   	if [ "$dns1" = "127.0.0.53" ]; then
> -		if command -v systemd-resolve 2>&1 > /dev/null; then
> +		if command -v resolvectl 2>&1 > /dev/null; then
> +			dns_opt="--dns=$(resolvectl status |
> +				sed -n "0,/Current DNS/s/^.*Current DNS Server: //p")"
> +		else
>   			dns_opt="--dns=$(systemd-resolve --status |
>   				awk '/DNS Servers:/{
>   					sub(/.*DNS Servers: */, "")
>   					sub(/,.*/, "")
>   					print
>   					exit}')"
> -		else
> -			dns_opt="--dns=$(resolvectl status |
> -				sed -n "0,/Current DNS/s/^.*Current DNS Server: //p")"
>   		fi
>   		echo -n "($dns_opt): "
>   	else
Po-Hsu Lin March 21, 2022, 2:17 p.m. UTC | #2
Applied and pushed.

Thanks
Sam
diff mbox series

Patch

diff --git a/ubuntu_fan_smoke_test/smoke_test_old.sh b/ubuntu_fan_smoke_test/smoke_test_old.sh
index 990a6804..8ad8ae54 100755
--- a/ubuntu_fan_smoke_test/smoke_test_old.sh
+++ b/ubuntu_fan_smoke_test/smoke_test_old.sh
@@ -142,16 +142,16 @@  fanatic_docker_test()
 	dns_opt=""
 	dns1=$(awk '$1=="nameserver"{print $2; exit}' /etc/resolv.conf)
 	if [ "$dns1" = "127.0.0.53" ]; then
-		if command -v systemd-resolve 2>&1 > /dev/null; then
+		if command -v resolvectl 2>&1 > /dev/null; then
+			dns_opt="--dns=$(resolvectl status |
+				sed -n "0,/Current DNS/s/^.*Current DNS Server: //p")"
+		else
 			dns_opt="--dns=$(systemd-resolve --status |
 				awk '/DNS Servers:/{
 					sub(/.*DNS Servers: */, "")
 					sub(/,.*/, "")
 					print
 					exit}')"
-		else
-			dns_opt="--dns=$(resolvectl status |
-				sed -n "0,/Current DNS/s/^.*Current DNS Server: //p")"
 		fi
 		echo -n "($dns_opt): "
 	else