///
/// Recreates MySQL schema for a test.
DORAMySQLTest() : DORATest() {
- db::test::destroyMySQLSchema();
+ // Ensure we have the proper schema with no transient data.
db::test::createMySQLSchema();
}
///
/// Destroys MySQL schema.
virtual ~DORAMySQLTest() {
+ // If data wipe enabled, delete transient data otherwise destroy the schema.
db::test::destroyMySQLSchema();
}
};
-// 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
// License, v. 2.0. If a copy of the MPL was not distributed with this
///
/// Recreates MySQL schema for a test.
JSONFileBackendMySQLTest() : JSONFileBackendTest() {
- destroyMySQLSchema();
+ // Ensure we have the proper schema with no transient data.
createMySQLSchema();
}
///
/// Destroys MySQL schema.
virtual ~JSONFileBackendMySQLTest() {
+ // If data wipe enabled, delete transient data otherwise destroy the schema.
destroyMySQLSchema();
}
-// 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
// License, v. 2.0. If a copy of the MPL was not distributed with this
///
/// Recreates MySQL schema for a test.
JSONFileBackendMySQLTest() : JSONFileBackendTest() {
- destroyMySQLSchema();
+ // Ensure we have the proper schema with no transient data.
createMySQLSchema();
}
///
/// Destroys MySQL schema.
virtual ~JSONFileBackendMySQLTest() {
+ // If data wipe enabled, delete transient data otherwise destroy the schema
destroyMySQLSchema();
}
// Recreate a fresh mgr.
ConfigBackendDHCPv4Mgr::create();
- // Recreate database schema.
+ // Ensure we have the proper schema with no transient data.
createMySQLSchema();
}
virtual ~MySqlConfigBackendDHCPv4MgrTest() {
// Destroy the mgr.
ConfigBackendDHCPv4Mgr::destroy();
+
+ // If data wipe enabled, delete transient data otherwise destroy the schema.
destroyMySQLSchema();
}
};
/// @brief Constructor.
MySqlConfigBackendDHCPv4Test()
: test_subnets_(), test_networks_(), timestamps_(), audit_entries_() {
- // Recreate database schema.
+ // Ensure we have the proper schema with no transient data.
createMySQLSchema();
try {
/// @brief Destructor.
virtual ~MySqlConfigBackendDHCPv4Test() {
cbptr_.reset();
+ // If data wipe enabled, delete transient data otherwise destroy the schema.
destroyMySQLSchema();
}
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
destroyCqlSchema(bool force_wipe, bool show_err) {
if (force_wipe || !softWipeEnabled()) {
/// @throw Unexpected when the script returns an error.
void runCqlScript(const std::string& path, const std::string& script_name,
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();
};
};
};
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);
+}
+
};
};
};
-// 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
// License, v. 2.0. If a copy of the MPL was not distributed with this
const char* host = NULL, const char* user = NULL,
const char* password = NULL, const char* timeout = 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();
+
};
};
};
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2017 Deutsche Telekom AG.
//
// Authors: Andrei Pavel <andrei.pavel@qualitance.com>
///
/// It cleans up schema and recreates tables, then instantiates HostMgr
void SetUp(::benchmark::State const&) override {
- destroyMySQLSchema(false);
+ // Ensure we have the proper schema with no transient data.
createMySQLSchema(false);
try {
HostDataSourceFactory::destroy();
<< endl;
}
HostDataSourceFactory::destroy();
+ // If data wipe enabled, delete transient data otherwise destroy the schema.
destroyMySQLSchema(false);
}
};
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2017 Deutsche Telekom AG.
//
// Authors: Andrei Pavel <andrei.pavel@qualitance.com>
///
/// It cleans up schema and recreates tables, then instantiates LeaseMgr
void SetUp(::benchmark::State const&) override {
- destroyMySQLSchema(false);
+ // Ensure we have the proper schema with no transient data.
createMySQLSchema(false);
try {
LeaseMgrFactory::destroy();
<< endl;
}
LeaseMgrFactory::destroy();
+ // If data wipe enabled, delete transient data otherwise destroy the schema.
destroyMySQLSchema(false);
}
};
/// @brief Constructor.
CfgMySQLDbAccessTest() {
- // Ensure schema is the correct one.
+ // Ensure we have the proper schema with no transient data.
createMySQLSchema();
}
/// @brief Destructor.
virtual ~CfgMySQLDbAccessTest() {
+ // If data wipe enabled, delete transient data otherwise destroy the schema
destroyMySQLSchema();
LeaseMgrFactory::destroy();
}
MySQLHostMgrTest::SetUp() {
HostMgrTest::SetUp();
- // Ensure schema is the correct one.
+ // Ensure we have the proper schema with no transient data.
db::test::createMySQLSchema();
// Connect to the database
MySQLHostMgrTest::TearDown() {
HostMgr::instance().getHostDataSource()->rollback();
HostMgr::delBackend("mysql");
+
+ // If data wipe enabled, delete transient data otherwise destroy the schema
db::test::destroyMySQLSchema();
}
public:
/// @brief Clears the database and opens connection to it.
void initializeTest() {
- // Ensure schema is the correct one.
+ // Ensure we have the proper schema with no transient data.
createMySQLSchema();
// Connect to the database
}
HostMgr::delAllBackends();
hdsptr_.reset();
+
+ // If data wipe enabled, delete transient data otherwise destroy the schema
destroyMySQLSchema();
}
public:
/// @brief Clears the database and opens connection to it.
void initializeTest() {
- // Ensure schema is the correct one.
+ // Ensure we have the proper schema with no transient data.
createMySQLSchema();
// Connect to the database
// Rollback may fail if backend is in read only mode. That's ok.
}
LeaseMgrFactory::destroy();
+ // If data wipe enabled, delete transient data otherwise destroy the schema
destroyMySQLSchema();
}
void destroyMySQLSchema(bool show_err, bool force) {
// 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);
}
}
void createMySQLSchema(bool show_err, bool force) {
// 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);
runMySQLScript(DATABASE_SCRIPTS_DIR, "mysql/dhcpdb_create.mysql", show_err);
}
/// database /or destroys the database itself by submitting the
/// 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
/// the schema. If the schema destruction fails, the
/upgrade_5.2_to_6.0.sh
/upgrade_6.0_to_7.0.sh
/upgrade_7.0_to_8.0.sh
+/wipe_data.sh
# If the existing schema doesn't match, the fail
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
- 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
fi