mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-02 15:05:16 +00:00
[#526,!269] Addressed more review comments
src/lib/cql/testutils/cql_schema.* Modified to use common softWipeEnabled(), which defaults to true src/lib/database/testutils/schema.* bool softWipeEnabled() - new function that checks env varible to determine if DB data wiping is enabled (default is true/enabled) src/lib/mysql/testutils/mysql_schema.* createMySQLSchema() destroyMySQLSchema()- now softWipeEnabled() to allow data wiping to be turned on/off src/share/database/scripts/mysql/wipe_data.sh.in Added better error messaging several files: Removed extraneous calls to destroyMySQLSchema, added comments
This commit is contained in:
@@ -2200,7 +2200,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// Recreates MySQL schema for a test.
|
/// Recreates MySQL schema for a test.
|
||||||
DORAMySQLTest() : DORATest() {
|
DORAMySQLTest() : DORATest() {
|
||||||
db::test::destroyMySQLSchema();
|
// Ensure we have the proper schema with no transient data.
|
||||||
db::test::createMySQLSchema();
|
db::test::createMySQLSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2208,6 +2208,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// Destroys MySQL schema.
|
/// Destroys MySQL schema.
|
||||||
virtual ~DORAMySQLTest() {
|
virtual ~DORAMySQLTest() {
|
||||||
|
// If data wipe enabled, delete transient data otherwise destroy the schema.
|
||||||
db::test::destroyMySQLSchema();
|
db::test::destroyMySQLSchema();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
|
// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
|
||||||
//
|
//
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
@@ -662,7 +662,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// Recreates MySQL schema for a test.
|
/// Recreates MySQL schema for a test.
|
||||||
JSONFileBackendMySQLTest() : JSONFileBackendTest() {
|
JSONFileBackendMySQLTest() : JSONFileBackendTest() {
|
||||||
destroyMySQLSchema();
|
// Ensure we have the proper schema with no transient data.
|
||||||
createMySQLSchema();
|
createMySQLSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -670,6 +670,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// Destroys MySQL schema.
|
/// Destroys MySQL schema.
|
||||||
virtual ~JSONFileBackendMySQLTest() {
|
virtual ~JSONFileBackendMySQLTest() {
|
||||||
|
// If data wipe enabled, delete transient data otherwise destroy the schema.
|
||||||
destroyMySQLSchema();
|
destroyMySQLSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC")
|
// Copyright (C) 2012-2019 Internet Systems Consortium, Inc. ("ISC")
|
||||||
//
|
//
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
@@ -649,7 +649,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// Recreates MySQL schema for a test.
|
/// Recreates MySQL schema for a test.
|
||||||
JSONFileBackendMySQLTest() : JSONFileBackendTest() {
|
JSONFileBackendMySQLTest() : JSONFileBackendTest() {
|
||||||
destroyMySQLSchema();
|
// Ensure we have the proper schema with no transient data.
|
||||||
createMySQLSchema();
|
createMySQLSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -657,6 +657,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// Destroys MySQL schema.
|
/// Destroys MySQL schema.
|
||||||
virtual ~JSONFileBackendMySQLTest() {
|
virtual ~JSONFileBackendMySQLTest() {
|
||||||
|
// If data wipe enabled, delete transient data otherwise destroy the schema
|
||||||
destroyMySQLSchema();
|
destroyMySQLSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,7 +29,7 @@ public:
|
|||||||
// Recreate a fresh mgr.
|
// Recreate a fresh mgr.
|
||||||
ConfigBackendDHCPv4Mgr::create();
|
ConfigBackendDHCPv4Mgr::create();
|
||||||
|
|
||||||
// Recreate database schema.
|
// Ensure we have the proper schema with no transient data.
|
||||||
createMySQLSchema();
|
createMySQLSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +37,8 @@ public:
|
|||||||
virtual ~MySqlConfigBackendDHCPv4MgrTest() {
|
virtual ~MySqlConfigBackendDHCPv4MgrTest() {
|
||||||
// Destroy the mgr.
|
// Destroy the mgr.
|
||||||
ConfigBackendDHCPv4Mgr::destroy();
|
ConfigBackendDHCPv4Mgr::destroy();
|
||||||
|
|
||||||
|
// If data wipe enabled, delete transient data otherwise destroy the schema.
|
||||||
destroyMySQLSchema();
|
destroyMySQLSchema();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -47,7 +47,7 @@ public:
|
|||||||
/// @brief Constructor.
|
/// @brief Constructor.
|
||||||
MySqlConfigBackendDHCPv4Test()
|
MySqlConfigBackendDHCPv4Test()
|
||||||
: test_subnets_(), test_networks_(), timestamps_(), audit_entries_() {
|
: test_subnets_(), test_networks_(), timestamps_(), audit_entries_() {
|
||||||
// Recreate database schema.
|
// Ensure we have the proper schema with no transient data.
|
||||||
createMySQLSchema();
|
createMySQLSchema();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -76,6 +76,7 @@ public:
|
|||||||
/// @brief Destructor.
|
/// @brief Destructor.
|
||||||
virtual ~MySqlConfigBackendDHCPv4Test() {
|
virtual ~MySqlConfigBackendDHCPv4Test() {
|
||||||
cbptr_.reset();
|
cbptr_.reset();
|
||||||
|
// If data wipe enabled, delete transient data otherwise destroy the schema.
|
||||||
destroyMySQLSchema();
|
destroyMySQLSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,16 +31,6 @@ validCqlConnectionString() {
|
|||||||
VALID_PASSWORD));
|
VALID_PASSWORD));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
softWipeEnabled() {
|
|
||||||
const char* const env = getenv("KEA_TEST_CASSANDRA_WIPE");
|
|
||||||
if (env && (std::string(env) == std::string("soft"))) {
|
|
||||||
return (true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
destroyCqlSchema(bool force_wipe, bool show_err) {
|
destroyCqlSchema(bool force_wipe, bool show_err) {
|
||||||
if (force_wipe || !softWipeEnabled()) {
|
if (force_wipe || !softWipeEnabled()) {
|
||||||
|
@@ -65,30 +65,6 @@ void createCqlSchema(bool force_wipe, bool show_err = false);
|
|||||||
/// @throw Unexpected when the script returns an error.
|
/// @throw Unexpected when the script returns an error.
|
||||||
void runCqlScript(const std::string& path, const std::string& script_name,
|
void runCqlScript(const std::string& path, const std::string& script_name,
|
||||||
bool show_err);
|
bool show_err);
|
||||||
|
|
||||||
/// @brief Returns status if the soft-wipe is enabled or not.
|
|
||||||
///
|
|
||||||
/// In some deployments (In case of Tomek's dev system) Cassandra tests take
|
|
||||||
/// a very long time to execute. This was traced back to slow table/indexes
|
|
||||||
/// creation/deletion. With full wipe and recreation of all structures, it
|
|
||||||
/// took over 60 seconds for each test to execute. To avoid this problem, a
|
|
||||||
/// feature called soft-wipe has been implemented. If enabled, it does not
|
|
||||||
/// remove the structures, just the data from essential tables. To enable
|
|
||||||
/// it set KEA_TEST_CASSANDRA_WIPE environment variable to 'soft'. Make sure
|
|
||||||
/// that the database schema is set up properly before running in soft-wipe
|
|
||||||
/// mode.
|
|
||||||
///
|
|
||||||
/// For example to use soft-wipe mode, you can:
|
|
||||||
///
|
|
||||||
/// $ cqlsh -u keatest -p keatest -k keatest
|
|
||||||
/// -f src/share/database/scripts/cql/dhcpdb_create.cql
|
|
||||||
/// $ export KEA_TEST_CASSANDRA_WIPE=soft
|
|
||||||
/// $ cd src/lib/dhcpsrv
|
|
||||||
/// $ make -j9
|
|
||||||
/// $ tests/libdhcpsrv_unittests --gtest_filter=CqlLeaseMgrTest.*
|
|
||||||
///
|
|
||||||
/// @return true if soft-wipe is enabled, false otherwise
|
|
||||||
bool softWipeEnabled();
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@@ -89,6 +89,16 @@ string connectionString(const char* type, const char* name, const char* host,
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
softWipeEnabled() {
|
||||||
|
const char* const wipe_only = getenv("KEA_TEST_DB_WIPE_DATA_ONLY");
|
||||||
|
if (wipe_only && (std::string(wipe_only) == std::string("false"))) {
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
|
// Copyright (C) 2016-2019 Internet Systems Consortium, Inc. ("ISC")
|
||||||
//
|
//
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
@@ -45,6 +45,13 @@ std::string connectionString(const char* type, const char* name = NULL,
|
|||||||
const char* host = NULL, const char* user = NULL,
|
const char* host = NULL, const char* user = NULL,
|
||||||
const char* password = NULL, const char* timeout = NULL,
|
const char* password = NULL, const char* timeout = NULL,
|
||||||
const char* readonly_db = NULL);
|
const char* readonly_db = NULL);
|
||||||
|
|
||||||
|
/// @brief Determines if wiping only the data between tests is enabled
|
||||||
|
///
|
||||||
|
/// @return true if the environment variable, KEA_TEST_DB_WIPE_ONLY is
|
||||||
|
/// defined as "true" or if it is not present.
|
||||||
|
bool softWipeEnabled();
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
|
// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
|
||||||
// Copyright (C) 2017 Deutsche Telekom AG.
|
// Copyright (C) 2017 Deutsche Telekom AG.
|
||||||
//
|
//
|
||||||
// Authors: Andrei Pavel <andrei.pavel@qualitance.com>
|
// Authors: Andrei Pavel <andrei.pavel@qualitance.com>
|
||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// It cleans up schema and recreates tables, then instantiates HostMgr
|
/// It cleans up schema and recreates tables, then instantiates HostMgr
|
||||||
void SetUp(::benchmark::State const&) override {
|
void SetUp(::benchmark::State const&) override {
|
||||||
destroyMySQLSchema(false);
|
// Ensure we have the proper schema with no transient data.
|
||||||
createMySQLSchema(false);
|
createMySQLSchema(false);
|
||||||
try {
|
try {
|
||||||
HostDataSourceFactory::destroy();
|
HostDataSourceFactory::destroy();
|
||||||
@@ -60,6 +60,7 @@ public:
|
|||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
HostDataSourceFactory::destroy();
|
HostDataSourceFactory::destroy();
|
||||||
|
// If data wipe enabled, delete transient data otherwise destroy the schema.
|
||||||
destroyMySQLSchema(false);
|
destroyMySQLSchema(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
|
// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
|
||||||
// Copyright (C) 2017 Deutsche Telekom AG.
|
// Copyright (C) 2017 Deutsche Telekom AG.
|
||||||
//
|
//
|
||||||
// Authors: Andrei Pavel <andrei.pavel@qualitance.com>
|
// Authors: Andrei Pavel <andrei.pavel@qualitance.com>
|
||||||
@@ -36,7 +36,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// It cleans up schema and recreates tables, then instantiates LeaseMgr
|
/// It cleans up schema and recreates tables, then instantiates LeaseMgr
|
||||||
void SetUp(::benchmark::State const&) override {
|
void SetUp(::benchmark::State const&) override {
|
||||||
destroyMySQLSchema(false);
|
// Ensure we have the proper schema with no transient data.
|
||||||
createMySQLSchema(false);
|
createMySQLSchema(false);
|
||||||
try {
|
try {
|
||||||
LeaseMgrFactory::destroy();
|
LeaseMgrFactory::destroy();
|
||||||
@@ -58,6 +58,7 @@ public:
|
|||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
LeaseMgrFactory::destroy();
|
LeaseMgrFactory::destroy();
|
||||||
|
// If data wipe enabled, delete transient data otherwise destroy the schema.
|
||||||
destroyMySQLSchema(false);
|
destroyMySQLSchema(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -147,12 +147,13 @@ public:
|
|||||||
|
|
||||||
/// @brief Constructor.
|
/// @brief Constructor.
|
||||||
CfgMySQLDbAccessTest() {
|
CfgMySQLDbAccessTest() {
|
||||||
// Ensure schema is the correct one.
|
// Ensure we have the proper schema with no transient data.
|
||||||
createMySQLSchema();
|
createMySQLSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Destructor.
|
/// @brief Destructor.
|
||||||
virtual ~CfgMySQLDbAccessTest() {
|
virtual ~CfgMySQLDbAccessTest() {
|
||||||
|
// If data wipe enabled, delete transient data otherwise destroy the schema
|
||||||
destroyMySQLSchema();
|
destroyMySQLSchema();
|
||||||
LeaseMgrFactory::destroy();
|
LeaseMgrFactory::destroy();
|
||||||
}
|
}
|
||||||
|
@@ -971,7 +971,7 @@ void
|
|||||||
MySQLHostMgrTest::SetUp() {
|
MySQLHostMgrTest::SetUp() {
|
||||||
HostMgrTest::SetUp();
|
HostMgrTest::SetUp();
|
||||||
|
|
||||||
// Ensure schema is the correct one.
|
// Ensure we have the proper schema with no transient data.
|
||||||
db::test::createMySQLSchema();
|
db::test::createMySQLSchema();
|
||||||
|
|
||||||
// Connect to the database
|
// Connect to the database
|
||||||
@@ -991,6 +991,8 @@ void
|
|||||||
MySQLHostMgrTest::TearDown() {
|
MySQLHostMgrTest::TearDown() {
|
||||||
HostMgr::instance().getHostDataSource()->rollback();
|
HostMgr::instance().getHostDataSource()->rollback();
|
||||||
HostMgr::delBackend("mysql");
|
HostMgr::delBackend("mysql");
|
||||||
|
|
||||||
|
// If data wipe enabled, delete transient data otherwise destroy the schema
|
||||||
db::test::destroyMySQLSchema();
|
db::test::destroyMySQLSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,7 +41,7 @@ class MySqlHostDataSourceTest : public GenericHostDataSourceTest {
|
|||||||
public:
|
public:
|
||||||
/// @brief Clears the database and opens connection to it.
|
/// @brief Clears the database and opens connection to it.
|
||||||
void initializeTest() {
|
void initializeTest() {
|
||||||
// Ensure schema is the correct one.
|
// Ensure we have the proper schema with no transient data.
|
||||||
createMySQLSchema();
|
createMySQLSchema();
|
||||||
|
|
||||||
// Connect to the database
|
// Connect to the database
|
||||||
@@ -69,6 +69,8 @@ public:
|
|||||||
}
|
}
|
||||||
HostMgr::delAllBackends();
|
HostMgr::delAllBackends();
|
||||||
hdsptr_.reset();
|
hdsptr_.reset();
|
||||||
|
|
||||||
|
// If data wipe enabled, delete transient data otherwise destroy the schema
|
||||||
destroyMySQLSchema();
|
destroyMySQLSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -43,7 +43,7 @@ class MySqlLeaseMgrTest : public GenericLeaseMgrTest {
|
|||||||
public:
|
public:
|
||||||
/// @brief Clears the database and opens connection to it.
|
/// @brief Clears the database and opens connection to it.
|
||||||
void initializeTest() {
|
void initializeTest() {
|
||||||
// Ensure schema is the correct one.
|
// Ensure we have the proper schema with no transient data.
|
||||||
createMySQLSchema();
|
createMySQLSchema();
|
||||||
|
|
||||||
// Connect to the database
|
// Connect to the database
|
||||||
@@ -69,6 +69,7 @@ public:
|
|||||||
// Rollback may fail if backend is in read only mode. That's ok.
|
// Rollback may fail if backend is in read only mode. That's ok.
|
||||||
}
|
}
|
||||||
LeaseMgrFactory::destroy();
|
LeaseMgrFactory::destroy();
|
||||||
|
// If data wipe enabled, delete transient data otherwise destroy the schema
|
||||||
destroyMySQLSchema();
|
destroyMySQLSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,14 +32,14 @@ validMySQLConnectionString() {
|
|||||||
|
|
||||||
void destroyMySQLSchema(bool show_err, bool force) {
|
void destroyMySQLSchema(bool show_err, bool force) {
|
||||||
// If force is true or wipeData() fails, destory the schema.
|
// If force is true or wipeData() fails, destory the schema.
|
||||||
if (force || wipeData(show_err)) {
|
if (force || (!softWipeEnabled()) || wipeData(show_err)) {
|
||||||
runMySQLScript(DATABASE_SCRIPTS_DIR, "mysql/dhcpdb_drop.mysql", show_err);
|
runMySQLScript(DATABASE_SCRIPTS_DIR, "mysql/dhcpdb_drop.mysql", show_err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void createMySQLSchema(bool show_err, bool force) {
|
void createMySQLSchema(bool show_err, bool force) {
|
||||||
// If force is true or wipeData() fails, recreate the schema.
|
// If force is true or wipeData() fails, recreate the schema.
|
||||||
if (force || wipeData(show_err)) {
|
if (force || (!softWipeEnabled()) || wipeData(show_err)) {
|
||||||
destroyMySQLSchema(show_err, true);
|
destroyMySQLSchema(show_err, true);
|
||||||
runMySQLScript(DATABASE_SCRIPTS_DIR, "mysql/dhcpdb_create.mysql", show_err);
|
runMySQLScript(DATABASE_SCRIPTS_DIR, "mysql/dhcpdb_create.mysql", show_err);
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@ std::string validMySQLConnectionString();
|
|||||||
/// database /or destroys the database itself by submitting the
|
/// database /or destroys the database itself by submitting the
|
||||||
/// SQL script:
|
/// SQL script:
|
||||||
///
|
///
|
||||||
/// <TEST_ADMIN_SCRIPTS_DIR>/mysql/dhcpdb_drop.sh
|
/// <TEST_ADMIN_SCRIPTS_DIR>/mysql/dhcpdb_drop.mysql
|
||||||
///
|
///
|
||||||
/// If wipeData() is called and fails, it will destroy
|
/// If wipeData() is called and fails, it will destroy
|
||||||
/// the schema. If the schema destruction fails, the
|
/// the schema. If the schema destruction fails, the
|
||||||
|
1
src/share/database/scripts/mysql/.gitignore
vendored
1
src/share/database/scripts/mysql/.gitignore
vendored
@@ -8,3 +8,4 @@
|
|||||||
/upgrade_5.2_to_6.0.sh
|
/upgrade_5.2_to_6.0.sh
|
||||||
/upgrade_6.0_to_7.0.sh
|
/upgrade_6.0_to_7.0.sh
|
||||||
/upgrade_7.0_to_8.0.sh
|
/upgrade_7.0_to_8.0.sh
|
||||||
|
/wipe_data.sh
|
||||||
|
@@ -28,8 +28,13 @@ shift;
|
|||||||
|
|
||||||
# If the existing schema doesn't match, the fail
|
# If the existing schema doesn't match, the fail
|
||||||
VERSION=`mysql_version "$@"`
|
VERSION=`mysql_version "$@"`
|
||||||
|
if [ "$VERSION" = "" ]; then
|
||||||
|
printf "Cannot wipe data, schema version could not be detected.\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$VERSION" != "$exp_version" ]; then
|
if [ "$VERSION" != "$exp_version" ]; then
|
||||||
printf "Reported version is $VERSION is wrong, expected $exp_version.\n"
|
printf "Cannot wipe data, wrong schema version. Expected $exp_version, found version $VERSION.\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user