retcode=$?
else
export PGPASSWORD=$db_password
- psql --set ON_ERROR_STOP=1 -A -t -h localhost -q -U $db_user -d $db_name -h localhost -f $file
+ psql --set ON_ERROR_STOP=1 -A -t -h localhost -q -U $db_user -d $db_name -f $file
retcode=$?
fi
return $retcode
cql_init() {
printf "Checking if there is a database initialized already... Please ignore errors.\n"
- result=`cql_execute "DESCRIBE KEYSPACES;"`
- if [ "$result" != "" ]; then
- result=`echo "$result" | sed -n "/$db_name/ p"`
- if [ "$result" = "" ]; then
- printf "Creating keyspace $db_name...\n"
- cql_execute "CREATE KEYSPACE $db_name WITH replication = {'class' : 'SimpleStrategy','replication_factor' : 1};"
- else
- printf "Keyspace $db_name already exists.\n"
- fi
- fi
-
result=`cql_execute "USE $db_name; DESCRIBE tables;"`
if [ "$result"="<empty>" ]; then
printf "Creating and initializing tables using script %s...\n" $scripts_dir/cql/dhcpdb_create.cql
version=`cql_version`
printf "Lease DB version reported after initialization: $version\n"
- return 0
+ exit 0
}
### Functions that implement database version checking commands
version=`cql_version`
printf "Lease DB version reported after upgrade: $version\n"
- return 0
+ exit 0
}
# Utility function which tests if the given file exists and
# delete the tmp file on success
rm $tmp_file
echo lease$dump_type successfully dumped to $dump_file
- return 0
+ exit 0
}
### Script starts here ###
/// CqlLeaseMgr test fixure set. This test checks that the database can be
/// opened: the fixtures assume that and check basic operations.
-TEST(CQLOpenTest, OpenDatabase) {
+TEST(CqlOpenTest, OpenDatabase) {
// Schema needs to be created for the test to work.
destroyCqlSchema(false, true);
return (false);
}
-void destroyCqlSchema(bool , bool show_err) {
-// if (force_wipe || !softWipeEnabled()) {
+void destroyCqlSchema(bool force_wipe, bool show_err) {
+ if (force_wipe || !softWipeEnabled()) {
// Do full wipe
runCqlScript(DATABASE_SCRIPTS_DIR, "cql/dhcpdb_drop.cql", show_err);
-// } else {
+ } else {
// do soft wipe (just remove the data, not the structures)
-// runCqlScript(DATABASE_SCRIPTS_DIR, "cql/soft_wipe.cql", show_err);
-// }
+ runCqlScript(DATABASE_SCRIPTS_DIR, "cql/soft_wipe.cql", show_err);
+ }
}
void createCqlSchema(bool force_wipe, bool show_err) {
-- SOURCE dhcpdb_create.cql
--- This script is also called from kea-admin, see kea-admin init cql
+-- This script is also called from kea-admin, see kea-admin lease-init cql
-- Over time, Kea database schema will evolve. Each version is marked with
-- major.minor version. This file is organized sequentially, i.e. database