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
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
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
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__
# ".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.
#
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
"""
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
"""
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 " +
# 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)
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:
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)
--- /dev/null
+#! /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 "$@"
# @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
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
# @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"
# 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
# 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
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
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
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 $?
echo "10.4 Interactive prompt - no"
cp $testdata/old_v1.sqlite3 $tempfile
-../b10-dbutil --upgrade $tempfile << .
+../run_dbutil.sh --upgrade $tempfile << .
no
.
passzero $?