aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS6
-rw-r--r--README4
-rw-r--r--perl/Wallet/Admin.pm29
-rw-r--r--perl/Wallet/Schema.pm2
-rwxr-xr-xperl/t/admin.t7
-rwxr-xr-xserver/wallet-admin11
-rwxr-xr-xtests/server/admin-t22
7 files changed, 69 insertions, 12 deletions
diff --git a/NEWS b/NEWS
index c11bff9..9e2fa3b 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,11 @@
User-Visible wallet Changes
+wallet 1.0 (unreleased)
+
+ wallet-admin has a new sub-command, upgrade, which upgrades the wallet
+ database to the latest schema version. This command should be run
+ when deploying any new version of the wallet server.
+
wallet 0.12 (2010-08-25)
New client program wallet-rekey that, given a list of keytabs on the
diff --git a/README b/README
index 5eae7fd..c981272 100644
--- a/README
+++ b/README
@@ -131,6 +131,10 @@ BUILD AND INSTALLATION
make
make install
+ If you are upgrading the wallet server from an earlier installed
+ version, run wallet-admin upgrade after installation to upgrade the
+ database schema. See the wallet-admin manual page for more information.
+
Pass --enable-silent-rules to configure for a quieter build (similar to
the Linux kernel). Use make warnings instead of make to build with full
GCC compiler warnings (requires a relatively current version of GCC).
diff --git a/perl/Wallet/Admin.pm b/perl/Wallet/Admin.pm
index f208e13..8fb49af 100644
--- a/perl/Wallet/Admin.pm
+++ b/perl/Wallet/Admin.pm
@@ -1,7 +1,8 @@
# Wallet::Admin -- Wallet system administrative interface.
#
# Written by Russ Allbery <rra@stanford.edu>
-# Copyright 2008, 2009, 2010 Board of Trustees, Leland Stanford Jr. University
+# Copyright 2008, 2009, 2010, 2011
+# The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.
@@ -22,7 +23,7 @@ use Wallet::Schema;
# This version should be increased on any code change to this module. Always
# use two digits for the minor version with a leading zero if necessary so
# that it will sort properly.
-$VERSION = '0.05';
+$VERSION = '0.06';
##############################################################################
# Constructor, destructor, and accessors
@@ -110,6 +111,19 @@ sub destroy {
return 1;
}
+# Upgrade the database to the latest schema version. Returns true on success
+# and false on failure.
+sub upgrade {
+ my ($self) = @_;
+ my $schema = Wallet::Schema->new;
+ eval { $schema->upgrade ($self->{dbh}) };
+ if ($@) {
+ $self->error ($@);
+ return;
+ }
+ return 1;
+}
+
##############################################################################
# Object registration
##############################################################################
@@ -204,12 +218,12 @@ failure to get the error message.
=over 4
-=item destroy()
+=item destroy ()
Destroys the database, deleting all of its data and all of the tables used
by the wallet server. Returns true on success and false on failure.
-=item error()
+=item error ()
Returns the error of the last failing operation or undef if no operations
have failed. Callers should call this function to get the error message
@@ -240,7 +254,7 @@ Register in the database a mapping from the ACL scheme SCHEME to the class
CLASS. Returns true on success and false on failure (including when the
verifier is already registered).
-=item reinitialize(PRINCIPAL)
+=item reinitialize (PRINCIPAL)
Performs the same actions as initialize(), but first drops any existing
wallet database tables from the database, allowing this function to be
@@ -249,6 +263,11 @@ be deleted and a fresh set of wallet database tables will be created.
This method is equivalent to calling destroy() followed by initialize().
Returns true on success and false on failure.
+=item upgrade ()
+
+Upgrades the database to the latest schema version, preserving data as
+much as possible. Returns true on success and false on failure.
+
=back
=head1 SEE ALSO
diff --git a/perl/Wallet/Schema.pm b/perl/Wallet/Schema.pm
index 911d7a9..0f6c53f 100644
--- a/perl/Wallet/Schema.pm
+++ b/perl/Wallet/Schema.pm
@@ -126,7 +126,7 @@ sub _schema_version {
eval {
my $sql = 'select md_version from metadata';
my $result = $dbh->selectrow_arrayref ($sql);
- $version = $result->[0][0];
+ $version = $result->[0];
};
if ($@) {
$version = 0;
diff --git a/perl/t/admin.t b/perl/t/admin.t
index 074dbc6..6250f8e 100755
--- a/perl/t/admin.t
+++ b/perl/t/admin.t
@@ -3,11 +3,12 @@
# Tests for wallet administrative interface.
#
# Written by Russ Allbery <rra@stanford.edu>
-# Copyright 2008, 2009, 2010 Board of Trustees, Leland Stanford Jr. University
+# Copyright 2008, 2009, 2010, 2011
+# The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.
-use Test::More tests => 16;
+use Test::More tests => 18;
use Wallet::Admin;
use Wallet::Report;
@@ -24,6 +25,8 @@ is ($@, '', 'Wallet::Admin creation did not die');
ok ($admin->isa ('Wallet::Admin'), ' and returned the right class');
is ($admin->initialize ('admin@EXAMPLE.COM'), 1,
' and initialization succeeds');
+is ($admin->upgrade, 1, ' and upgrade succeeds (should do nothing)');
+is ($admin->error, undef, ' and there is no error');
# We have an empty database, so we should see no objects and one ACL.
my $report = Wallet::Report->new;
diff --git a/server/wallet-admin b/server/wallet-admin
index f81c195..fbab72b 100755
--- a/server/wallet-admin
+++ b/server/wallet-admin
@@ -3,7 +3,8 @@
# wallet-admin -- Wallet server administrative commands.
#
# Written by Russ Allbery <rra@stanford.edu>
-# Copyright 2008, 2009, 2010 Board of Trustees, Leland Stanford Jr. University
+# Copyright 2008, 2009, 2010, 2011
+# The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.
@@ -56,6 +57,9 @@ sub command {
} else {
die "only object or verifier is supported for register\n";
}
+ } elsif ($command eq 'upgrade') {
+ die "too many arguments to upgrade\n" if @args;
+ $admin->upgrade or die $admin->error, "\n";
} else {
die "unknown command $command\n";
}
@@ -133,6 +137,11 @@ default as part of database initialization, so this command is used
primarily to register local implementations of additional object types or
ACL schemes.
+=item upgrade
+
+Upgrades the database to the latest schema version, preserving data as
+much as possible.
+
=back
=head1 SEE ALSO
diff --git a/tests/server/admin-t b/tests/server/admin-t
index 5bde104..6846609 100755
--- a/tests/server/admin-t
+++ b/tests/server/admin-t
@@ -3,12 +3,13 @@
# Tests for the wallet-admin dispatch code.
#
# Written by Russ Allbery <rra@stanford.edu>
-# Copyright 2008, 2009, 2010 Board of Trustees, Leland Stanford Jr. University
+# Copyright 2008, 2009, 2010, 2011
+# The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.
use strict;
-use Test::More tests => 36;
+use Test::More tests => 42;
# Create a dummy class for Wallet::Admin that prints what method was called
# with its arguments and returns data for testing.
@@ -57,6 +58,12 @@ sub register_verifier {
return 1;
}
+sub upgrade {
+ print "upgrade\n";
+ return if $error;
+ return 1;
+}
+
# Back to the main package and the actual test suite. Lie about whether the
# Wallet::Admin package has already been loaded.
package main;
@@ -86,7 +93,8 @@ is ($out, "new\n", ' and nothing ran');
# Check too few and too many arguments for every command.
my %commands = (destroy => [0, 0],
initialize => [1, 1],
- register => [3, 3]);
+ register => [3, 3],
+ upgrade => [0, 0]);
for my $command (sort keys %commands) {
my ($min, $max) = @{ $commands{$command} };
if ($min > 0) {
@@ -150,6 +158,11 @@ is ($err, '', 'Register succeeds for verifier');
is ($out, "new\nregister_verifier foo Foo::Verifier\n",
' and returns the right outout');
+# Test upgrade.
+($out, $err) = run_admin ('upgrade');
+is ($err, '', 'Upgrade succeeds');
+is ($out, "new\nupgrade\n", ' and runs the right code');
+
# Test error handling.
$Wallet::Admin::error = 1;
($out, $err) = run_admin ('destroy');
@@ -169,3 +182,6 @@ is ($out, "new\nregister_object foo Foo::Object\n",
is ($err, "some error\n", 'Error handling succeeds for register verifier');
is ($out, "new\nregister_verifier foo Foo::Verifier\n",
' and calls the right methods');
+($out, $err) = run_admin ('upgrade');
+is ($err, "some error\n", 'Error handling succeeds for initialize');
+is ($out, "new\nupgrade\n", ' and calls the right methods');