1 #! /usr/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 #
  29 # Create the configuration file based on passed in variables
  30 # or those set in the configuration file provided by run_test
  31 # file.
  32 #
  33 
  34 #
  35 # Use the same mechanism as a test suite, use a test purpose
  36 # for the configuration processes.   The first is to do the
  37 # configuration and the second test purpose is to unconfigure
  38 # the test suite.
  39 #
  40 iclist="ic1 ic2"
  41 ic1=config_test_suite
  42 ic2=unconfig_test_suite
  43 #
  44 # NAME
  45 #       createconfig
  46 #
  47 # DESCRIPTION
  48 #       Take the current configuration based on the config file provided
  49 #       and create the configuration based on variables passed in.
  50 #
  51 function createconfig
  52 {
  53         if [ ! -f $configfile_tmpl ]
  54         then
  55                 cti_report "There is no template config file to create config from."
  56                 configresult="FAIL"
  57                 return
  58         fi
  59 
  60         if [ -f $configfile ]
  61         then
  62                 cti_report "Test Suite already configured."
  63                 cti_report "to unconfigure the test suite use :"
  64                 cti_report "   run_test comstar iscsi_unconfigure"
  65                 cti_report " or supply an alternate configfile name by using :"
  66                 cti_report "   run_test -v configfile=<filename> comstar iscsi_configure"
  67                 configresult="FAIL"
  68                 return
  69         else
  70                 touch ${configfile}
  71                 if [ $? -ne 0 ]
  72                 then
  73                         cti_report "Could not create the configuration file"
  74                         configresult="FAIL"
  75                         return
  76                 fi
  77         fi
  78 
  79         exec 3<$configfile_tmpl
  80         while :
  81         do
  82                 read -u3 line
  83                 if [[ $? = 1 ]]
  84                 then
  85                         break
  86                 fi
  87                 if [[ "$line" = *([     ]) || "$line" = *([     ])#* ]]
  88                 then
  89                         echo $line
  90                         continue
  91                 fi
  92 
  93                 variable_name=${line%%=*}
  94                 variable_name=${variable_name##*([      ])}
  95                 variable_name=${variable_name%%*([      ])}
  96                 eval variable_value="\${$variable_name}"
  97 
  98                 variable_val=${line##*=}
  99                 variable_val=${variable_val##*([        ])}
 100                 variable_val=${variable_val%%*([        ])}
 101                 if [[ -z $variable_value ]];then
 102                         if [[ "$variable_name" == "RADIUS_HOST" ]];then
 103                                 echo "$variable_name=$iscsi_ihost"
 104                         elif [[ "$variable_name" == "ISCSI_IHOST" ]];then
 105                                 echo "$line"
 106                                 iscsi_ihost=$variable_val
 107                         else
 108                                 echo "$line"
 109                         fi
 110                 else
 111                         # Surround the value with quotation marks if
 112                         # the content of the value is a list 
 113                         typeset tmp
 114                         if [[ "$variable_name" == "ISCSI_IHOST" ]];then
 115                                 iscsi_ihost=$variable_value
 116                         fi
 117                         
 118                         set -A tmp $variable_value      
 119                         if [[ ${#tmp[@]} -gt 1 ]] ; then
 120                                 echo "$variable_name=\"$variable_value\""
 121                         else
 122                                 echo $variable_name=$variable_value
 123                         fi
 124                 fi
 125         done > $configfile
 126 }
 127 
 128 #
 129 # NAME
 130 #       config_test_suite
 131 #
 132 # DESCRIPTION
 133 #       The test purpose the test suite calls to initialize and
 134 #       configure the test suite. 
 135 #
 136 function config_test_suite
 137 {
 138         #
 139         # Check to see if the config file variable is not set,
 140         # and if not the set to the default value
 141         #
 142         if [ -z $configfile ]
 143         then
 144                 configfile=${CTI_SUITE}/config/test_config
 145         fi
 146 
 147         #
 148         # set the config file template variable to the test_config
 149         # template file.
 150         #
 151         configfile_tmpl=${CTI_SUITE}/config/iscsi_test_config.tmpl
 152 
 153         #
 154         # Call the createconfig function to actually process the variables
 155         # and process the template and create the configuration file used
 156         # by the test suite.
 157         #
 158         createconfig
 159 
 160         #
 161         # Verify that the configuration results are PASS or FAIL.
 162         # Report the results tot he end user.
 163         #
 164         if [ "$configresult" = "FAIL" ]
 165         then
 166                 rm -f $configfile
 167                 cti_report "FAIL - Unable to configure test suite."
 168                 cti_fail
 169         else
 170                 cti_report "PASS - Configured test suite."
 171                 cti_pass
 172         fi
 173 }
 174 
 175 #
 176 # NAME
 177 #       unconfig_test_suite
 178 #
 179 # DESCRIPTION
 180 #       The test purpose the test suite calls to un-initialize and
 181 #       configure the test suite. 
 182 #
 183 function unconfig_test_suite
 184 {
 185         #
 186         # Check to see if the config file variable is not set,
 187         # and if not the set to the default value
 188         #
 189         if [ -z $configfile ]
 190         then
 191                 configfile=${CTI_SUITE}/config/test_config
 192         fi
 193 
 194         #
 195         # Remove the configuration file provided, and verify the results
 196         # of the file removal.
 197         #
 198         rm -f $configfile
 199         if [ $? -eq 0 ]
 200         then
 201                 cti_report "PASS - $configfile removed."
 202                 cti_pass
 203         else
 204                 cti_report "FAIL - unable to remove $configfile"
 205                 cti_fail
 206         fi
 207 }
 208 
 209 . ${CTI_ROOT}/lib/ctiutils.ksh
 210 . ${TET_ROOT}/lib/ksh/tcm.ksh
 211