DSCSqlLeaseMgrTest() {
// Ensure schema is the correct one.
- destroyDSCSQLSchema();
- createDSCSQLSchema();
+ destroyDSCSQLSchema(false, true);
+ createDSCSQLSchema(false, true);
// Connect to the database
try {
virtual ~DSCSqlLeaseMgrTest() {
lmptr_->rollback();
LeaseMgrFactory::destroy();
- destroyDSCSQLSchema();
+ destroyDSCSQLSchema(false, true);
}
/// @brief Reopen the database
TEST(DSCSqlOpenTest, OpenDatabase) {
// Schema needs to be created for the test to work.
- destroyDSCSQLSchema();
- createDSCSQLSchema();
+ destroyDSCSQLSchema(true, true);
+ createDSCSQLSchema(true, true);
// Check that lease manager open the database opens correctly and tidy up.
// If it fails, print the error message.
NoDatabaseName);
// Tidy up after the test
- destroyDSCSQLSchema();
+ destroyDSCSQLSchema(true, true);
}
/// @brief Check the getType() method
VALID_USER, VALID_PASSWORD));
}
-void destroyDSCSQLSchema(bool show_err) {
- runDSCSQLScript(DATABASE_SCRIPTS_DIR, "dscsql/dhcpdb_drop.cql", show_err);
+bool softWipeEnabled() {
+ const char* const env = getenv("KEA_TEST_CASSANDRA_WIPE");
+ if (env && (string(env) == string("soft"))) {
+ return (true);
+ }
+
+ return (false);
+}
+
+void destroyDSCSQLSchema(bool force_wipe, bool show_err) {
+ if (force_wipe || !softWipeEnabled()) {
+ // Do full wipe
+ runDSCSQLScript(DATABASE_SCRIPTS_DIR, "dscsql/dhcpdb_drop.cql", show_err);
+ } else {
+
+ // do soft wipe (just remove the data, not the structures)
+ runDSCSQLScript(DATABASE_SCRIPTS_DIR, "dscsql/soft_wipe.cql", show_err);
+ }
}
-void createDSCSQLSchema(bool show_err) {
- runDSCSQLScript(DATABASE_SCRIPTS_DIR, "dscsql/dhcpdb_create.cql",
- show_err);
+void createDSCSQLSchema(bool force_wipe, bool show_err) {
+ if (force_wipe || !softWipeEnabled()) {
+ runDSCSQLScript(DATABASE_SCRIPTS_DIR, "dscsql/dhcpdb_create.cql",
+ show_err);
+ }
}
void runDSCSQLScript(const std::string& path, const std::string& script_name,
bool show_err) {
std::ostringstream cmd;
- cmd << "cqlsh -u keatest -p keatest -k keatest -f";
+ cmd << "cqlsh -u keatest -p keatest -k keatest";
if (!show_err) {
cmd << " 2>/dev/null ";
}
+ cmd << " -f ";
+
if (!path.empty()) {
- cmd << " < " << path << "/";
+ cmd << path << "/";
}
-
cmd << script_name;
+ /// @todo: Remove this once the unit-tests are in better shape.
+ ///
+ /// This print is here only temporary. We will remove it once all of the
+ /// Cassandra unit-tests will be passing.
+ std::cout << "cmdline:" << cmd.str() << endl;
+
int retval = ::system(cmd.str().c_str());
ASSERT_EQ(0, retval) << "runDSCSQLSchema failed:" << cmd.str();
}
/// will fail. The output of stderr is suppressed unless the parameter,
/// show_err is true.
///
+/// @param force_wipe forces wipe of the database, even if KEA_TEST_CASSANDRA_WIPE
+/// is set.
/// @param show_err flag which governs whether or not stderr is suppressed.
-void destroyDSCSQLSchema(bool show_err = false);
+void destroyDSCSQLSchema(bool force_wipe, bool show_err = false);
/// @brief Create the DSCSQL Schema
///
/// will fail. The output of stderr is suppressed unless the parameter,
/// show_err is true.
///
+/// @param force_wipe forces wipe of the database, even if KEA_TEST_CASSANDRA_WIPE
+/// is set.
/// @param show_err flag which governs whether or not stderr is suppressed.
-void createDSCSQLSchema(bool show_err = false);
+void createDSCSQLSchema(bool force_wipe, bool show_err = false);
/// @brief Run a DSCSQL SQL script against the DSCSQL unit test database
///
void runDSCSQLScript(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/dscsql/dhcpdb_create.cql
+/// $ export KEA_TEST_CASSANDRA_WIPE=soft
+/// $ cd src/lib/dhcpsrv
+/// $ make -j9
+/// $ tests/libdhcpsrv_unittests --gtest_filter=DSCSqlLeaseMgrTest.*
+///
+/// @return true if soft-wipe is enabled, false otherwise
+bool softWipeEnabled();
};
};
};
SUBDIRS = .
sqlscriptsdir = ${datarootdir}/${PACKAGE_NAME}/scripts/dscsql
-sqlscripts_DATA = dhcpdb_create.cql
+sqlscripts_DATA = dhcpdb_create.cql dhcpdb_drop.cql soft_wipe.cql
EXTRA_DIST = ${sqlscripts_DATA}