|
@@ -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
|
|
// 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
|
|
@@ -132,9 +132,7 @@ public:
|
|
|
|
|
|
// Construct a map of keyword value pairs.
|
|
// Construct a map of keyword value pairs.
|
|
std::map<string, string> expected;
|
|
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) {
|
|
for (size_t i = 0; keyval[i] != NULL; i += 2) {
|
|
// Get the value. This should not be NULL
|
|
// Get the value. This should not be NULL
|
|
ASSERT_NE(static_cast<const char*>(NULL), keyval[i + 1]) <<
|
|
ASSERT_NE(static_cast<const char*>(NULL), keyval[i + 1]) <<
|
|
@@ -195,10 +193,9 @@ public:
|
|
|
|
|
|
/// @brief Constructor
|
|
/// @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
|
|
/// @brief Destructor
|
|
@@ -239,8 +236,7 @@ TEST_F(DbAccessParserTest, validTypeMemfile) {
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
EXPECT_TRUE(json_elements);
|
|
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));
|
|
EXPECT_NO_THROW(parser.build(json_elements));
|
|
checkAccessString("Valid memfile", parser.getDbAccessParameters(), config);
|
|
checkAccessString("Valid memfile", parser.getDbAccessParameters(), config);
|
|
}
|
|
}
|
|
@@ -256,8 +252,7 @@ TEST_F(DbAccessParserTest, emptyKeyword) {
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
EXPECT_TRUE(json_elements);
|
|
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));
|
|
EXPECT_NO_THROW(parser.build(json_elements));
|
|
checkAccessString("Valid memfile", parser.getDbAccessParameters(), config);
|
|
checkAccessString("Valid memfile", parser.getDbAccessParameters(), config);
|
|
}
|
|
}
|
|
@@ -274,8 +269,7 @@ TEST_F(DbAccessParserTest, persistV4Memfile) {
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
EXPECT_TRUE(json_elements);
|
|
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));
|
|
EXPECT_NO_THROW(parser.build(json_elements));
|
|
|
|
|
|
checkAccessString("Valid memfile", parser.getDbAccessParameters(),
|
|
checkAccessString("Valid memfile", parser.getDbAccessParameters(),
|
|
@@ -294,8 +288,7 @@ TEST_F(DbAccessParserTest, persistV6Memfile) {
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
EXPECT_TRUE(json_elements);
|
|
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));
|
|
EXPECT_NO_THROW(parser.build(json_elements));
|
|
|
|
|
|
checkAccessString("Valid memfile", parser.getDbAccessParameters(),
|
|
checkAccessString("Valid memfile", parser.getDbAccessParameters(),
|
|
@@ -314,9 +307,8 @@ TEST_F(DbAccessParserTest, validLFCInterval) {
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
EXPECT_TRUE(json_elements);
|
|
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(),
|
|
checkAccessString("Valid LFC Interval", parser.getDbAccessParameters(),
|
|
config, Option::V6);
|
|
config, Option::V6);
|
|
}
|
|
}
|
|
@@ -333,8 +325,7 @@ TEST_F(DbAccessParserTest, negativeLFCInterval) {
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
EXPECT_TRUE(json_elements);
|
|
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);
|
|
EXPECT_THROW(parser.build(json_elements), BadValue);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -350,8 +341,7 @@ TEST_F(DbAccessParserTest, largeLFCInterval) {
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
EXPECT_TRUE(json_elements);
|
|
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);
|
|
EXPECT_THROW(parser.build(json_elements), BadValue);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -368,8 +358,7 @@ TEST_F(DbAccessParserTest, validTypeMysql) {
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
EXPECT_TRUE(json_elements);
|
|
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));
|
|
EXPECT_NO_THROW(parser.build(json_elements));
|
|
checkAccessString("Valid mysql", parser.getDbAccessParameters(), config);
|
|
checkAccessString("Valid mysql", parser.getDbAccessParameters(), config);
|
|
}
|
|
}
|
|
@@ -386,8 +375,7 @@ TEST_F(DbAccessParserTest, missingTypeKeyword) {
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
EXPECT_TRUE(json_elements);
|
|
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);
|
|
EXPECT_THROW(parser.build(json_elements), TypeKeywordMissing);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -396,7 +384,7 @@ TEST_F(DbAccessParserTest, factory) {
|
|
|
|
|
|
// Check that the parser is built through the factory.
|
|
// Check that the parser is built through the factory.
|
|
boost::scoped_ptr<DhcpConfigParser> parser(
|
|
boost::scoped_ptr<DhcpConfigParser> parser(
|
|
- DbAccessParser::factory("lease-database", ParserContext(Option::V4))
|
|
|
|
|
|
+ DbAccessParser::factory("lease-database")
|
|
);
|
|
);
|
|
EXPECT_TRUE(parser);
|
|
EXPECT_TRUE(parser);
|
|
DbAccessParser* dbap = dynamic_cast<DbAccessParser*>(parser.get());
|
|
DbAccessParser* dbap = dynamic_cast<DbAccessParser*>(parser.get());
|
|
@@ -447,8 +435,7 @@ TEST_F(DbAccessParserTest, incrementalChanges) {
|
|
"name", "keatest",
|
|
"name", "keatest",
|
|
NULL};
|
|
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
|
|
// First configuration string should cause a representation of that string
|
|
// to be held.
|
|
// to be held.
|
|
@@ -512,8 +499,7 @@ TEST_F(DbAccessParserTest, getDbAccessString) {
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
ConstElementPtr json_elements = Element::fromJSON(json_config);
|
|
EXPECT_TRUE(json_elements);
|
|
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));
|
|
EXPECT_NO_THROW(parser.build(json_elements));
|
|
|
|
|
|
// Get the database access string
|
|
// Get the database access string
|
|
@@ -522,96 +508,7 @@ TEST_F(DbAccessParserTest, getDbAccessString) {
|
|
// String should be either "type=mysql name=keatest" or
|
|
// String should be either "type=mysql name=keatest" or
|
|
// "name=keatest type=mysql". The "host" entry is null, so should not be
|
|
// "name=keatest type=mysql". The "host" entry is null, so should not be
|
|
// output.
|
|
// 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
|
|
}; // Anonymous namespace
|