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 # ident "@(#)fc_configure.ksh   1.6     09/08/26 SMI"
  28 #
  29 
  30 #
  31 # Create the configuration file based on passed in variables
  32 # or those set in the configuration file provided by run_test
  33 # file.
  34 #
  35 
  36 #
  37 # Use the same mechanism as a test suite, use a test purpose
  38 # for the configuration processes.   The first is to do the
  39 # configuration and the second test purpose is to unconfigure
  40 # the test suite.
  41 #
  42 iclist="ic1 ic2"
  43 ic1=config_test_suite
  44 ic2=unconfig_test_suite
  45 #
  46 # NAME
  47 #       createconfig
  48 #
  49 # DESCRIPTION
  50 #       Take the current configuration based on the config file provided
  51 #       and create the configuration based on variables passed in.
  52 #
  53 function createconfig
  54 {
  55         if [ ! -f $configfile_tmpl ]
  56         then
  57                 cti_report "There is no template config file to create config from."
  58                 configresult="FAIL"
  59                 return
  60         fi
  61 
  62         if [ -f $configfile ]
  63         then
  64                 cti_report "Test Suite already configured."
  65                 cti_report "to unconfigure the test suite use :"
  66                 cti_report "   run_test comstar fc_unconfigure"
  67                 cti_report " or supply an alternate configfile name by using :"
  68                 cti_report "   run_test -v configfile=<filename> comstar fc_configure"
  69                 configresult="FAIL"
  70                 return
  71         else
  72                 touch ${configfile}
  73                 if [ $? -ne 0 ]
  74                 then
  75                         cti_report "Could not create the configuration file"
  76                         configresult="FAIL"
  77                         return
  78                 fi
  79         fi
  80 
  81         exec 3<$configfile_tmpl
  82         while :
  83         do
  84                 read -u3 line
  85                 if [[ $? = 1 ]]
  86                 then
  87                         break
  88                 fi
  89                 if [[ "$line" = *([     ]) || "$line" = *([     ])#* ]]
  90                 then
  91                         echo $line
  92                         continue
  93                 fi
  94 
  95                 variable_name=${line%%=*}
  96                 variable_name=${variable_name##*([      ])}
  97                 variable_name=${variable_name%%*([      ])}
  98                 eval variable_value="\${$variable_name}"
  99 
 100                 if [[ -z $variable_value ]];then
 101                         echo "$line"
 102                 else
 103                         echo $variable_name=$variable_value
 104                 fi
 105         done > $configfile
 106 }
 107 
 108 #
 109 # NAME
 110 #       config_test_suite
 111 #
 112 # DESCRIPTION
 113 #       The test purpose the test suite calls to initialize and
 114 #       configure the test suite. 
 115 #
 116 function config_test_suite
 117 {
 118         #
 119         # Check to see if the config file variable is not set,
 120         # and if not the set to the default value
 121         #
 122         if [ -z $configfile ]
 123         then
 124                 configfile=${CTI_SUITE}/config/test_config
 125         fi
 126 
 127         #
 128         # set the config file template variable to the test_config
 129         # template file.
 130         #
 131         configfile_tmpl=${CTI_SUITE}/config/fc_test_config.tmpl
 132 
 133         #
 134         # Call the createconfig function to actually process the variables
 135         # and process the template and create the configuration file used
 136         # by the test suite.
 137         #
 138         createconfig
 139 
 140         #
 141         # Verify that the configuration results are PASS or FAIL.
 142         # Report the results tot he end user.
 143         #
 144         if [ "$configresult" = "FAIL" ]
 145         then
 146                 rm -f $configfile
 147                 cti_report "FAIL - Unable to configure test suite."
 148                 cti_fail
 149         else
 150                 cti_report "PASS - Configured test suite."
 151                 cti_pass
 152         fi
 153 }
 154 
 155 #
 156 # NAME
 157 #       unconfig_test_suite
 158 #
 159 # DESCRIPTION
 160 #       The test purpose the test suite calls to un-initialize and
 161 #       configure the test suite. 
 162 #
 163 function unconfig_test_suite
 164 {
 165         #
 166         # Check to see if the config file variable is not set,
 167         # and if not the set to the default value
 168         #
 169         if [ -z $configfile ]
 170         then
 171                 configfile=${CTI_SUITE}/config/test_config
 172         fi
 173 
 174         #
 175         # Remove the configuration file provided, and verify the results
 176         # of the file removal.
 177         #
 178         rm -f $configfile
 179         if [ $? -eq 0 ]
 180         then
 181                 cti_report "PASS - $configfile removed."
 182                 cti_pass
 183         else
 184                 cti_report "FAIL - unable to remove $configfile"
 185                 cti_fail
 186         fi
 187 }
 188 
 189 . ${CTI_ROOT}/lib/ctiutils.ksh
 190 . ${TET_ROOT}/lib/ksh/tcm.ksh
 191