2 # Copyright (C) 2000 by Sam Hartman
3 # This file may be copied either under the terms of the GNU GPL or the IBM Public License
4 # either version 2 or later of the GPL or version 1.0 or later of the IPL.
8 use OpenAFS::ConfigUtils;
13 use vars qw($admin $server $cellname $cachesize $part
14 $shutdown_needed $csdb);
15 my $rl = new Term::ReadLine('run-suite');
19 run-suite - Set up AFS cell and test.
23 B<run-suite> [B<--cellname> cellname] [B<--cachesize> size]
28 This script sets up an AFS cell, then runs a suite of tests against the
29 cell to verify the build.
31 The B<cellname> option specifies the name of the cell.
33 The B<cachesize> option specifies the size of the AFS cache.
39 # mkvol(volume, mount)
42 run("$openafsdirpath->{'afssrvsbindir'}/vos create $server $part $vol -localauth");
43 unwind("$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part $vol -localauth");
44 run("$openafsdirpath->{'afssrvbindir'}/fs mkm $mnt $vol ");
45 run("$openafsdirpath->{'afssrvbindir'}/fs sa $mnt system:anyuser rl");
49 "cellname=s" => \$cellname,
50 "cachesize=s" => \$cachesize,
51 "partition=s" => \$part,
52 "admin=s" => \$admin);
55 die "This script should almost always be run as root.\n";
58 open(MOUNT, "mount |") or die "Failed to run mount: $!\n";
61 print "The AFS client is currently running on this workstation.\n";
62 print "Please restart this script after running $openafsinitcmd->{'client-stop'}\n";
66 print "The AFS client is currently running on this workstation.\n";
67 print "Please restart this script after running $openafsinitcmd->{'client-stop'}\n";
73 unless ( -f "$openafsdirpath->{'afsconfdir'}/KeyFile") {
74 print "You do not have an AFS keyfile. Please create this using asetkey from openafs-krb5 or
75 the bos addkey command";
79 print "If the fileserver is not running, this may hang for 30 seconds.\n";
80 run("$openafsinitcmd->{'filesrv-stop'}");
83 $admin = "admin" unless $admin;
86 die "The administrative user must be in the same realm as the cell and no realm may be specified.\n";
89 $cellname = $rl->readline("What cellname should be used? ") unless $cellname;
90 die "Please specify a cellname\n" unless $cellname;
92 if (! -f "$openafsdirpath->{'afsconfdir'}/ThisCell") {
93 open(CELL, "> $openafsdirpath->{'afsconfdir'}/ThisCell");
94 print CELL "${cellname}";
98 open(CELL, "$openafsdirpath->{'afsconfdir'}/ThisCell") or
99 die "Cannot open $openafsdirpath->{'afsconfdir'}/ThisCell: $!\n";
105 run( "echo \\>$lcell >$openafsdirpath->{'afsconfdir'}/CellServDB");
106 $csdb = `host $server|awk '{print $4 " #" $1}'`;
107 run( "echo $csdb >>$openafsdirpath->{'afsconfdir'}/CellServDB");
108 run("$openafsinitcmd->{'filesrv-start'}");
109 unwind("$openafsinitcmd->{'filesrv-stop'}");
110 $shutdown_needed = 1;
111 run ("$openafsdirpath->{'afssrvbindir'}/bos addhost $server $server -localauth ||true");
112 run("$openafsdirpath->{'afssrvbindir'}/bos adduser $server $admin -localauth");
113 unwind("$openafsdirpath->{'afssrvbindir'}/bos removeuser $server $admin -localauth");
114 if ( -f "$openafsdirpath->{'afsdbdir'}/prdb.DB0" ) {
115 die "Protection database already exists; cell already partially created\n";
117 open(PRDB, "|$openafsdirpath->{'afssrvsbindir'}/pt_util -p $openafsdirpath->{'afsdbdir'}/prdb.DB0 -w ")
118 or die "Unable to start pt_util: $!\n";
119 print PRDB "$admin 128/20 1 -204 -204\n";
120 print PRDB "system:administrators 130/20 -204 -204 -204\n";
121 print PRDB" $admin 1\n";
123 unwind( "rm $openafsdirpath->{'afsdbdir'}/prdb* ");
124 # Start up ptserver and vlserver
125 run("$openafsdirpath->{'afssrvbindir'}/bos create $server ptserver simple $openafsdirpath->{'afssrvlibexecdir'}/ptserver -localauth");
126 unwind("$openafsdirpath->{'afssrvbindir'}/bos delete $server ptserver -localauth");
127 unwind("$openafsdirpath->{'afssrvbindir'}/bos stop $server ptserver -localauth -wait");
129 run("$openafsdirpath->{'afssrvbindir'}/bos create $server vlserver simple $openafsdirpath->{'afssrvlibexecdir'}/vlserver -localauth");
130 unwind("$openafsdirpath->{'afssrvbindir'}/bos delete $server vlserver -localauth");
131 unwind("$openafsdirpath->{'afssrvbindir'}/bos stop $server vlserver -localauth -wait");
133 run( "$openafsdirpath->{'afssrvbindir'}/bos create $server fs fs ".
134 "-cmd $openafsdirpath->{'afssrvlibexecdir'}/fileserver ".
135 "-cmd $openafsdirpath->{'afssrvlibexecdir'}/volserver ".
136 "-cmd $openafsdirpath->{'afssrvlibexecdir'}/salvager -localauth");
137 unwind( "$openafsdirpath->{'afssrvbindir'}/bos delete $server fs -localauth ");
138 unwind( "$openafsdirpath->{'afssrvbindir'}/bos stop $server fs -localauth -wait");
140 print "Waiting for database elections: ";
143 # Past this point we want to control when bos shutdown happens
144 $shutdown_needed = 0;
145 unwind( "$openafsdirpath->{'afssrvbindir'}/bos shutdown $server -localauth ");
146 run("$openafsdirpath->{'afssrvsbindir'}/vos create $server a root.afs -localauth");
149 $cachesize = $rl->readline("What size cache (in 1k blocks)? ") unless $cachesize;
150 die "Please specify a cache size\n" unless $cachesize;
152 run("echo $lcell >$openafsdirpath->{'viceetcdir'}/ThisCell");
153 run("cp $openafsdirpath->{'afsconfdir'}/CellServDB $openafsdirpath->{'viceetcdir'}/CellServDB");
154 run("echo /afs:/usr/vice/cache:${cachesize} >$openafsdirpath->{'viceetcdir'}/cacheinfo");
155 run("$openafsinitcmd->{'client-forcestart'}");
157 open(MOUNT, "mount |") or die "Failed to run mount: $!\n";
163 unless ($afs_running) {
164 print "*** The AFS client failed to start.\n";
165 print "Please fix whatever problem kept it from running.\n";
168 unwind("$openafsinitcmd->{'client-stop'}");
170 $part = "a" unless $part;
172 &OpenAFS::Auth::authadmin();
174 run("$openafsdirpath->{'afssrvbindir'}/fs sa /afs system:anyuser rl");
176 run("$openafsdirpath->{'afssrvsbindir'}/vos create $server $part root.cell -localauth");
177 unwind("$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part root.cell -localauth");
178 # We make root.cell s:anyuser readable after we mount in the next
180 open(CELLSERVDB, "$openafsdirpath->{'viceetcdir'}/CellServDB")
181 or die "Unable to open $openafsdirpath->{'viceetcdir'}/CellServDB: $!\n";
182 while(<CELLSERVDB>) {
184 if (/^>\s*([a-z0-9_\-.]+)/ ) {
185 run("$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/$1 root.cell -cell $1 -fast");
186 unwind ("$openafsdirpath->{'afssrvbindir'}/fs rmm /afs/$1");
190 run("$openafsdirpath->{'afssrvbindir'}/fs sa /afs/$lcell system:anyuser rl");
191 run ("$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/.$lcell root.cell -cell $lcell -rw");
192 unwind ("$openafsdirpath->{'afssrvbindir'}/fs rmm /afs/.$lcell");
193 run("$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/.root.afs root.afs -rw");
194 unwind ("$openafsdirpath->{'afssrvbindir'}/fs rmm /afs/.root.afs");
196 mkvol( "user", "/afs/$lcell/user" );
197 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part user -localauth ");
199 mkvol( "service", "/afs/$lcell/service" );
200 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part service -localauth ");
202 mkvol( "rep", "/afs/$lcell/.replicated" );
203 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part rep -localauth ");
204 run( "$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/$lcell/replicated rep.readonly " );
206 run( "$openafsdirpath->{'afssrvsbindir'}/vos addsite $server $part rep -localauth" );
207 run( "$openafsdirpath->{'afssrvsbindir'}/vos release rep -localauth" );
208 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part rep.readonly -localauth ");
210 mkvol( "unrep", "/afs/$lcell/unreplicated" );
211 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part unrep -localauth ");
213 $lcell =~ /^([^.]*)/;
215 run("ln -s /afs/$lcell /afs/$cellpart");
216 unwind ("rm /afs/$cellpart");
217 run( "ln -s /afs/.$lcell /afs/.$cellpart" );
218 unwind ("rm /afs/.$cellpart");
220 run( "$openafsdirpath->{'afssrvsbindir'}/vos addsite $server $part root.afs -localauth" );
221 run( "$openafsdirpath->{'afssrvsbindir'}/vos addsite $server $part root.cell -localauth" );
222 run( "$openafsdirpath->{'afssrvsbindir'}/vos release root.afs -localauth" );
223 run( "$openafsdirpath->{'afssrvsbindir'}/vos release root.cell -localauth" );
224 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part root.cell.readonly -localauth ");
225 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part root.afs.readonly -localauth ");
227 system ("pagsh -c './test-front.sh $lcell'");
231 # If we fail before all the instances are created, we need to perform
232 # our own bos shutdown
233 system("$openafsdirpath->{'afssrvbindir'}/bos shutdown $server -localauth") if $shutdown_needed;
234 run(pop @unwinds) while @unwinds;