From ebb883e51491077ba08fe5a035cb6b089de2061f Mon Sep 17 00:00:00 2001 From: Kyrylo Shatskyy Date: Thu, 8 Nov 2012 12:55:33 +0200 Subject: [PATCH] LU-2351 tests: remote_node works wrong The test-framework's remote_node works wrong for host names with any suffixes. To resolve this the host identification has been switch to IP address. Target node address is compared with address on each interface of the local host. Assume host remote if it is unable to resolve its IP address. Results of comparison are cached in global variables in order to suppress host resolution overhead. Signed-off-by: Kyrylo Shatskyy Xyratex-bug-id: MRP-629 Reviewed-by: Alexander Lezhoev Reviewed-by: Roman Grigoryev Reviewed-by: Bruce Korb Change-Id: I6128650ac8c5cc2759f9ff53856b5ffdf3222aa4 Reviewed-on: http://review.whamcloud.com/4609 Reviewed-by: Bruce Korb Reviewed-by: Alexander Lezhoev Tested-by: Hudson Tested-by: Maloo Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- lustre/tests/Makefile.am | 1 + lustre/tests/resolveip | 39 +++++++++++++++++++++++++++++++++++++++ lustre/tests/test-framework.sh | 40 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100755 lustre/tests/resolveip diff --git a/lustre/tests/Makefile.am b/lustre/tests/Makefile.am index b37ae12..7b58a50 100644 --- a/lustre/tests/Makefile.am +++ b/lustre/tests/Makefile.am @@ -33,6 +33,7 @@ noinst_SCRIPTS += mds-survey.sh parallel-scale-nfs.sh large-lun.sh noinst_SCRIPTS += parallel-scale-nfsv3.sh parallel-scale-nfsv4.sh noinst_SCRIPTS += posix.sh sanity-scrub.sh scrub-performance.sh noinst_SCRIPTS += sanity-quota-old.sh +noinst_SCRIPTS += resolveip nobase_noinst_SCRIPTS = cfg/local.sh nobase_noinst_SCRIPTS += test-groups/regression test-groups/regression-mpi nobase_noinst_SCRIPTS += acl/make-tree acl/run cfg/ncli.sh diff --git a/lustre/tests/resolveip b/lustre/tests/resolveip new file mode 100755 index 0000000..0e3cfd0 --- /dev/null +++ b/lustre/tests/resolveip @@ -0,0 +1,39 @@ +#!/usr/bin/perl +=pod + +=head1 NAME + +resolveip - Resolve IP address for given hostname + +=head1 DESCRIPTION + +Tries to resolve IP address of given hostname and return its value, +returns empty value if unable to detect it. + +=cut + +use Socket; +$hostname = $ARGV[0]; + +sub resolve_ip { + ($hostname) = @_; + + return unless defined $hostname; + + $packed_ip = gethostbyname($hostname); + if (defined $packed_ip) { + $ip_address = inet_ntoa($packed_ip); + return $ip_address; + } +} + +$ip = resolve_ip($hostname); + +if (not $ip or $ip eq '') { + print STDERR "Unable to detect ip address for host: '$hostname'\n"; + exit 1; +} + +print $ip; + +exit 0; diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index 515c4d1..25b6d09 100644 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -4338,9 +4338,45 @@ mdtuuid_from_index() $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p" } +# Description: +# Return unique identifier for given hostname +host_id() { + local host_name=$1 + echo $host_name | md5sum | cut -d' ' -f1 +} + +# Description: +# Returns list of ip addresses for each interface +local_addr_list() { + ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}' +} + +is_local_addr() { + local addr=$1 + # Cache address list to avoid mutiple execution of local_addr_list + LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)} + local i + for i in $LOCAL_ADDR_LIST ; do + [[ "$i" == "$addr" ]] && return 0 + done + return 1 +} + +local_node() { + local host_name=$1 + local is_local="IS_LOCAL_$(host_id $host_name)" + if [ -z "${!is_local-}" ] ; then + eval $is_local=0 + local host_ip=$($LUSTRE/tests/resolveip $host_name) + is_local_addr "$host_ip" && eval $is_local=1 + fi + [[ "${!is_local}" == "1" ]] +} + remote_node () { - local node=$1 - [ "$node" != "$(hostname)" ] + local node=$1 + local_node $node && return 1 + return 0 } remote_mds () -- 1.8.3.1