blob: 678b56fb72beac242cf4c7279b032b813e8db12a [file] [log] [blame]
mridge06925cd2003-07-08 18:05:01 +00001#!/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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080020# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
mridge06925cd2003-07-08 18:05:01 +000021#
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@us.ibm.com)
mreed108e247262005-08-02 18:25:06 +000032# 08/01/2005 Michael Reed (mreed10@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
mridge06925cd2003-07-08 18:05:01 +000037#
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
58if [ $UID != 0 ]
59then
60 echo "FAILED: Must have root access to execute this script"
61 exit 1
62fi
63
64if [ $# != 1 ]
65then
66 echo "FAILED: Usage $0 <disk_partition>"
mridgea64d3222004-02-06 16:00:20 +000067 echo "Example: $0 /dev/hdc1"
mridge06925cd2003-07-08 18:05:01 +000068 exit 1
69else
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
Chris Dearman37550cf2012-10-17 19:54:01 -070076 mkfs -t ext2 $disk_partition
mridge06925cd2003-07-08 18:05:01 +000077fi
78
Chris Dearman37550cf2012-10-17 19:54:01 -070079rpm -q -a | grep autofs
mridge06925cd2003-07-08 18:05:01 +000080if [ $? != 0 ]
81then
82 echo "FAILED: autofs package is not installed"
83 exit 1
84fi
85
Chris Dearman37550cf2012-10-17 19:54:01 -070086grep autofs /proc/filesystems
mridge06925cd2003-07-08 18:05:01 +000087if [ $? != 0 ]
88then
89 echo "FAILED: autofs module is not built into the kernel or loaded"
90 exit 1
91fi
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
104floppy_dev=`grep floppy /etc/fstab | awk '{print $1}'`
105
mridgea64d3222004-02-06 16:00:20 +0000106echo "Found floppy device:$floppy_dev"
107
mridge06925cd2003-07-08 18:05:01 +0000108if [ $floppy_dev != "" ]
109then
Chris Dearman37550cf2012-10-17 19:54:01 -0700110 /sbin/mkfs -t ext2 $floppy_dev
mridge06925cd2003-07-08 18:05:01 +0000111 if [ $? != 0 ]
112 then
113 echo "FAILED: mkfs -t ext2 $floppy_dev failed"
mreed108e247262005-08-02 18:25:06 +0000114 echo "Insert a disk into the floppy drive"
Chris Dearman37550cf2012-10-17 19:54:01 -0700115 exit 1
mridge06925cd2003-07-08 18:05:01 +0000116 fi
117fi
118
119if [ ! -d /AUTOFS ]
120then
mridgea64d3222004-02-06 16:00:20 +0000121 mkdir -m 777 /AUTOFS
mridge06925cd2003-07-08 18:05:01 +0000122fi
123
mridgea64d3222004-02-06 16:00:20 +0000124echo "/AUTOFS/MEDIA /etc/auto.media" > /etc/auto.master
125echo "floppy -fstype=ext2 :$floppy_dev" > /etc/auto.media
mridge06925cd2003-07-08 18:05:01 +0000126
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
Chris Dearman37550cf2012-10-17 19:54:01 -0700137/etc/init.d/autofs start
mridge06925cd2003-07-08 18:05:01 +0000138if [ $? != 0 ]
139then
140 rm -rf /etc/auto.master /etc/auto.media /AUTOFS
141 echo "FAILED: "/etc/init.d/autofs start""
142 exit 1
143fi
mridgea64d3222004-02-06 16:00:20 +0000144echo "Resuming test, please wait..."
mridge06925cd2003-07-08 18:05:01 +0000145sleep 15
146
Chris Dearman37550cf2012-10-17 19:54:01 -0700147/etc/init.d/autofs stop
mridge06925cd2003-07-08 18:05:01 +0000148if [ $? != 0 ]
149then
150 rm -rf /etc/auto.master /etc/auto.media /AUTOFS
151 echo "FAILED: "/etc/init.d/autofs stop""
152 exit 1
153else
Chris Dearman37550cf2012-10-17 19:54:01 -0700154 /etc/init.d/autofs start
mridge06925cd2003-07-08 18:05:01 +0000155fi
mridgea64d3222004-02-06 16:00:20 +0000156echo "Resuming test, please wait..."
mridge06925cd2003-07-08 18:05:01 +0000157sleep 15
158
Chris Dearman37550cf2012-10-17 19:54:01 -0700159/etc/init.d/autofs restart
mridge06925cd2003-07-08 18:05:01 +0000160if [ $? != 0 ]
161then
Chris Dearman37550cf2012-10-17 19:54:01 -0700162 /etc/init.d/autofs stop
mridge06925cd2003-07-08 18:05:01 +0000163 rm -rf /etc/auto.master /etc/auto.media /AUTOFS
164 echo "FAILED: "/etc/init.d/autofs restart""
165 exit 1
166fi
mridgea64d3222004-02-06 16:00:20 +0000167echo "Resuming test, please wait..."
mridge06925cd2003-07-08 18:05:01 +0000168sleep 15
169
Chris Dearman37550cf2012-10-17 19:54:01 -0700170/etc/init.d/autofs status
mridge06925cd2003-07-08 18:05:01 +0000171if [ $? != 0 ]
172then
Chris Dearman37550cf2012-10-17 19:54:01 -0700173 /etc/init.d/autofs stop
mridge06925cd2003-07-08 18:05:01 +0000174 rm -rf /etc/auto.master /etc/auto.media /AUTOFS
175 echo "FAILED: "/etc/init.d/autofs status""
176 exit 1
177fi
178
Chris Dearman37550cf2012-10-17 19:54:01 -0700179/etc/init.d/autofs reload
mridge06925cd2003-07-08 18:05:01 +0000180if [ $? != 0 ]
181then
Chris Dearman37550cf2012-10-17 19:54:01 -0700182 /etc/init.d/autofs stop
mridge06925cd2003-07-08 18:05:01 +0000183 rm -rf /etc/auto.master /etc/auto.media /AUTOFS
184 echo "FAILED: "/etc/init.d/autofs reload""
185 exit 1
186fi
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
mreed108e247262005-08-02 18:25:06 +0000200echo "forcing error paths and conditions..."
mridgea64d3222004-02-06 16:00:20 +0000201
Chris Dearman37550cf2012-10-17 19:54:01 -0700202mkdir /AUTOFS/MEDIA/mydir 2>&1 > /dev/null
203rm -rf /AUTOFS 2>&1 > /dev/null
mridge06925cd2003-07-08 18:05:01 +0000204
205mkdir /AUTOFS/MEDIA/floppy/test
206cp /etc/auto.master /etc/auto.media /AUTOFS/MEDIA/floppy/test
207sync; sync
mridgea64d3222004-02-06 16:00:20 +0000208echo "Resuming test, please wait..."
mridge06925cd2003-07-08 18:05:01 +0000209sleep 60
Chris Dearman37550cf2012-10-17 19:54:01 -0700210mkdir /AUTOFS/MEDIA/mydir 2>&1 > /dev/null
211rm -rf /AUTOFS 2>&1 > /dev/null
mridge06925cd2003-07-08 18:05:01 +0000212
213
214##############################################################
215#
216# Add an entry to the /etc/auto.master and reload.
217#
218##############################################################
219
mridgea64d3222004-02-06 16:00:20 +0000220echo "/AUTOFS/DISK /etc/auto.disk" >> /etc/auto.master
221echo "disk -fstype=auto,rw,sync :$disk_partition " > /etc/auto.disk
Chris Dearman37550cf2012-10-17 19:54:01 -0700222/etc/init.d/autofs reload
mridgea64d3222004-02-06 16:00:20 +0000223echo "Resuming test, please wait..."
mridge06925cd2003-07-08 18:05:01 +0000224sleep 30
225
mridgea64d3222004-02-06 16:00:20 +0000226
227
mridge06925cd2003-07-08 18:05:01 +0000228mkdir /AUTOFS/DISK/disk/test
229cp /etc/auto.master /etc/auto.media /AUTOFS/DISK/disk/test
230sync; sync
mridgea64d3222004-02-06 16:00:20 +0000231echo "Resuming test, please wait..."
mridge06925cd2003-07-08 18:05:01 +0000232sleep 60
233
mreed108e247262005-08-02 18:25:06 +0000234
235if [ -e /AUTOFS/DISK/disk/test ]; then
Chris Dearman37550cf2012-10-17 19:54:01 -0700236 cd /AUTOFS/DISK/disk/test
mreed108e247262005-08-02 18:25:06 +0000237 umount /AUTOFS/DISK/disk/ 2>&1 > /dev/null
238 if [ $? = 0 ]
239 then
Chris Dearman37550cf2012-10-17 19:54:01 -0700240 /etc/init.d/autofs stop
mridge06925cd2003-07-08 18:05:01 +0000241 rm -rf /etc/auto.master /etc/auto.media /etc/auto.disk /AUTOFS
242 echo "FAILED: unmounted a busy file system!"
243 exit 1
mreed108e247262005-08-02 18:25:06 +0000244 fi
Chris Dearman37550cf2012-10-17 19:54:01 -0700245 cd
246 umount /AUTOFS/DISK/disk/
mridge06925cd2003-07-08 18:05:01 +0000247if [ $? != 0 ]
mreed108e247262005-08-02 18:25:06 +0000248 then
Chris Dearman37550cf2012-10-17 19:54:01 -0700249 /etc/init.d/autofs stop
mridge06925cd2003-07-08 18:05:01 +0000250 rm -rf /etc/auto.master /etc/auto.media /etc/auto.disk /AUTOFS
251 echo "FAILED: Could not unmount automounted file system"
252 exit 1
mreed108e247262005-08-02 18:25:06 +0000253 fi
mridge06925cd2003-07-08 18:05:01 +0000254fi
mridge06925cd2003-07-08 18:05:01 +0000255#
256# Mount the disk partition somewhere else and then reference automount
257# point for disk partition.
258#
259mount -t ext2 $disk_partition /mnt/
260ls -l /AUTOFS/DISK/disk
261umount /mnt
262
263
264#######################################################
265#
266# Just before exit, stop autofs and cleanup.
267#
268#######################################################
269
Chris Dearman37550cf2012-10-17 19:54:01 -0700270/etc/init.d/autofs stop
mridge06925cd2003-07-08 18:05:01 +0000271rm -rf /etc/auto.master /etc/auto.media /etc/auto.disk /AUTOFS
272echo "PASSED: $0 passed!"
273exit 0