diff mbox series

Support for 'hostname' usage when the short name option (-s) is not available

Message ID 20240710073400.3112068-1-neill.whillans@codethink.co.uk (mailing list archive)
State New, archived
Headers show
Series Support for 'hostname' usage when the short name option (-s) is not available | expand

Commit Message

Neill Whillans July 10, 2024, 7:34 a.m. UTC
There could be systems where the only 'hostname' options available are
--help and --version, for example, when 'hostname' is provided by
coreutils. This can result in output that corrupts the expected test
output, leading to a test failure.

This commit modifies all instances of 'hostname -s' usage, to check if
the short name option is available, and if not, use only 'hostname'.

Signed-off-by: Neill Whillans <neill.whillans@codethink.co.uk>
---
 common/config  |  8 +++++++-
 common/gcov    |  8 +++++++-
 common/rc      |  9 ++++++++-
 crash/xfscrash | 13 ++++++++++---
 tools/auto-qa  |  8 +++++++-
 tools/db-walk  |  7 ++++++-
 tools/fs-walk  |  7 ++++++-
 tools/interop  |  7 ++++++-
 8 files changed, 57 insertions(+), 10 deletions(-)

Comments

Zorro Lang July 14, 2024, 2:43 p.m. UTC | #1
On Wed, Jul 10, 2024 at 08:34:00AM +0100, Neill Whillans wrote:
> There could be systems where the only 'hostname' options available are
> --help and --version, for example, when 'hostname' is provided by
> coreutils. This can result in output that corrupts the expected test
> output, leading to a test failure.

What kind of test env. do you use which doesn't have `hostname -s`?

> 
> This commit modifies all instances of 'hostname -s' usage, to check if
> the short name option is available, and if not, use only 'hostname'.
> 
> Signed-off-by: Neill Whillans <neill.whillans@codethink.co.uk>
> ---
>  common/config  |  8 +++++++-
>  common/gcov    |  8 +++++++-
>  common/rc      |  9 ++++++++-
>  crash/xfscrash | 13 ++++++++++---
>  tools/auto-qa  |  8 +++++++-
>  tools/db-walk  |  7 ++++++-
>  tools/fs-walk  |  7 ++++++-
>  tools/interop  |  7 ++++++-
>  8 files changed, 57 insertions(+), 10 deletions(-)
> 
> diff --git a/common/config b/common/config
> index a1cd14de..9728a884 100644
> --- a/common/config
> +++ b/common/config
> @@ -48,7 +48,13 @@ export LC_ALL=C
>  
>  PATH=".:$PATH"
>  
> -export HOST=`hostname -s`
> +# If 'hostname -s' option not available, use 'hostname'
> +if ! hostname -s > /dev/null 2>&1; then
> +	export HOST=`hostname`

Maybe `hostname | cut -d. -f1` ?

> +else
> +	export HOST=`hostname -s`
> +fi

Or we just let HOST=$(hostname | cut -d. -f1), to reduce the steps.

