Commit e42f812d authored by Robert Ricci's avatar Robert Ricci

New script: schemacheck - Checks to see if the currently-running database

matches the one in the checked-out source.

This now gets called as part of the 'boss-install' target, to guard
against installing software that is out-of-sync with the running
database. It is skipped if @prefix@ is not /usr/testbed, to avoid
getting in the way of development.

If you want to bypass this check, use the 'boss-install-force' target.
Use of this, however, is not recommended.
parent 52854f15
......@@ -21,7 +21,13 @@ install:
#
# For installation on boss node (okay, paper).
#
boss-install: install-subdirs install-mkdirs
boss-install: install-schemacheck install-subdirs install-mkdirs
@echo "DON'T FORGET TO RUN A POST-INSTALL AS ROOT"
#
# Same target, with the install-schemacheck dependency omitted
#
boss-install-force: install-subdirs install-mkdirs
@echo "DON'T FORGET TO RUN A POST-INSTALL AS ROOT"
post-install:
......@@ -58,6 +64,19 @@ tipserv-install:
@$(MAKE) -C capture tipserv-install
@$(MAKE) -C tbsetup tipserv-install
#
# A check to see if this is a 'real' install. Kinda hacky, but as far as I can
# tell, you can't put ifeq()'s inside of targets
#
ifeq ($(TBROOT),/usr/testbed)
SCHEMACHECK= perl $(OBJDIR)/db/schemacheck
else
SCHEMACHECK= @echo "Skipping schema check, since prefix isn't /usr/testbed"
endif
install-schemacheck:
@echo "Checking DB schema..."
$(SCHEMACHECK)
clean: clean-subdirs
distclean: distclean-subdirs
rm -f Makeconf GNUmakefile config.status config.cache config.log
......
......@@ -1180,7 +1180,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
discvr/GNUmakefile \
db/libdb.pm db/inuse db/avail db/nodeip db/showgraph \
db/dhcpd_makeconf db/nodelog db/webnodelog db/unixgroups \
db/dbcheck db/interswitch db/dbboot \
db/dbcheck db/interswitch db/dbboot db/schemacheck \
ipod/GNUmakefile \
lib/GNUmakefile lib/libtb/GNUmakefile \
os/GNUmakefile os/split-image.sh os/imagezip/GNUmakefile \
......
......@@ -252,7 +252,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
discvr/GNUmakefile \
db/libdb.pm db/inuse db/avail db/nodeip db/showgraph \
db/dhcpd_makeconf db/nodelog db/webnodelog db/unixgroups \
db/dbcheck db/interswitch db/dbboot \
db/dbcheck db/interswitch db/dbboot db/schemacheck \
ipod/GNUmakefile \
lib/GNUmakefile lib/libtb/GNUmakefile \
os/GNUmakefile os/split-image.sh os/imagezip/GNUmakefile \
......
#!/usr/bin/perl -w
use strict;
#
# schemacheck - Make sure that the scehma in the currently-running database
# matches the one in the checked-out source. Exits with value 1 if the two
# differ, 0 if they do not, and -1 if some error (such as the mysql server is
# not running, or the database does not exist) prevents us from telling if
# they differ or not
#
#
# Configure variables
#
my $testbed_srcdir = "@top_srcdir@";
my $DBNAME = "@TBDBNAME@";
my $master_schema = "$testbed_srcdir/sql/database-create.sql";
my $schemadiff = "$testbed_srcdir/utils/schemadiff";
#
# XXX: Requires that mysqldump be in caller's $PATH - probably an OK
# assumption, but maybe not always
#
my $mysqldump = "mysqldump $DBNAME";
#
# We use Mysql module instead of the tesbed libraries, so that we can get
# a more precise feel for what the error is.
#
use Mysql;
#
# Check to see if the mysqld is running by trying to connect to it.
#
my $dbh = Mysql->connect(undef,undef,undef,undef);
if (!$dbh) {
fatal("Unable to connect to mysqld - Either it's not running or \n" .
"permission was denied.\n");
}
#
# Check to see if the database exists
#
my @dbs = $dbh->listdbs();
if (! grep (/^$DBNAME$/,@dbs)) {
fatal("Database $DBNAME does not exist in the running database\n");
}
undef $dbh;
#
# Make sure we can write the temporary file
#
my $db_schema = "/tmp/schemacheck.$$";
open(SCHEMAFILE,">$db_schema") or
fatal("Unable to write to temporary file $db_schema: $!\n");
close(SCHEMAFILE);
#
# Stick the output of mysqldump into a file
#
system "$mysqldump 2> /dev/null > $db_schema";
#
# ... and compare it to the schema from the source
#
my $diff = (system("$schemadiff -q $db_schema $master_schema") >> 8);
unlink($db_schema);
if ($diff) {
print << "EOSTR";
The schema from $master_schema differs from
the running database. As a safety measure, you will not be able to install
until this is resolved.
If you are a user of the emulab software outside of Utah, this is probably
because your database was created for an older version of the emulab software.
Contact emulab-ops\@emulab.net for help in updating your database.
If you're a developer at Utah, this is probably because you (or someone else)
forgot to update sql/database-create.sql .
EOSTR
exit(1);
} else {
exit(0);
}
sub fatal(@) {
# Offset the text with a few blank lines, so it doesn't get lost in the
# make messages
warn "\n\n";
warn "*** schemacheck - Unable to check database schema:\n";
warn @_;
warn "\n\n";
exit(-1);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment