Whamcloud - gitweb
LU-2351 tests: remote_node works wrong
authorKyrylo Shatskyy <kyrylo_shatskyy@xyratex.com>
Thu, 8 Nov 2012 10:55:33 +0000 (12:55 +0200)
committerOleg Drokin <green@whamcloud.com>
Tue, 8 Jan 2013 05:28:52 +0000 (00:28 -0500)
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 <kyrylo_shatskyy@xyratex.com>
Xyratex-bug-id: MRP-629
Reviewed-by: Alexander Lezhoev <Alexander_Lezhoev@xyratex.com>
Reviewed-by: Roman Grigoryev <Roman_Grigoryev@xyratex.com>
Reviewed-by: Bruce Korb <Bruce_Korb@xyratex.com>
Change-Id: I6128650ac8c5cc2759f9ff53856b5ffdf3222aa4
Reviewed-on: http://review.whamcloud.com/4609
Reviewed-by: Bruce Korb <bruce_korb@xyratex.com>
Reviewed-by: Alexander Lezhoev <alexander_lezhoev@xyratex.com>
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Jian Yu <jian.yu@intel.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/Makefile.am
lustre/tests/resolveip [new file with mode: 0755]
lustre/tests/test-framework.sh

index b37ae12..7b58a50 100644 (file)
@@ -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 (executable)
index 0000000..0e3cfd0
--- /dev/null
@@ -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;
index 515c4d1..25b6d09 100644 (file)
@@ -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 ()