> +
>  test `uname -s` = "Linux" || _fatal "fstests only supports Linux"
>  
>  export MODULAR=0               # using XFS as a module or not
> diff --git a/common/gcov b/common/gcov
> index b7e3ed5a..3e75d765 100644
> --- a/common/gcov
> +++ b/common/gcov
> @@ -45,9 +45,15 @@ _gcov_generate_report() {
>  	# Generate a detailed HTML report from the summary
>  	local gcov_start_time="$(date --date="${fstests_start_time:-now}")"
>  	local genhtml=()
> +  # If 'hostname -s' option not available, use 'hostname'
> +  if ! hostname -s > /dev/null 2>&1; then
> +	  export HOST=`hostname`
> +  else
> +	  export HOST=`hostname -s`
> +  fi

As we've gotten and exported HOST in common/config, can't we just use the $HOST
at here?

>  	if command -v genhtml > /dev/null; then
>  		genhtml+=(genhtml -o "${output_dir}/" "${output_dir}/gcov.report")
> -		genhtml+=(--title "fstests on $(hostname -s) @ ${gcov_start_time}" --legend)
> +		genhtml+=(--title "fstests on ${HOST} @ ${gcov_start_time}" --legend)
>  	fi
>  
>  	# Try to convert the HTML report summary as text for easier grepping if
> diff --git a/common/rc b/common/rc
> index 163041fe..34203c78 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -3453,8 +3453,15 @@ _full_fstyp_details()
>  
>  _full_platform_details()
>  {
> +	# If 'hostname -s' option not available, use 'hostname'
> +	if ! hostname -s > /dev/null 2>&1; then
> +		export HOST=`hostname`
> +	else
> +		export HOST=`hostname -s`
> +	fi
> +

Same question as above

>       local os=`uname -s`
> -     local host=`hostname -s`
> +     local host=${HOST}
>       local kernel=`uname -rv`
>       local platform=`uname -m`
>       echo "$os/$platform $host $kernel"
> diff --git a/crash/xfscrash b/crash/xfscrash
> index 579b724d..cc88c6fc 100755
> --- a/crash/xfscrash
> +++ b/crash/xfscrash


Wow... I've forgotten that we have this program. It's created in 2001, I'm
wondering does anyone still use below scripts :)

Thanks,
Zorro

> @@ -22,8 +22,15 @@ AWK_PROG=gawk
>  # clear FS if >= this percent full at start of run. 100 is a good
>  # number - only used on corrupt test so far
>  FULL_LIMIT=80
> -  
> -case `hostname -s`
> +
> +# If 'hostname -s' option not available, use 'hostname'
> +if ! hostname -s > /dev/null 2>&1; then
> +	export HOST=`hostname`
> +else
> +	export HOST=`hostname -s`
> +fi
> +
> +case ${HOST}
>  in
>      leesa)
>          # mount test partition here
> @@ -54,7 +61,7 @@ in
>          STRESS_RANDOM=360
>  	;;
>      *)
> -        echo "!!! no configuration data for host `hostname -s`"
> +        echo "!!! no configuration data for host ${HOST}"
>          exit 1
>          ;;
>  esac
> diff --git a/tools/auto-qa b/tools/auto-qa
> index 1beb2835..431c1435 100755
> --- a/tools/auto-qa
> +++ b/tools/auto-qa
> @@ -59,7 +59,13 @@ _get_kernel_version()
>  # this should be constant
>  
>  ROOT="$HOME/qa"
> -HOST=`hostname -s`
> +# If 'hostname -s' option not available, use 'hostname'
> +if ! hostname -s > /dev/null 2>&1; then
> +	export HOST=`hostname`
> +else
> +	export HOST=`hostname -s`
> +fi
> +
>  if [ ! -z "$CVSROOT" ]; then
>      export WORKAREA="$ROOT/xfs-cmds"
>  else
> diff --git a/tools/db-walk b/tools/db-walk
> index e0992055..cb6fdc52 100755
> --- a/tools/db-walk
> +++ b/tools/db-walk
> @@ -162,7 +162,12 @@ $device=shift @ARGV;
>  die "can't read $device\n" unless (-r $device);
>  die "$device is not a block device\n" unless (-b _);
>  
> -chomp($HOST = `hostname -s`);
> +# If 'hostname -s' option not available, use 'hostname'
> +if(system('hostname -s > /dev/null 2>&1')){
> +	chomp($HOST = `hostname`);
> +} else {
> +	chomp($HOST = `hostname -s`);
> +}
>  
>  print "*** db-walk host $HOST device $device\n";
>  
> diff --git a/tools/fs-walk b/tools/fs-walk
> index 918e1ad6..4ff713a4 100755
> --- a/tools/fs-walk
> +++ b/tools/fs-walk
> @@ -56,7 +56,12 @@ $dir=shift @ARGV;
>  die "can't read $dir\n" unless (-r $dir);
>  die "$dir is not a directory\n" unless (-d _);
>  
> -chomp($HOST = `hostname -s`);
> +# If 'hostname -s' option not available, use 'hostname'
> +if(system('hostname -s > /dev/null 2>&1')){
> +	chomp($HOST = `hostname`);
> +} else {
> +	chomp($HOST = `hostname -s`);
> +}
>  
>  print "*** fs-walk host $HOST dir $dir\n";
>  
> diff --git a/tools/interop b/tools/interop
> index dc1652c2..db73dfba 100755
> --- a/tools/interop
> +++ b/tools/interop
> @@ -63,7 +63,12 @@ sub mount($)
>      run("mount -t xfs $ops $SCRATCH_DEV $SCRATCH_MNT");
>  }
>  
> -chomp($HOST=`hostname -s`);
> +# If 'hostname -s' option not available, use 'hostname'
> +if(system('hostname -s > /dev/null 2>&1')){
> +	chomp($HOST = `hostname`);
> +} else {
> +	chomp($HOST = `hostname -s`);
> +}
>  
>  die "usage: $ARGV0 <operation> [parameters]\n" unless (scalar(@ARGV));
>  print "*** $HOST: Interop started\n";
> -- 
> 2.43.0
>
diff mbox series

Patch

diff --git a/common/config b/common/config
index a1cd14de..9728a884 100644
--- a/common/config
+++ b/common/config
@@ -48,7 +48,13 @@  export LC_ALL=C
 
 PATH=".:$PATH"
 
-export HOST=`hostname -s`
+# If 'hostname -s' option not available, use 'hostname'
+if ! hostname -s > /dev/null 2>&1; then
+	export HOST=`hostname`
+else
+	export HOST=`hostname -s`
+fi
+
 test `uname -s` = "Linux" || _fatal "fstests only supports Linux"
 
 export MODULAR=0               # using XFS as a module or not
