35b7619f4c37e13f6682c2553d91684d278642d0
[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 unlink "$openafsdirpath->{'viceetcdir'}/CellServDB";
93 unlink "$openafsdirpath->{'viceetcdir'}/ThisCell";
94
95 my $lcell = "${cellname}";
96
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";
107  }
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";
113 close PRDB;
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");
119
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");
123
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");
131
132 print "Waiting for database elections: ";
133 sleep(90);
134 print "done.\n";
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");
139 # bring up client
140
141 $cachesize = $rl->readline("What size cache (in 1k blocks)? ") unless $cachesize;
142 die "Please specify a cache size\n" unless $cachesize;
143
144 mkdir "/usr/vice/cache", 0700;
145 mkdir "/afs", 0777;
146
147 run("echo /afs:/usr/vice/cache:${cachesize} >$openafsdirpath->{'viceetcdir'}/cacheinfo");
148 run("$openafsinitcmd->{'client-forcestart'}");
149 my $afs_running = 0;
150 open(MOUNT, "mount |") or die "Failed to run mount: $!\n";
151 while(<MOUNT>) {
152 if(m:^AFS:) {
153        $afs_running = 1;
154 }
155        }
156 unless ($afs_running) {
157 print "*** The AFS client failed to start.\n";
158 print  "Please fix whatever problem kept it from running.\n";
159        exit(1);
160 }
161 unwind("$openafsinitcmd->{'client-stop'}");
162
163 $part = "a" unless $part;
164
165 &OpenAFS::Auth::authadmin();
166
167 run("$openafsdirpath->{'afssrvbindir'}/fs sa /afs system:anyuser rl");
168
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
172 # loop.
173 open(CELLSERVDB, "$openafsdirpath->{'viceetcdir'}/CellServDB")
174     or die "Unable to open $openafsdirpath->{'viceetcdir'}/CellServDB: $!\n";
175 while(<CELLSERVDB>) {
176     chomp;
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");
180    }
181 }
182
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");
188
189 mkvol( "user", "/afs/$lcell/user" );
190 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part user -localauth ");
191
192 mkvol( "service", "/afs/$lcell/service" );
193 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part service -localauth ");
194
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 " );
198
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 ");
202
203 mkvol( "unrep", "/afs/$lcell/unreplicated" );
204 unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part unrep -localauth ");
205
206 $lcell =~ /^([^.]*)/;
207 my $cellpart = $1;
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");
212
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 ");
219
220 run("$openafsinitcmd->{'client-restart'}");
221
222 system ("pagsh -c './test-front.sh $lcell'");
223
224 @unwinds = ();
225 END {
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;
230   }
231