test-suite-update-20020115
[openafs.git] / src / tests / run-suite.pl
1 #!/usr/bin/env perl
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.
5
6 use Term::ReadLine;
7 use strict;
8 use OpenAFS::ConfigUtils;
9 use OpenAFS::Dirpath;
10 use OpenAFS::OS;
11 use OpenAFS::Auth;
12 use Getopt::Long;
13 use vars qw($admin $server $cellname $cachesize $part
14           $shutdown_needed $csdb);
15 my $rl = new Term::ReadLine('run-suite');
16
17 =head1  NAME
18
19    run-suite - Set up AFS cell and test.
20
21 =head1 SYNOPSIS
22
23 B<run-suite> [B<--cellname> cellname] [B<--cachesize> size]
24
25 =head1 DESCRIPTION
26
27
28 This script sets up an AFS cell, then runs a suite of tests against the 
29 cell to verify the build.
30
31 The B<cellname> option specifies the name of the cell.
32
33 The B<cachesize> option specifies the size of the AFS cache.
34
35 =cut
36
37 # main script
38
39 # mkvol(volume, mount)
40 sub mkvol($$) {
41     my ($vol, $mnt) = @_;
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");
46 }
47
48 GetOptions (
49            "cellname=s" => \$cellname, 
50            "cachesize=s" => \$cachesize,
51            "partition=s" => \$part,
52            "admin=s" => \$admin);
53
54 if ($> != 0) {
55   die "This script should almost always be run as root.\n";
56 }
57
58 open(MOUNT, "mount |") or die "Failed to run mount: $!\n";
59 while(<MOUNT>) {
60   if(m:^AFS:) {
61     print "The AFS client is currently running on this workstation.\n";
62     print "Please restart this script after running $openafsinitcmd->{'client-stop'}\n";
63     exit(1);
64   }
65   if(m:^/afs on AFS:) {
66     print "The AFS client is currently running on this workstation.\n";
67     print "Please restart this script after running $openafsinitcmd->{'client-stop'}\n";
68     exit(1);
69   }
70 }
71 close MOUNT;
72
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";
76   exit(1);
77 }
78
79 print "If the fileserver is not running, this may hang for 30 seconds.\n";
80 run("$openafsinitcmd->{'filesrv-stop'}");
81 $server = `hostname`;
82 chomp $server;
83 $admin = "admin" unless $admin;
84 $admin =~ s:/:.:g;
85 if($admin =~ /@/) {
86 die "The administrative user must be in the same realm as the cell and no realm may be specified.\n";
87 }
88
89 $cellname = $rl->readline("What cellname should be used? ") unless $cellname;
90 die "Please specify a cellname\n" unless $cellname;
91
92 if (! -f "$openafsdirpath->{'afsconfdir'}/ThisCell") {
93     open(CELL, "> $openafsdirpath->{'afsconfdir'}/ThisCell");
94     print CELL "${cellname}";
95     close CELL;
96 }
97
98 open(CELL, "$openafsdirpath->{'afsconfdir'}/ThisCell") or
99     die "Cannot open $openafsdirpath->{'afsconfdir'}/ThisCell: $!\n";
100
101 my $lcell = <CELL>;
102 chomp $lcell;
103 close CELL;
104
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";
116  }
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";
122 close PRDB;
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");
128
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");
132
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");
139
140 print "Waiting for database elections: ";
141 sleep(30);
142 print "done.\n";
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");
147 # bring up client
148
149 $cachesize = $rl->readline("What size cache (in 1k blocks)? ") unless $cachesize;
150 die "Please specify a cache size\n" unless $cachesize;
151
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'}");
156 my $afs_running = 0;
157 open(MOUNT, "mount |") or die "Failed to run mount: $!\n";
158 while(<MOUNT>) {
159 if(m:^AFS:) {
160        $afs_running = 1;
161 }
162        }
163 unless ($afs_running) {
164 print "*** The AFS client failed to start.\n";
165 print  "Please fix whatever problem kept it from running.\n";
166        exit(1);
167 }
168 unwind("$openafsinitcmd->{'client-stop'}");
169
170 $part = "a" unless $part;
171
172 &OpenAFS::Auth::authadmin();
173
174 run("$openafsdirpath->{'afssrvbindir'}/fs sa /afs system:anyuser rl");
175
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
179 # loop.
180 open(CELLSERVDB, "$openafsdirpath->{'viceetcdir'}/CellServDB")
181     or die "Unable to open $openafsdirpath->{'viceetcdir'}/CellServDB: $!\n";
182 while(<CELLSERVDB>) {
183     chomp;
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");
187    }
188 }
189
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");
195
196 mkvol( "user", "/afs/$lcell/user" );
197 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part user -localauth ");
198
199 mkvol( "service", "/afs/$lcell/service" );
200 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part service -localauth ");
201
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 " );
205
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 ");
209
210 mkvol( "unrep", "/afs/$lcell/unreplicated" );
211 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part unrep -localauth ");
212
213 $lcell =~ /^([^.]*)/;
214 my $cellpart = $1;
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");
219
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 ");
226
227 system ("pagsh -c './test-front.sh $lcell'");
228
229 @unwinds = ();
230 END {
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;
235   }
236