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 unlink "$openafsdirpath->{'viceetcdir'}/CellServDB";
93 unlink "$openafsdirpath->{'viceetcdir'}/ThisCell";
95 my $lcell = "${cellname}";
97 #let bosserver create symlinks
98 run("$openafsinitcmd->{'filesrv-start'}");
99 unwind("$openafsinitcmd->{'filesrv-stop'}");
100 $shutdown_needed = 1;
101 run ("$openafsdirpath->{'afssrvbindir'}/bos setcellname $server $lcell -localauth ||true");
102 run ("$openafsdirpath->{'afssrvbindir'}/bos addhost $server $server -localauth ||true");
103 run("$openafsdirpath->{'afssrvbindir'}/bos adduser $server $admin -localauth");
104 unwind("$openafsdirpath->{'afssrvbindir'}/bos removeuser $server $admin -localauth");
105 if ( -f "$openafsdirpath->{'afsdbdir'}/prdb.DB0" ) {
106 die "Protection database already exists; cell already partially created\n";
108 open(PRDB, "|$openafsdirpath->{'afssrvsbindir'}/pt_util -p $openafsdirpath->{'afsdbdir'}/prdb.DB0 -w ")
109 or die "Unable to start pt_util: $!\n";
110 print PRDB "$admin 128/20 1 -204 -204\n";
111 print PRDB "system:administrators 130/20 -204 -204 -204\n";
112 print PRDB" $admin 1\n";
114 unwind( "rm $openafsdirpath->{'afsdbdir'}/prdb* ");
115 # Start up ptserver and vlserver
116 run("$openafsdirpath->{'afssrvbindir'}/bos create $server ptserver simple $openafsdirpath->{'afssrvlibexecdir'}/ptserver -localauth");
117 unwind("$openafsdirpath->{'afssrvbindir'}/bos delete $server ptserver -localauth");
118 unwind("$openafsdirpath->{'afssrvbindir'}/bos stop $server ptserver -localauth -wait");
120 run("$openafsdirpath->{'afssrvbindir'}/bos create $server vlserver simple $openafsdirpath->{'afssrvlibexecdir'}/vlserver -localauth");
121 unwind("$openafsdirpath->{'afssrvbindir'}/bos delete $server vlserver -localauth");
122 unwind("$openafsdirpath->{'afssrvbindir'}/bos stop $server vlserver -localauth -wait");
124 run( "$openafsdirpath->{'afssrvbindir'}/bos create $server fs fs ".
125 "-cmd $openafsdirpath->{'afssrvlibexecdir'}/fileserver ".
126 "-cmd $openafsdirpath->{'afssrvlibexecdir'}/volserver ".
127 "-cmd $openafsdirpath->{'afssrvlibexecdir'}/salvager -localauth");
128 unwind( "$openafsdirpath->{'afssrvbindir'}/bos delete $server fs -localauth ");
129 unwind( "$openafsdirpath->{'afssrvbindir'}/bos stop $server fs -localauth -wait");
130 run("$openafsdirpath->{'afssrvbindir'}/bos restart $server -all -bosserver -localauth");
132 print "Waiting for database elections: ";
135 # Past this point we want to control when bos shutdown happens
136 $shutdown_needed = 0;
137 unwind( "$openafsdirpath->{'afssrvbindir'}/bos shutdown $server -localauth ");
138 run("$openafsdirpath->{'afssrvsbindir'}/vos create $server a root.afs -localauth");
141 $cachesize = $rl->readline("What size cache (in 1k blocks)? ") unless $cachesize;
142 die "Please specify a cache size\n" unless $cachesize;
144 mkdir "/usr/vice/cache", 0700;
146 run("echo /afs:/usr/vice/cache:${cachesize} >$openafsdirpath->{'viceetcdir'}/cacheinfo");
147 run("$openafsinitcmd->{'client-forcestart'}");
149 open(MOUNT, "mount |") or die "Failed to run mount: $!\n";
155 unless ($afs_running) {
156 print "*** The AFS client failed to start.\n";
157 print "Please fix whatever problem kept it from running.\n";
160 unwind("$openafsinitcmd->{'client-stop'}");
162 $part = "a" unless $part;
164 &OpenAFS::Auth::authadmin();
166 run("$openafsdirpath->{'afssrvbindir'}/fs sa /afs system:anyuser rl");
168 run("$openafsdirpath->{'afssrvsbindir'}/vos create $server $part root.cell -localauth");
169 unwind("$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part root.cell -localauth");
170 # We make root.cell s:anyuser readable after we mount in the next
172 open(CELLSERVDB, "$openafsdirpath->{'viceetcdir'}/CellServDB")
173 or die "Unable to open $openafsdirpath->{'viceetcdir'}/CellServDB: $!\n";
174 while(<CELLSERVDB>) {
176 if (/^>\s*([a-z0-9_\-.]+)/ ) {
177 run("$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/$1 root.cell -cell $1 -fast");
178 unwind ("$openafsdirpath->{'afssrvbindir'}/fs rmm /afs/$1");
182 run("$openafsdirpath->{'afssrvbindir'}/fs sa /afs/$lcell system:anyuser rl");
183 run ("$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/.$lcell root.cell -cell $lcell -rw");
184 unwind ("$openafsdirpath->{'afssrvbindir'}/fs rmm /afs/.$lcell");
185 run("$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/.root.afs root.afs -rw");
186 unwind ("$openafsdirpath->{'afssrvbindir'}/fs rmm /afs/.root.afs");
188 mkvol( "user", "/afs/$lcell/user" );
189 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part user -localauth ");
191 mkvol( "service", "/afs/$lcell/service" );
192 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part service -localauth ");
194 mkvol( "rep", "/afs/$lcell/.replicated" );
195 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part rep -localauth ");
196 run( "$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/$lcell/replicated rep.readonly " );
198 run( "$openafsdirpath->{'afssrvsbindir'}/vos addsite $server $part rep -localauth" );
199 run( "$openafsdirpath->{'afssrvsbindir'}/vos release rep -localauth" );
200 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part rep.readonly -localauth ");
202 mkvol( "unrep", "/afs/$lcell/unreplicated" );
203 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part unrep -localauth ");
205 $lcell =~ /^([^.]*)/;
207 run("ln -s /afs/$lcell /afs/$cellpart");
208 unwind ("rm /afs/$cellpart");
209 run( "ln -s /afs/.$lcell /afs/.$cellpart" );
210 unwind ("rm /afs/.$cellpart");
212 run( "$openafsdirpath->{'afssrvsbindir'}/vos addsite $server $part root.afs -localauth" );
213 run( "$openafsdirpath->{'afssrvsbindir'}/vos addsite $server $part root.cell -localauth" );
214 run( "$openafsdirpath->{'afssrvsbindir'}/vos release root.afs -localauth" );
215 run( "$openafsdirpath->{'afssrvsbindir'}/vos release root.cell -localauth" );
216 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part root.cell.readonly -localauth ");
217 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part root.afs.readonly -localauth ");
219 run("$openafsinitcmd->{'client-restart'}");
221 system ("pagsh -c './test-front.sh $lcell'");
225 # If we fail before all the instances are created, we need to perform
226 # our own bos shutdown
227 system("$openafsdirpath->{'afssrvbindir'}/bos shutdown $server -localauth") if $shutdown_needed;
228 run(pop @unwinds) while @unwinds;