1 #!/usr/bin/ksh
   2 
   3 #
   4 # This file and its contents are supplied under the terms of the
   5 # Common Development and Distribution License ("CDDL"), version 1.0.
   6 # You may only use this file in accordance with the terms of version
   7 # 1.0 of the CDDL.
   8 #
   9 # A full copy of the text of the CDDL should have accompanied this
  10 # source.  A copy of the CDDL is also available via the Internet at
  11 # http://www.illumos.org/license/CDDL.
  12 #
  13 
  14 #
  15 # Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  16 #
  17 
  18 #
  19 # Define necessary environments and config variables here
  20 # prior to invoke TET test runner 'run_test'
  21 #
  22 # Test wrapper for COMSTAR iSCSI tests
  23 #
  24 # Initiator and free disks on target are required 
  25 # Two additional NIF are required on both target and initiator
  26 #
  27 export TET_ROOT=/opt/SUNWstc-tetlite
  28 export CTI_ROOT=$TET_ROOT/contrib/ctitools
  29 export TET_SUITE_ROOT=/opt
  30 export CTI_SUITE=$TET_SUITE_ROOT/comstar-tests
  31 PATH=$PATH:$CTI_ROOT/bin
  32 export PATH
  33 
  34 usage() {
  35         echo "Usage: $0 ip disk"
  36         echo "Where"
  37         echo "   ip     Initiator IP address"
  38         echo "   disk   c0t0d0s0 c0t1d0s0"
  39         exit 1
  40 }
  41 
  42 #
  43 # Must be run by root
  44 #
  45 if [ `id -u` -ne 0 ]; then
  46         echo Must run by root
  47         exit 1
  48 fi
  49 
  50 if [ $# -lt 1 ]; then
  51         usage
  52 fi
  53 
  54 #
  55 # Heart beat check on initiator exit if fails
  56 #
  57 INITIATOR=$1            # Initiator IP
  58 ping $INITIATOR 5
  59 if [ $? != 0 ]; then
  60         echo "Invalid IP address for Initiator"
  61         exit 1
  62 fi
  63 
  64 shift
  65 DISKS=$@
  66 
  67 if [ `echo $DISKS|wc -w` -lt 3 ]; then
  68         echo "At least three free disk slices are required"
  69         exit 1
  70 fi
  71 
  72 #
  73 # Two additional nif are needed
  74 #
  75 IFC="ifconfig -a|egrep -v 'ether|inet|ipib|lo0' | cut -d: -f1|sort -u|wc -w"
  76 Lnif=`eval $IFC`
  77 Rnif=`ssh $INITIATOR "$IFC"`
  78 
  79 if [ $Lnif -lt 3 -o $Rnif -lt 3 ]; then
  80         echo "Two additional network interfaces are required for testing"
  81         exit 1
  82 fi
  83 
  84 #
  85 # Initiator needs to have diskomizer package installed
  86 #
  87 ssh $INITIATOR ls /opt/SUNWstc-diskomizer/bin >/dev/null 2>&1
  88 if [ $? -ne 0 ]; then
  89         echo "Need to install SUNWstc-diskomizer package on $INITIATOR"
  90         exit
  91 fi
  92 
  93 #
  94 # Required configurations
  95 #
  96 HOST=`hostname`
  97 TRANS=SOCKETS   # SOCKETS or ALL can be specified
  98 TARG=`getent hosts $HOST|awk '{print $1}'`      # Target IP
  99 ISNS=$Target            # We don't support iSNS, use target IP
 100 BLKDEVS=
 101 RAWDEVS=
 102 
 103 #
 104 # Construct block and raw devices
 105 #
 106 for d in $DISKS; do
 107         BLKDEVS="$BLKDEVS/dev/dsk/$d "
 108         RAWDEVS="$RAWDEVS/dev/rdsk/$d "
 109 done
 110 
 111 #
 112 # Configure
 113 #
 114 run_test -v TRANSPORT=$TRANS \
 115         -v ISCSI_THOST=$TARG \
 116         -v ISCSI_IHOST=$INITIATOR \
 117         -v ISNS_HOST=$ISNS \
 118         -v "BDEVS=\"$BLKDEVS\"" \
 119         -v "RDEVS=\"$RAWDEVS\"" comstar-tests iscsi_configure
 120 
 121 #
 122 # To run the entire test suite
 123 #
 124 run_test comstar-tests iscsi
 125 
 126 #
 127 # To run individual scenarios (itadm iscsi_auth iscsi_discovery...etc)
 128 #
 129 # run_test comstar-tests iscsi/auth:1
 130 # run_test comstar-tests iscsi/auth:1-2
 131 #
 132 
 133 #
 134 # Unconfigure
 135 #
 136 run_test comstar-tests iscsi_unconfigure