diff --git a/common/gcov b/common/gcov
index b7e3ed5a..3e75d765 100644
--- a/common/gcov
+++ b/common/gcov
@@ -45,9 +45,15 @@  _gcov_generate_report() {
 	# Generate a detailed HTML report from the summary
 	local gcov_start_time="$(date --date="${fstests_start_time:-now}")"
 	local genhtml=()
+  # If 'hostname -s' option not available, use 'hostname'
+  if ! hostname -s > /dev/null 2>&1; then
+	  export HOST=`hostname`
+  else
+	  export HOST=`hostname -s`
+  fi
 	if command -v genhtml > /dev/null; then
 		genhtml+=(genhtml -o "${output_dir}/" "${output_dir}/gcov.report")
-		genhtml+=(--title "fstests on $(hostname -s) @ ${gcov_start_time}" --legend)
+		genhtml+=(--title "fstests on ${HOST} @ ${gcov_start_time}" --legend)
 	fi
 
 	# Try to convert the HTML report summary as text for easier grepping if
diff --git a/common/rc b/common/rc
index 163041fe..34203c78 100644
--- a/common/rc
+++ b/common/rc
@@ -3453,8 +3453,15 @@  _full_fstyp_details()
 
 _full_platform_details()
 {
+	# If 'hostname -s' option not available, use 'hostname'
+	if ! hostname -s > /dev/null 2>&1; then
+		export HOST=`hostname`
+	else
+		export HOST=`hostname -s`
+	fi
+
      local os=`uname -s`
-     local host=`hostname -s`
+     local host=${HOST}
      local kernel=`uname -rv`
      local platform=`uname -m`
      echo "$os/$platform $host $kernel"
diff --git a/crash/xfscrash b/crash/xfscrash
index 579b724d..cc88c6fc 100755
--- a/crash/xfscrash
+++ b/crash/xfscrash
@@ -22,8 +22,15 @@  AWK_PROG=gawk
 # clear FS if >= this percent full at start of run. 100 is a good
 # number - only used on corrupt test so far
 FULL_LIMIT=80
-  
-case `hostname -s`
+
+# If 'hostname -s' option not available, use 'hostname'
+if ! hostname -s > /dev/null 2>&1; then
+	export HOST=`hostname`
+else
+	export HOST=`hostname -s`
+fi
+
+case ${HOST}
 in
     leesa)
         # mount test partition here
@@ -54,7 +61,7 @@  in
         STRESS_RANDOM=360
 	;;
     *)
-        echo "!!! no configuration data for host `hostname -s`"
+        echo "!!! no configuration data for host ${HOST}"
         exit 1
         ;;
 esac
diff --git a/tools/auto-qa b/tools/auto-qa
index 1beb2835..431c1435 100755
--- a/tools/auto-qa
+++ b/tools/auto-qa
@@ -59,7 +59,13 @@  _get_kernel_version()
 # this should be constant
 
 ROOT="$HOME/qa"
-HOST=`hostname -s`
+# If 'hostname -s' option not available, use 'hostname'
+if ! hostname -s > /dev/null 2>&1; then
+	export HOST=`hostname`
+else
+	export HOST=`hostname -s`
+fi
+
 if [ ! -z "$CVSROOT" ]; then
     export WORKAREA="$ROOT/xfs-cmds"
 else
diff --git a/tools/db-walk b/tools/db-walk
index e0992055..cb6fdc52 100755
--- a/tools/db-walk
+++ b/tools/db-walk
@@ -162,7 +162,12 @@  $device=shift @ARGV;
 die "can't read $device\n" unless (-r $device);
 die "$device is not a block device\n" unless (-b _);
 
-chomp($HOST = `hostname -s`);
+# If 'hostname -s' option not available, use 'hostname'
+if(system('hostname -s > /dev/null 2>&1')){
+	chomp($HOST = `hostname`);
+} else {
+	chomp($HOST = `hostname -s`);
+}
 
 print "*** db-walk host $HOST device $device\n";
 
diff --git a/tools/fs-walk b/tools/fs-walk
index 918e1ad6..4ff713a4 100755
--- a/tools/fs-walk
+++ b/tools/fs-walk
@@ -56,7 +56,12 @@  $dir=shift @ARGV;
 die "can't read $dir\n" unless (-r $dir);
 die "$dir is not a directory\n" unless (-d _);
 
-chomp($HOST = `hostname -s`);
+# If 'hostname -s' option not available, use 'hostname'
+if(system('hostname -s > /dev/null 2>&1')){
+	chomp($HOST = `hostname`);
+} else {
+	chomp($HOST = `hostname -s`);
+}
 
 print "*** fs-walk host $HOST dir $dir\n";
 
diff --git a/tools/interop b/tools/interop
index dc1652c2..db73dfba 100755
--- a/tools/interop
+++ b/tools/interop
@@ -63,7 +63,12 @@  sub mount($)
     run("mount -t xfs $ops $SCRATCH_DEV $SCRATCH_MNT");
 }
 
-chomp($HOST=`hostname -s`);
+# If 'hostname -s' option not available, use 'hostname'
+if(system('hostname -s > /dev/null 2>&1')){
+	chomp($HOST = `hostname`);
+} else {
+	chomp($HOST = `hostname -s`);
+}
 
 die "usage: $ARGV0 <operation> [parameters]\n" unless (scalar(@ARGV));
 print "*** $HOST: Interop started\n";