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;
147 run("echo /afs:/usr/vice/cache:${cachesize} >$openafsdirpath->{'viceetcdir'}/cacheinfo");
148 run("$openafsinitcmd->{'client-forcestart'}");
150 open(MOUNT, "mount |") or die "Failed to run mount: $!\n";
156 unless ($afs_running) {
157 print "*** The AFS client failed to start.\n";
158 print "Please fix whatever problem kept it from running.\n";
161 unwind("$openafsinitcmd->{'client-stop'}");
163 $part = "a" unless $part;
165 &OpenAFS::Auth::authadmin();
167 run("$openafsdirpath->{'afssrvbindir'}/fs sa /afs system:anyuser rl");
169 run("$openafsdirpath->{'afssrvsbindir'}/vos create $server $part root.cell -localauth");
170 unwind("$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part root.cell -localauth");
171 # We make root.cell s:anyuser readable after we mount in the next
173 open(CELLSERVDB, "$openafsdirpath->{'viceetcdir'}/CellServDB")
174 or die "Unable to open $openafsdirpath->{'viceetcdir'}/CellServDB: $!\n";
175 while(<CELLSERVDB>) {
177 if (/^>\s*([a-z0-9_\-.]+)/ ) {
178 run("$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/$1 root.cell -cell $1 -fast");
179 unwind ("$openafsdirpath->{'afssrvbindir'}/fs rmm /afs/$1");
183 run("$openafsdirpath->{'afssrvbindir'}/fs sa /afs/$lcell system:anyuser rl");
184 run ("$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/.$lcell root.cell -cell $lcell -rw");
185 unwind ("$openafsdirpath->{'afssrvbindir'}/fs rmm /afs/.$lcell");
186 run("$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/.root.afs root.afs -rw");
187 unwind ("$openafsdirpath->{'afssrvbindir'}/fs rmm /afs/.root.afs");
189 mkvol( "user", "/afs/$lcell/user" );
190 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part user -localauth ");
192 mkvol( "service", "/afs/$lcell/service" );
193 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part service -localauth ");
195 mkvol( "rep", "/afs/$lcell/.replicated" );
196 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part rep -localauth ");
197 run( "$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/$lcell/replicated rep.readonly " );
199 run( "$openafsdirpath->{'afssrvsbindir'}/vos addsite $server $part rep -localauth" );
200 run( "$openafsdirpath->{'afssrvsbindir'}/vos release rep -localauth" );
201 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part rep.readonly -localauth ");
203 mkvol( "unrep", "/afs/$lcell/unreplicated" );
204 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part unrep -localauth ");
206 $lcell =~ /^([^.]*)/;
208 run("ln -s /afs/$lcell /afs/$cellpart");
209 unwind ("rm /afs/$cellpart");
210 run( "ln -s /afs/.$lcell /afs/.$cellpart" );
211 unwind ("rm /afs/.$cellpart");
213 run( "$openafsdirpath->{'afssrvsbindir'}/vos addsite $server $part root.afs -localauth" );
214 run( "$openafsdirpath->{'afssrvsbindir'}/vos addsite $server $part root.cell -localauth" );
215 run( "$openafsdirpath->{'afssrvsbindir'}/vos release root.afs -localauth" );
216 run( "$openafsdirpath->{'afssrvsbindir'}/vos release root.cell -localauth" );
217 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part root.cell.readonly -localauth ");
218 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part root.afs.readonly -localauth ");
220 run("$openafsinitcmd->{'client-restart'}");
222 system ("pagsh -c './test-front.sh $lcell'");
226 # If we fail before all the instances are created, we need to perform
227 # our own bos shutdown
228 system("$openafsdirpath->{'afssrvbindir'}/bos shutdown $server -localauth") if $shutdown_needed;
229 run(pop @unwinds) while @unwinds;