2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 05:55:28 +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:
Thomas Markwalder
2019-03-11 13:50:00 -04:00
parent 6af5e78ec8
commit 9bc1a0edf9
19 changed files with 57 additions and 54 deletions

View File

@@ -2200,7 +2200,7 @@ public:
///
/// Recreates MySQL schema for a test.
DORAMySQLTest() : DORATest() {
db::test::destroyMySQLSchema();
// Ensure we have the proper schema with no transient data.
db::test::createMySQLSchema();
}
@@ -2208,6 +2208,7 @@ public:
///
/// Destroys MySQL schema.
virtual ~DORAMySQLTest() {
// If data wipe enabled, delete transient data otherwise destroy the schema.
db::test::destroyMySQLSchema();
}
};

View File

@@ -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
// 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.
JSONFileBackendMySQLTest() : JSONFileBackendTest() {
destroyMySQLSchema();
// Ensure we have the proper schema with no transient data.
createMySQLSchema();
}
@@ -670,6 +670,7 @@ public:
///
/// Destroys MySQL schema.
virtual ~JSONFileBackendMySQLTest() {
// If data wipe enabled, delete transient data otherwise destroy the schema.
destroyMySQLSchema();
}

View File

@@ -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
// 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.
JSONFileBackendMySQLTest() : JSONFileBackendTest() {
destroyMySQLSchema();
// Ensure we have the proper schema with no transient data.
createMySQLSchema();
}
@@ -657,6 +657,7 @@ public:
///
/// Destroys MySQL schema.
virtual ~JSONFileBackendMySQLTest() {
// If data wipe enabled, delete transient data otherwise destroy the schema
destroyMySQLSchema();
}

View File

@@ -29,7 +29,7 @@ public:
// Recreate a fresh mgr.
ConfigBackendDHCPv4Mgr::create();
// Recreate database schema.
// Ensure we have the proper schema with no transient data.
createMySQLSchema();
}
@@ -37,6 +37,8 @@ public:
virtual ~MySqlConfigBackendDHCPv4MgrTest() {
// Destroy the mgr.
ConfigBackendDHCPv4Mgr::destroy();
// If data wipe enabled, delete transient data otherwise destroy the schema.
destroyMySQLSchema();
}
};

View File

@@ -47,7 +47,7 @@ public:
/// @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 {
@@ -76,6 +76,7 @@ public:
/// @brief Destructor.
virtual ~MySqlConfigBackendDHCPv4Test() {
cbptr_.reset();
// If data wipe enabled, delete transient data otherwise destroy the schema.
destroyMySQLSchema();
}

View File

@@ -31,16 +31,6 @@ validCqlConnectionString() {
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()) {

View File

@@ -65,30 +65,6 @@ void createCqlSchema(bool force_wipe, bool show_err = false);
/// @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();
};
};
};

View File

@@ -89,6 +89,16 @@ string connectionString(const char* type, const char* name, const char* host,
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);
}
};
};
};

View File

@@ -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
// 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* 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();
};
};
};

View File

@@ -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.
//
// Authors: Andrei Pavel <andrei.pavel@qualitance.com>
@@ -38,7 +38,7 @@ public:
///
/// 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();
@@ -60,6 +60,7 @@ public:
<< endl;
}
HostDataSourceFactory::destroy();
// If data wipe enabled, delete transient data otherwise destroy the schema.
destroyMySQLSchema(false);
}
};

View File

@@ -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.
//
// Authors: Andrei Pavel <andrei.pavel@qualitance.com>
@@ -36,7 +36,7 @@ public:
///
/// 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();
@@ -58,6 +58,7 @@ public:
<< endl;
}
LeaseMgrFactory::destroy();
// If data wipe enabled, delete transient data otherwise destroy the schema.
destroyMySQLSchema(false);
}
};

View File

@@ -147,12 +147,13 @@ public:
/// @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();
}

View File

@@ -971,7 +971,7 @@ void
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
@@ -991,6 +991,8 @@ void
MySQLHostMgrTest::TearDown() {
HostMgr::instance().getHostDataSource()->rollback();
HostMgr::delBackend("mysql");
// If data wipe enabled, delete transient data otherwise destroy the schema
db::test::destroyMySQLSchema();
}

View File

@@ -41,7 +41,7 @@ class MySqlHostDataSourceTest : public GenericHostDataSourceTest {
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
@@ -69,6 +69,8 @@ public:
}
HostMgr::delAllBackends();
hdsptr_.reset();
// If data wipe enabled, delete transient data otherwise destroy the schema
destroyMySQLSchema();
}

View File

@@ -43,7 +43,7 @@ class MySqlLeaseMgrTest : public GenericLeaseMgrTest {
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
@@ -69,6 +69,7 @@ public:
// 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();
}

View File

@@ -32,14 +32,14 @@ validMySQLConnectionString() {
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);
}

View File

@@ -28,7 +28,7 @@ std::string validMySQLConnectionString();
/// 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

View File

@@ -8,3 +8,4 @@
/upgrade_5.2_to_6.0.sh
/upgrade_6.0_to_7.0.sh
/upgrade_7.0_to_8.0.sh
/wipe_data.sh

View File

@@ -28,8 +28,13 @@ shift;
# 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