|
@@ -1,4 +1,4 @@
|
|
|
-// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
|
|
|
+// Copyright (C) 2012-2016 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
|
|
@@ -9,7 +9,7 @@
|
|
|
#include <cc/command_interpreter.h>
|
|
|
#include <dhcpsrv/lease_mgr_factory.h>
|
|
|
#include <dhcpsrv/parsers/dbaccess_parser.h>
|
|
|
-#include <dhcpsrv/tests/mysql_schema.h>
|
|
|
+#include <dhcpsrv/testutils/mysql_schema.h>
|
|
|
#include <dhcpsrv/host_mgr.h>
|
|
|
#include <log/logger_support.h>
|
|
|
|
|
@@ -123,18 +123,14 @@ public:
|
|
|
/// @param dbaccess set of database access parameters to check
|
|
|
/// @param keyval Array of "const char*" strings in the order keyword,
|
|
|
/// value, keyword, value ... A NULL entry terminates the list.
|
|
|
- /// @param u Universe (V4 or V6).
|
|
|
void checkAccessString(const char* trace_string,
|
|
|
const DbAccessParser::StringPairMap& parameters,
|
|
|
- const char* keyval[],
|
|
|
- Option::Universe u = Option::V4) {
|
|
|
+ const char* keyval[]) {
|
|
|
SCOPED_TRACE(trace_string);
|
|
|
|
|
|
// Construct a map of keyword value pairs.
|
|
|
std::map<string, string> expected;
|
|
|
- expected["universe"] = (u == Option::V4 ? "4" : "6");
|
|
|
- // The universe is always injected by the parser itself.
|
|
|
- size_t expected_count = 1;
|
|
|
+ size_t expected_count = 0;
|
|
|
for (size_t i = 0; keyval[i] != NULL; i += 2) {
|
|
|
// Get the value. This should not be NULL
|
|
|
ASSERT_NE(static_cast<const char*>(NULL), keyval[i + 1]) <<
|
|
@@ -195,10 +191,9 @@ public:
|
|
|
|
|
|
/// @brief Constructor
|
|
|
///
|
|
|
- /// @brief Keyword/value collection of ddatabase access parameters
|
|
|
- TestDbAccessParser(const std::string& param_name, DbAccessParser::DBType type,
|
|
|
- const ParserContext& ctx)
|
|
|
- : DbAccessParser(param_name, type, ctx)
|
|
|
+ /// @brief Keyword/value collection of database access parameters
|
|
|
+ TestDbAccessParser(const std::string& param_name, DbAccessParser::DBType type)
|
|
|
+ : DbAccessParser(param_name, type)
|
|
|
{}
|
|
|
|
|
|
/// @brief Destructor
|
|
@@ -239,8 +234,7 @@ TEST_F(DbAccessParserTest, validTypeMemfile) {
|
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
EXPECT_TRUE(json_elements);
|
|
|
|
|
|
- TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB,
|
|
|
- ParserContext(Option::V4));
|
|
|
+ TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
|
|
|
EXPECT_NO_THROW(parser.build(json_elements));
|
|
|
checkAccessString("Valid memfile", parser.getDbAccessParameters(), config);
|
|
|
}
|
|
@@ -256,8 +250,7 @@ TEST_F(DbAccessParserTest, emptyKeyword) {
|
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
EXPECT_TRUE(json_elements);
|
|
|
|
|
|
- TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB,
|
|
|
- ParserContext(Option::V4));
|
|
|
+ TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
|
|
|
EXPECT_NO_THROW(parser.build(json_elements));
|
|
|
checkAccessString("Valid memfile", parser.getDbAccessParameters(), config);
|
|
|
}
|
|
@@ -274,8 +267,7 @@ TEST_F(DbAccessParserTest, persistV4Memfile) {
|
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
EXPECT_TRUE(json_elements);
|
|
|
|
|
|
- TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB,
|
|
|
- ParserContext(Option::V4));
|
|
|
+ TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
|
|
|
EXPECT_NO_THROW(parser.build(json_elements));
|
|
|
|
|
|
checkAccessString("Valid memfile", parser.getDbAccessParameters(),
|
|
@@ -294,12 +286,11 @@ TEST_F(DbAccessParserTest, persistV6Memfile) {
|
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
EXPECT_TRUE(json_elements);
|
|
|
|
|
|
- TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB,
|
|
|
- ParserContext(Option::V6));
|
|
|
+ TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
|
|
|
EXPECT_NO_THROW(parser.build(json_elements));
|
|
|
|
|
|
checkAccessString("Valid memfile", parser.getDbAccessParameters(),
|
|
|
- config, Option::V6);
|
|
|
+ config);
|
|
|
}
|
|
|
|
|
|
// This test checks that the parser accepts the valid value of the
|
|
@@ -314,11 +305,10 @@ TEST_F(DbAccessParserTest, validLFCInterval) {
|
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
EXPECT_TRUE(json_elements);
|
|
|
|
|
|
- TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB,
|
|
|
- ParserContext(Option::V6));
|
|
|
- ASSERT_NO_THROW(parser.build(json_elements));
|
|
|
+ TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
|
|
|
+ EXPECT_NO_THROW(parser.build(json_elements));
|
|
|
checkAccessString("Valid LFC Interval", parser.getDbAccessParameters(),
|
|
|
- config, Option::V6);
|
|
|
+ config);
|
|
|
}
|
|
|
|
|
|
// This test checks that the parser rejects the negative value of the
|
|
@@ -333,8 +323,7 @@ TEST_F(DbAccessParserTest, negativeLFCInterval) {
|
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
EXPECT_TRUE(json_elements);
|
|
|
|
|
|
- TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB,
|
|
|
- ParserContext(Option::V6));
|
|
|
+ TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
|
|
|
EXPECT_THROW(parser.build(json_elements), BadValue);
|
|
|
}
|
|
|
|
|
@@ -350,8 +339,7 @@ TEST_F(DbAccessParserTest, largeLFCInterval) {
|
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
EXPECT_TRUE(json_elements);
|
|
|
|
|
|
- TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB,
|
|
|
- ParserContext(Option::V6));
|
|
|
+ TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
|
|
|
EXPECT_THROW(parser.build(json_elements), BadValue);
|
|
|
}
|
|
|
|
|
@@ -368,8 +356,7 @@ TEST_F(DbAccessParserTest, validTypeMysql) {
|
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
EXPECT_TRUE(json_elements);
|
|
|
|
|
|
- TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB,
|
|
|
- ParserContext(Option::V4));
|
|
|
+ TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
|
|
|
EXPECT_NO_THROW(parser.build(json_elements));
|
|
|
checkAccessString("Valid mysql", parser.getDbAccessParameters(), config);
|
|
|
}
|
|
@@ -386,8 +373,7 @@ TEST_F(DbAccessParserTest, missingTypeKeyword) {
|
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
EXPECT_TRUE(json_elements);
|
|
|
|
|
|
- TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB,
|
|
|
- ParserContext(Option::V4));
|
|
|
+ TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
|
|
|
EXPECT_THROW(parser.build(json_elements), TypeKeywordMissing);
|
|
|
}
|
|
|
|
|
@@ -396,7 +382,7 @@ TEST_F(DbAccessParserTest, factory) {
|
|
|
|
|
|
// Check that the parser is built through the factory.
|
|
|
boost::scoped_ptr<DhcpConfigParser> parser(
|
|
|
- DbAccessParser::factory("lease-database", ParserContext(Option::V4))
|
|
|
+ DbAccessParser::factory("lease-database")
|
|
|
);
|
|
|
EXPECT_TRUE(parser);
|
|
|
DbAccessParser* dbap = dynamic_cast<DbAccessParser*>(parser.get());
|
|
@@ -447,8 +433,7 @@ TEST_F(DbAccessParserTest, incrementalChanges) {
|
|
|
"name", "keatest",
|
|
|
NULL};
|
|
|
|
|
|
- TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB,
|
|
|
- ParserContext(Option::V4));
|
|
|
+ TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
|
|
|
|
|
|
// First configuration string should cause a representation of that string
|
|
|
// to be held.
|
|
@@ -512,8 +497,7 @@ TEST_F(DbAccessParserTest, getDbAccessString) {
|
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
EXPECT_TRUE(json_elements);
|
|
|
|
|
|
- TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB,
|
|
|
- ParserContext(Option::V4));
|
|
|
+ TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
|
|
|
EXPECT_NO_THROW(parser.build(json_elements));
|
|
|
|
|
|
// Get the database access string
|
|
@@ -522,96 +506,7 @@ TEST_F(DbAccessParserTest, getDbAccessString) {
|
|
|
// String should be either "type=mysql name=keatest" or
|
|
|
// "name=keatest type=mysql". The "host" entry is null, so should not be
|
|
|
// output.
|
|
|
- EXPECT_EQ(dbaccess, "name=keatest type=mysql universe=4");
|
|
|
-}
|
|
|
-
|
|
|
-// Check that the "commit" function actually opens the database, when type
|
|
|
-// is set to LEASE_DB. We will only do this for the "memfile" database, as
|
|
|
-// that does not assume that the test has been built with MySQL support.
|
|
|
-TEST_F(DbAccessParserTest, commitLeaseDb) {
|
|
|
-
|
|
|
- // Verify that no lease database is open
|
|
|
- EXPECT_THROW({
|
|
|
- LeaseMgr& manager = LeaseMgrFactory::instance();
|
|
|
- manager.getType(); // Never executed but satisfies compiler
|
|
|
- }, isc::dhcp::NoLeaseManager);
|
|
|
-
|
|
|
- // Set up the parser to open the memfile database.
|
|
|
- const char* config[] = {"type", "memfile", "persist", "false", NULL};
|
|
|
- string json_config = toJson(config);
|
|
|
-
|
|
|
- ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
- EXPECT_TRUE(json_elements);
|
|
|
-
|
|
|
- TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB,
|
|
|
- ParserContext(Option::V4));
|
|
|
- EXPECT_NO_THROW(parser.build(json_elements));
|
|
|
-
|
|
|
- // Ensure that the access string is as expected.
|
|
|
- EXPECT_EQ("persist=false type=memfile universe=4",
|
|
|
- parser.getDbAccessString());
|
|
|
-
|
|
|
- // Committal of the parser changes should open the database.
|
|
|
- EXPECT_NO_THROW(parser.commit());
|
|
|
-
|
|
|
- // Verify by checking the type of database open.
|
|
|
- std::string dbtype;
|
|
|
- EXPECT_NO_THROW(dbtype = LeaseMgrFactory::instance().getType());
|
|
|
- EXPECT_EQ(std::string("memfile"), dbtype);
|
|
|
-}
|
|
|
-
|
|
|
-#ifdef HAVE_MYSQL
|
|
|
-// Check that the "commit" function actually opens the database, when type
|
|
|
-// is set to HOSTS_DB. We're using MySQL here. Since the only currently supported
|
|
|
-// host data source is the one that uses MySQL, we have no other choice, but to
|
|
|
-// depend this test on MYSQL availability.
|
|
|
-TEST_F(DbAccessParserTest, commitHostsDb) {
|
|
|
-
|
|
|
- // Remove schema (if there are any leftovers from previous tests).
|
|
|
- destroyMySQLSchema();
|
|
|
-
|
|
|
- // Verify that no lease database is open
|
|
|
- EXPECT_THROW({
|
|
|
- LeaseMgr& manager = LeaseMgrFactory::instance();
|
|
|
- manager.getType(); // Never executed but satisfies compiler
|
|
|
- }, isc::dhcp::NoLeaseManager);
|
|
|
-
|
|
|
- // Set up the parser to open the memfile database.
|
|
|
- const char* config[] = {"type", "mysql", "user", "keatest",
|
|
|
- "password", "keatest", "name", "keatest", NULL};
|
|
|
- string json_config = toJson(config);
|
|
|
-
|
|
|
- ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
|
- EXPECT_TRUE(json_elements);
|
|
|
-
|
|
|
- TestDbAccessParser parser("hosts-database", DbAccessParser::HOSTS_DB,
|
|
|
- ParserContext(Option::V4));
|
|
|
- EXPECT_NO_THROW(parser.build(json_elements));
|
|
|
-
|
|
|
- // Ensure that the access string is as expected.
|
|
|
- EXPECT_EQ("name=keatest password=keatest type=mysql universe=4 user=keatest",
|
|
|
- parser.getDbAccessString());
|
|
|
-
|
|
|
- // Destroy lease mgr (if there's any)
|
|
|
- LeaseMgrFactory::destroy();
|
|
|
-
|
|
|
- EXPECT_NO_THROW(createMySQLSchema());
|
|
|
-
|
|
|
- // Committal of the parser changes should not create LeaseMgr.
|
|
|
- // It should create HostDataSource instead.
|
|
|
- EXPECT_NO_THROW(parser.commit());
|
|
|
-
|
|
|
- // Check that LeaseMgr was NOT created (it shouldn't, this is for HOSTS_DB).
|
|
|
- EXPECT_THROW(LeaseMgrFactory::instance(), NoLeaseManager);
|
|
|
-
|
|
|
- // Verify that HostDataSource has been created.
|
|
|
- HostDataSourcePtr hds = HostMgr::instance().getHostDataSource();
|
|
|
- ASSERT_TRUE(hds);
|
|
|
-
|
|
|
- EXPECT_EQ("mysql", hds->getType());
|
|
|
-
|
|
|
- EXPECT_NO_THROW(destroyMySQLSchema());
|
|
|
+ EXPECT_EQ(dbaccess, "name=keatest type=mysql");
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
}; // Anonymous namespace
|