Home | History | Annotate | Download | only in testscripts
      1 #!/bin/bash
      2 
      3 
      4 ##############################################################
      5 #
      6 #  Copyright (c) International Business Machines  Corp., 2003
      7 #
      8 #  This program is free software;  you can redistribute it and/or modify
      9 #  it under the terms of the GNU General Public License as published by
     10 #  the Free Software Foundation; either version 2 of the License, or
     11 #  (at your option) any later version.
     12 #
     13 #  This program is distributed in the hope that it will be useful,
     14 #  but WITHOUT ANY WARRANTY;  without even the implied warranty of
     15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     16 #  the GNU General Public License for more details.
     17 #
     18 #  You should have received a copy of the GNU General Public License
     19 #  along with this program;  if not, write to the Free Software
     20 #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     21 #
     22 #  FILE        : autofs1.sh
     23 #  USAGE       : autofs1.sh <disk_partition>
     24 #
     25 #  DESCRIPTION : A script that will test autofs on Linux system.
     26 #  REQUIREMENTS:
     27 #                1) System with a floppy device with a floppy disk in it.
     28 #                2) A spare (scratch) disk partition of 100MB or larger.
     29 #
     30 #  HISTORY     :
     31 #      06/11/2003 Prakash Narayana (prakashn (at] us.ibm.com)
     32 #      08/01/2005 Michael Reed (mreed10 (at] us.ibm.com)
     33 #      - Added an check to see if a directory exists
     34 #      - This prevents unnessary failures
     35 #      - Correction to an echo statement
     36 #      - Added an additional error message if a floppy disk is not present
     37 #
     38 #  CODE COVERAGE:
     39 #                41.46% - fs/autofs/dirhash.c
     40 #                33.33% - fs/autofs/init.c
     41 #                27.70% - fs/autofs/inode.c
     42 #                38.16% - fs/autofs/root.c
     43 #                 0.00% - fs/autofs/symlink.c
     44 #                43.40% - fs/autofs/waitq.c
     45 #
     46 ##############################################################
     47 
     48 
     49 ##############################################################
     50 #
     51 # Make sure that uid=root is running this script.
     52 # Validate the command line argument as a block special device.
     53 # Make sure that autofs package has been installed.
     54 # Make sure that autofs module is built into the kernel or loaded.
     55 #
     56 ##############################################################
     57 
     58 if [ $UID != 0 ]
     59 then
     60 	echo "FAILED: Must have root access to execute this script"
     61 	exit 1
     62 fi
     63 
     64 if [ $# != 1 ]
     65 then
     66 	echo "FAILED: Usage $0 <disk_partition>"
     67         echo "Example: $0 /dev/hdc1"
     68 	exit 1
     69 else
     70 	disk_partition=$1
     71 	if [ ! -b $disk_partition ]
     72 	then
     73 		echo "FAILED: Usage $0 <block special disk_partition>"
     74 		exit 1
     75 	fi
     76 	mkfs -t ext2 $disk_partition
     77 fi
     78 
     79 rpm -q -a | grep autofs
     80 if [ $? != 0 ]
     81 then
     82 	echo "FAILED: autofs package is not installed"
     83 	exit 1
     84 fi
     85 
     86 grep autofs /proc/filesystems
     87 if [ $? != 0 ]
     88 then
     89 	echo "FAILED: autofs module is not built into the kernel or loaded"
     90 	exit 1
     91 fi
     92 
     93 
     94 ##############################################################
     95 #
     96 # Pick the floppy device name from /etc/fstab
     97 # Format (mkfs -t ext2) the floppy to ext2 file system
     98 # Create the /etc/auto.master
     99 # Create the /etc/auto.media
    100 # Create /AUTOFS directory.
    101 #
    102 ##############################################################
    103 
    104 floppy_dev=`grep floppy /etc/fstab | awk '{print $1}'`
    105 
    106 echo "Found floppy device:$floppy_dev"
    107 
    108 if [ $floppy_dev != "" ]
    109 then
    110 	/sbin/mkfs -t ext2 $floppy_dev
    111 	if [ $? != 0 ]
    112 	then
    113 		echo "FAILED: mkfs -t ext2 $floppy_dev failed"
    114 		echo "Insert a disk into the floppy drive"
    115 		exit 1
    116 	fi
    117 fi
    118 
    119 if [ ! -d /AUTOFS ]
    120 then
    121 	mkdir -m 777 /AUTOFS
    122 fi
    123 
    124 echo "/AUTOFS/MEDIA	/etc/auto.media" > /etc/auto.master
    125 echo "floppy	-fstype=ext2	:$floppy_dev" > /etc/auto.media
    126 
    127 
    128 ##############################################################
    129 #
    130 # Verify that "/etc/init.d/autofs start|restart|stop|status|reload"
    131 # command works.
    132 #
    133 # If fails, cleanup and exit.
    134 #
    135 ##############################################################
    136 
    137 /etc/init.d/autofs start
    138 if [ $? != 0 ]
    139 then
    140 	rm -rf /etc/auto.master /etc/auto.media /AUTOFS
    141 	echo "FAILED: "/etc/init.d/autofs start""
    142 	exit 1
    143 fi
    144 echo "Resuming test, please wait..."
    145 sleep 15
    146 
    147 /etc/init.d/autofs stop
    148 if [ $? != 0 ]
    149 then
    150 	rm -rf /etc/auto.master /etc/auto.media /AUTOFS
    151 	echo "FAILED: "/etc/init.d/autofs stop""
    152 	exit 1
    153 else
    154 	/etc/init.d/autofs start
    155 fi
    156 echo "Resuming test, please wait..."
    157 sleep 15
    158 
    159 /etc/init.d/autofs restart
    160 if [ $? != 0 ]
    161 then
    162 	/etc/init.d/autofs stop
    163 	rm -rf /etc/auto.master /etc/auto.media /AUTOFS
    164 	echo "FAILED: "/etc/init.d/autofs restart""
    165 	exit 1
    166 fi
    167 echo "Resuming test, please wait..."
    168 sleep 15
    169 
    170 /etc/init.d/autofs status
    171 if [ $? != 0 ]
    172 then
    173 	/etc/init.d/autofs stop
    174 	rm -rf /etc/auto.master /etc/auto.media /AUTOFS
    175 	echo "FAILED: "/etc/init.d/autofs status""
    176 	exit 1
    177 fi
    178 
    179 /etc/init.d/autofs reload
    180 if [ $? != 0 ]
    181 then
    182 	/etc/init.d/autofs stop
    183 	rm -rf /etc/auto.master /etc/auto.media /AUTOFS
    184 	echo "FAILED: "/etc/init.d/autofs reload""
    185 	exit 1
    186 fi
    187 
    188 
    189 ##############################################################
    190 #
    191 # Tryout some error code paths by:
    192 # (1) Write into automount directory
    193 # (2) Remove automount parent directory
    194 # (3) Automount the floppy disk
    195 # (4) Hit automounter timeout by sleep 60; then wakeup with error
    196 #     condition.
    197 #
    198 ##############################################################
    199 
    200 echo "forcing error paths and conditions..."
    201 
    202 mkdir /AUTOFS/MEDIA/mydir >/dev/null 2>&1
    203 rm -rf /AUTOFS >/dev/null 2>&1
    204 
    205 mkdir /AUTOFS/MEDIA/floppy/test
    206 cp /etc/auto.master /etc/auto.media /AUTOFS/MEDIA/floppy/test
    207 sync; sync
    208 echo "Resuming test, please wait..."
    209 sleep 60
    210 mkdir /AUTOFS/MEDIA/mydir >/dev/null 2>&1
    211 rm -rf /AUTOFS >/dev/null 2>&1
    212 
    213 
    214 ##############################################################
    215 #
    216 # Add an entry to the /etc/auto.master and reload.
    217 #
    218 ##############################################################
    219 
    220 echo "/AUTOFS/DISK	/etc/auto.disk" >> /etc/auto.master
    221 echo "disk		-fstype=auto,rw,sync	:$disk_partition " > /etc/auto.disk
    222 /etc/init.d/autofs reload
    223 echo "Resuming test, please wait..."
    224 sleep 30
    225 
    226 
    227 
    228 mkdir /AUTOFS/DISK/disk/test
    229 cp /etc/auto.master /etc/auto.media /AUTOFS/DISK/disk/test
    230 sync; sync
    231 echo "Resuming test, please wait..."
    232 sleep 60
    233 
    234 
    235 if [ -e  /AUTOFS/DISK/disk/test ]; then
    236   cd /AUTOFS/DISK/disk/test
    237   umount /AUTOFS/DISK/disk/ >/dev/null 2>&1
    238   if [ $? = 0 ]
    239     then
    240 	/etc/init.d/autofs stop
    241 	rm -rf /etc/auto.master /etc/auto.media /etc/auto.disk /AUTOFS
    242 	echo "FAILED: unmounted a busy file system!"
    243 	exit 1
    244   fi
    245   cd
    246   umount /AUTOFS/DISK/disk/
    247 if [ $? != 0 ]
    248   then
    249 	/etc/init.d/autofs stop
    250 	rm -rf /etc/auto.master /etc/auto.media /etc/auto.disk /AUTOFS
    251 	echo "FAILED: Could not unmount automounted file system"
    252 	exit 1
    253   fi
    254 fi
    255 #
    256 # Mount the disk partition somewhere else and then reference automount
    257 # point for disk partition.
    258 #
    259 mount -t ext2 $disk_partition /mnt/
    260 ls -l /AUTOFS/DISK/disk
    261 umount /mnt
    262 
    263 
    264 #######################################################
    265 #
    266 # Just before exit, stop autofs and cleanup.
    267 #
    268 #######################################################
    269 
    270 /etc/init.d/autofs stop
    271 rm -rf /etc/auto.master /etc/auto.media /etc/auto.disk /AUTOFS
    272 echo "PASSED: $0 passed!"
    273 exit 0
    274