From: Stephen Morris Date: Mon, 19 Mar 2012 17:07:06 +0000 (+0000) Subject: [963] Miscellaneous changes X-Git-Tag: trac2351_base~226^2~116^2~95^2~2^2~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7e7b44723b80637d14bbbb714b69fe4ef7ea1f9a;p=thirdparty%2Fkea.git [963] Miscellaneous changes 1. Fix minor gremlins in unit test and main program 2. Update to rename b10-dbutil process (and so avoid an error from the process_rename_test check). 3. With (2), add run_dbutil to run in test mode --- diff --git a/configure.ac b/configure.ac index 93667b1e9d..e69c2c7fdd 100644 --- a/configure.ac +++ b/configure.ac @@ -1125,6 +1125,7 @@ AC_OUTPUT([doc/version.ent src/bin/cmdctl/tests/cmdctl_test src/bin/cmdctl/cmdctl.spec.pre src/bin/dbutil/dbutil.py + src/bin/dbutil/run_dbutil.sh src/bin/dbutil/tests/dbutil_test.sh src/bin/ddns/ddns.py src/bin/xfrin/tests/xfrin_test @@ -1209,6 +1210,7 @@ AC_OUTPUT([doc/version.ent chmod +x src/bin/zonemgr/run_b10-zonemgr.sh chmod +x src/bin/bind10/run_bind10.sh chmod +x src/bin/cmdctl/tests/cmdctl_test + chmod +x src/bin/dbutil/run_dbutil.sh chmod +x src/bin/dbutil/tests/dbutil_test.sh chmod +x src/bin/xfrin/tests/xfrin_test chmod +x src/bin/xfrout/tests/xfrout_test diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 7c6cdb8bde..499e2097ec 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -1,4 +1,4 @@ SUBDIRS = bind10 bindctl cfgmgr ddns loadzone msgq host cmdctl auth xfrin \ - xfrout usermgr zonemgr stats tests resolver sockcreator dhcp4 dhcp6 + xfrout usermgr zonemgr stats tests resolver sockcreator dhcp4 dhcp6 dbutil check-recursive: all-recursive diff --git a/src/bin/dbutil/Makefile.am b/src/bin/dbutil/Makefile.am index 5e7a942e79..bf3a4889f5 100644 --- a/src/bin/dbutil/Makefile.am +++ b/src/bin/dbutil/Makefile.am @@ -2,10 +2,14 @@ SUBDIRS = . tests bin_SCRIPTS = b10-dbutil +noinst_SCRIPTS = run_dbutil.sh + CLEANFILES = b10-dbutil b10-dbutil.pyc b10-dbutil: dbutil.py - $(SED) -e "s|@@LOCALSTATEDIR@@|$(localstatedir)|" dbutil.py > $@ + $(SED) -e "s|@@PYTHONPATH@@|@pyexecdir@|" \ + -e "s|@@SYSCONFDIR@@|@sysconfdir@|" \ + -e "s|@@LIBEXECDIR@@|$(pkglibexecdir)|" dbutil.py >$@ chmod a+x $@ CLEANDIRS = __pycache__ diff --git a/src/bin/dbutil/dbutil.py.in b/src/bin/dbutil/dbutil.py.in index 46cd0165fd..f7056ff31a 100755 --- a/src/bin/dbutil/dbutil.py.in +++ b/src/bin/dbutil/dbutil.py.in @@ -33,12 +33,21 @@ # ".backup" already exists). This is used to restore the database if the # upgrade fails. -import os, sqlite3, shutil, sys +import sys; sys.path.append("@@PYTHONPATH@@") +import os, sqlite3, shutil from optparse import OptionParser +import isc.util.process + +isc.util.process.rename() # Default database to use if the database is not given on the command line. # (This is the same string as in "auth.spec.pre.in".) -default_database_file = "@@LOCALSTATEDIR@@/@PACKAGE@/zone.sqlite3" +DEFAULT_DATABASE_FILE = "@@LOCALSTATEDIR@@/@PACKAGE@/zone.sqlite3" + +# This is the version displayed to the user. It comprises the module name, +# the module version number, and the overall BIND 10 version number (set in +# configure.ac) +VERSION = "b10-dbutil 20120319 (BIND 10 @PACKAGE_VERSION@)" # Statements to update the database. # @@ -174,12 +183,53 @@ upgrades = [ class DbutilException(Exception): pass +# Functions for outputting messages in a consistent format. As this is intended +# to be an interactive utility, it was not considered necessary to use the full +# logging framework for messages. + +def output(writer, prefix, text, ex = None): + """ + @brief Write error message to output stream + + @param writer Function to do the writing + @param prefix Prefix to the message + @param text Text to output + @param ex Possible exception holding additiona information + """ + writer(prefix + ": " + text) + if ex is not None: + writer(" - " + str(ex)) + writer("\n") + + +def error(text, ex = None): + """ + @brief Write error message to stderr. + + @param text Text to output + @param ex Possible exception holding additiona information + """ + output(sys.stderr.write, "ERROR", text, ex) + + +def warn(text, ex = None): + """ + @brief Write warning message to stderr. -def info(text): + @param text Text to output + @param ex Possible exception holding additiona information + """ + output(sys.stderr.write, "WARN", text, ex) + + +def info(text, ex = None): """ @brief Write informational message to stdout. + + @param text Text to output + @param ex Possible exception holding additiona information """ - sys.stdout.write("INFO: " + text + "\n") + output(sys.stdout.write, "INFO", text, ex) # @brief Database Encapsulation @@ -294,12 +344,12 @@ def prompt_user(): """ sys.stdout.write( """You have selected the upgrade option. This will upgrade the schema of the -selected BIND 10 database to the latest version. +selected BIND 10 zone database to the latest version. -The utility will take a copy of the database file before running so, in the -unlikely event of a problem, you will be able to restore the database from +The utility will take a copy of the zone database file before executing so, in +the event of a problem, you will be able to restore the zone database from the backup. To ensure that the integrity of this backup, please ensure that -BIND 10 is not running before proceeding. +BIND 10 is not running before continuing. """) yes_entered = False no_entered = False @@ -474,7 +524,7 @@ def parse_command(): """ usage = ("usage: %prog --check [options] [db_file]\n" + " %prog --upgrade [--noconfirm] [options] [db_file]") - parser = OptionParser(usage=usage) + parser = OptionParser(usage = usage, version = VERSION) parser.add_option("-c", "--check", action="store_true", dest="check", default=False, help="Print database version and check if it " + @@ -492,20 +542,20 @@ def parse_command(): # Set the database file on which to operate if (len(args) > 1): - sys.stderr.write(usage + "\n") + error("too many arguments to the command, maximum of one expected") + parser.print_usage() sys.exit(1) elif len(args) == 0: - args.append(default_database_file) + args.append(DEFAULT_DATABASE_FILE) # Check for conflicting options. If some are found, output a suitable # error message and print the usage. if options.check and options.upgrade: - sys.stderr.write("cannot select both --check and --upgrade, " + - "please choose one") + error("--upgrade is not compatible with --check") elif (not options.check) and (not options.upgrade): - sys.stderr.write("must select one of --check or --upgrade") + error("must select one of --check or --upgrade") elif (options.check and options.noconfirm): - sys.stderr.write("--noconfirm is not compatible with --check") + error("--noconfirm is not compatible with --check") else: return (options, args) @@ -525,8 +575,7 @@ if __name__ == "__main__": check_version(db) db.close() except Exception as ex: - sys.stderr.write("ERROR: unable to check database version - " + - str(ex) + "\n") + error("unable to check database version - " + str(ex)) sys.exit(1) elif options.upgrade: @@ -547,15 +596,12 @@ if __name__ == "__main__": db.close() except Exception as ex: if in_progress: - sys.stderr.write("ERROR: upgrade failed - " + str(ex) + "\n") - sys.stderr.write("WARN: database may be corrupt, " + - "restore database from backup\n") + error("upgrade failed - " + str(ex)) + warn("database may be corrupt, restore it from backup") else: - sys.stderr.write("ERROR: upgrade preparation failed - " + - str(ex) + "\n") - sys.stderr.write("INFO: database upgrade was not attempted\n") + error("upgrade preparation failed - " + str(ex)) + info("database upgrade was not attempted") sys.exit(1) else: - sys.stderr.write("ERROR: internal error, neither --check nor " + - " --upgrade selected") + error("internal error, neither --check nor --upgrade selected") sys.exit(1) diff --git a/src/bin/dbutil/run_dbutil.sh.in b/src/bin/dbutil/run_dbutil.sh.in new file mode 100755 index 0000000000..eaf4b0e915 --- /dev/null +++ b/src/bin/dbutil/run_dbutil.sh.in @@ -0,0 +1,41 @@ +#! /bin/sh + +# Copyright (C) 2010 Internet Systems Consortium. +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM +# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING +# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION +# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +PYTHON_EXEC=${PYTHON_EXEC:-@PYTHON@} +export PYTHON_EXEC + +DBUTIL_PATH=@abs_top_builddir@/src/bin/dbutil + +PYTHONPATH=@abs_top_srcdir@/src/bin:@abs_top_builddir@/src/lib/python/isc/log_messages:@abs_top_builddir@/src/lib/python:@abs_top_builddir@/src/bin:@abs_top_srcdir@/src/lib/python +export PYTHONPATH + +# If necessary (rare cases), explicitly specify paths to dynamic libraries +# required by loadable python modules. +SET_ENV_LIBRARY_PATH=@SET_ENV_LIBRARY_PATH@ +if test $SET_ENV_LIBRARY_PATH = yes; then + @ENV_LIBRARY_PATH@=@abs_top_builddir@/src/lib/dns/.libs:@abs_top_builddir@/src/lib/dns/python/.libs:@abs_top_builddir@/src/lib/cryptolink/.libs:@abs_top_builddir@/src/lib/cc/.libs:@abs_top_builddir@/src/lib/config/.libs:@abs_top_builddir@/src/lib/log/.libs:@abs_top_builddir@/src/lib/util/.libs:@abs_top_builddir@/src/lib/util/io/.libs:@abs_top_builddir@/src/lib/exceptions/.libs:@abs_top_builddir@/src/lib/datasrc/.libs:$@ENV_LIBRARY_PATH@ + export @ENV_LIBRARY_PATH@ +fi + +B10_FROM_SOURCE=@abs_top_srcdir@ +export B10_FROM_SOURCE + +BIND10_MSGQ_SOCKET_FILE=@abs_top_builddir@/msgq_socket +export BIND10_MSGQ_SOCKET_FILE + +cd ${DBUTIL_PATH} +exec ${PYTHON_EXEC} -O b10-dbutil "$@" diff --git a/src/bin/dbutil/tests/dbutil_test.sh.in b/src/bin/dbutil/tests/dbutil_test.sh.in index e30e2b7dba..2b35c9f97c 100755 --- a/src/bin/dbutil/tests/dbutil_test.sh.in +++ b/src/bin/dbutil/tests/dbutil_test.sh.in @@ -147,7 +147,7 @@ get_schema() { # @param $1 Database to upgrade upgrade_ok_test() { cp $1 $tempfile - ../b10-dbutil --upgrade --noconfirm $tempfile + ../run_dbutil.sh --upgrade --noconfirm $tempfile if [ $? -eq 0 ] then # Compare schema with the reference @@ -188,7 +188,7 @@ record_count_test() { records_count=`sqlite3 $tempfile 'select count(*) from records'` zones_count=`sqlite3 $tempfile 'select count(*) from zones'` - ../b10-dbutil --upgrade --noconfirm $tempfile + ../run_dbutil.sh --upgrade --noconfirm $tempfile if [ $? -ne 0 ] then # Reason for failure should already have been output @@ -234,12 +234,12 @@ record_count_test() { # @param $2 Expected version string check_version() { cp $1 $verfile - ../b10-dbutil --check $verfile + ../run_dbutil.sh --check $verfile if [ $? -ne 0 ] then fail "version check failed on database $1" else - ../b10-dbutil --check $verfile | grep "$2" + ../run_dbutil.sh --check $verfile | grep "$2" > /dev/null if [ $? -ne 0 ] then fail "database $1 not at expected version $2" @@ -257,12 +257,12 @@ rm -f $tempfile $backupfile # Test 1 - check that the utility fails if the database does not exist echo "1.1. Non-existent database - check" -../b10-dbutil --check $tempfile +../run_dbutil.sh --check $tempfile failzero $? check_no_backup $tempfile $backupfile echo "1.2. Non-existent database - upgrade" -../b10-dbutil --upgrade --noconfirm $tempfile +../run_dbutil.sh --upgrade --noconfirm $tempfile failzero $? check_no_backup $tempfile $backupfile rm -f $tempfile $backupfile @@ -271,14 +271,14 @@ rm -f $tempfile $backupfile # Test 2 - should fail to check an empty file and fail to upgrade it echo "2.1. Database is an empty file - check" touch $tempfile -../b10-dbutil --check $tempfile +../run_dbutil.sh --check $tempfile failzero $? check_no_backup $tempfile $backupfile rm -f $tempfile $backupfile echo "2.2. Database is an empty file - upgrade" touch $tempfile -../b10-dbutil --upgrade --noconfirm $tempfile +../run_dbutil.sh --upgrade --noconfirm $tempfile failzero $? # A backup is performed before anything else, so the backup should exist. check_backup $tempfile $backupfile @@ -287,12 +287,12 @@ rm -f $tempfile $backupfile echo "3.1. Database is not an SQLite file - check" echo "This is not an sqlite3 database" > $tempfile -../b10-dbutil --check $tempfile +../run_dbutil.sh --check $tempfile failzero $? check_no_backup $tempfile $backupfile echo "3.2. Database is not an SQLite file - upgrade" -../b10-dbutil --upgrade --noconfirm $tempfile +../run_dbutil.sh --upgrade --noconfirm $tempfile failzero $? # ...and as before, a backup should have been created check_backup $tempfile $backupfile @@ -301,14 +301,14 @@ rm -f $tempfile $backupfile echo "4.1. Database is an SQLite3 file without the schema table - check" cp $testdata/no_schema.sqlite3 $tempfile -../b10-dbutil --check $tempfile +../run_dbutil.sh --check $tempfile failzero $? check_no_backup $tempfile $backupfile rm -f $tempfile $backupfile echo "4.1. Database is an SQLite3 file without the schema table - upgrade" cp $testdata/no_schema.sqlite3 $tempfile -../b10-dbutil --upgrade --noconfirm $tempfile +../run_dbutil.sh --upgrade --noconfirm $tempfile failzero $? check_backup $testdata/no_schema.sqlite3 $backupfile rm -f $tempfile $backupfile @@ -360,25 +360,27 @@ check_backup $testdata/v2_0.sqlite3 ${backupfile}-2 rm -f $tempfile $backupfile ${backupfile}-1 ${backupfile}-2 -echo "10.1 Incompatible flags" +echo "10.1 Command-line errors" cp $testdata/old_v1.sqlite3 $tempfile -../b10-util --upgrade --check $tempfile +../run_dbutil.sh $tempfile failzero $? -../b10-util --upgrade --check $tempfile +../run_dbutil.sh --upgrade --check $tempfile failzero $? -../b10-util --noconfirm --check $tempfile +../run_dbutil.sh --noconfirm --check $tempfile +failzero $? +../run_dbutil.sh --check $tempfile $backupfile failzero $? rm -f $tempfile $backupfile echo "10.2 verbose flag" cp $testdata/old_v1.sqlite3 $tempfile -../b10-dbutil --upgrade --noconfirm --verbose $tempfile +../run_dbutil.sh --upgrade --noconfirm --verbose $tempfile passzero $? rm -f $tempfile $backupfile echo "10.3 Interactive prompt - yes" cp $testdata/old_v1.sqlite3 $tempfile -../b10-dbutil --upgrade $tempfile << . +../run_dbutil.sh --upgrade $tempfile << . Yes . passzero $? @@ -387,7 +389,7 @@ rm -f $tempfile $backupfile echo "10.4 Interactive prompt - no" cp $testdata/old_v1.sqlite3 $tempfile -../b10-dbutil --upgrade $tempfile << . +../run_dbutil.sh --upgrade $tempfile << . no . passzero $?