From: JINMEI Tatuya Date: Mon, 9 Apr 2012 23:35:57 +0000 (-0700) Subject: [1792] added support for "sqlite3" filetype of inmemory zone. X-Git-Tag: trac2351_base~226^2~116^2~33^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9b060a79e29c1691d1e84da5d6a656e99f2ec8a2;p=thirdparty%2Fkea.git [1792] added support for "sqlite3" filetype of inmemory zone. --- diff --git a/src/bin/auth/auth_config.cc b/src/bin/auth/auth_config.cc index 3b391d3da5..3a04dc8a6b 100644 --- a/src/bin/auth/auth_config.cc +++ b/src/bin/auth/auth_config.cc @@ -12,14 +12,6 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -#include -#include -#include -#include - -#include -#include - #include #include @@ -27,6 +19,7 @@ #include #include +#include #include #include @@ -34,6 +27,15 @@ #include +#include +#include +#include + +#include +#include +#include +#include + using namespace std; using namespace isc::dns; using namespace isc::data; @@ -165,10 +167,21 @@ MemoryDatasourceConfig::build(ConstElementPtr config_value) { isc_throw(AuthConfigError, "Missing zone file for zone: " << origin_txt); } + + // We support the traditional text type and SQLite3 backend. For the + // latter we create a client for the underlying SQLite3 data source, + // and build the in-memory zone using an iterator of the underlying + // zone. ConstElementPtr filetype = zone_config->get("filetype"); const string filetype_txt = filetype ? filetype->stringValue() : "text"; - if (filetype_txt != "text") { + boost::scoped_ptr container; + if (filetype_txt == "sqlite3") { + container.reset(new DataSourceClientContainer( + "sqlite3", + Element::fromJSON("{\"database_file\": \"" + + file_txt + "\"}"))); + } else if (filetype_txt != "text") { isc_throw(AuthConfigError, "Invalid filetype for zone " << origin_txt << ": " << filetype_txt); } @@ -198,7 +211,12 @@ MemoryDatasourceConfig::build(ConstElementPtr config_value) { * need the load method to be split into some kind of build and * commit/abort parts. */ - zone_finder->load(file_txt); + if (filetype_txt == "text") { + zone_finder->load(file_txt); + } else { + zone_finder->load(*container->getInstance().getIterator( + Name(origin_txt))); + } } } diff --git a/src/bin/auth/tests/Makefile.am b/src/bin/auth/tests/Makefile.am index 521890eb76..b33c7af91b 100644 --- a/src/bin/auth/tests/Makefile.am +++ b/src/bin/auth/tests/Makefile.am @@ -12,6 +12,9 @@ AM_CXXFLAGS = $(B10_CXXFLAGS) if USE_STATIC_LINK AM_LDFLAGS = -static +# Some test cases cannot work with static link. To selectively disable such +# tests we signal it via a definition. +AM_CPPFLAGS += -DUSE_STATIC_LINK=1 endif CLEANFILES = *.gcno *.gcda @@ -29,6 +32,7 @@ run_unittests_SOURCES += ../auth_config.h ../auth_config.cc run_unittests_SOURCES += ../command.h ../command.cc run_unittests_SOURCES += ../common.h ../common.cc run_unittests_SOURCES += ../statistics.h ../statistics.cc +run_unittests_SOURCES += datasrc_util.h datasrc_util.cc run_unittests_SOURCES += auth_srv_unittest.cc run_unittests_SOURCES += config_unittest.cc run_unittests_SOURCES += config_syntax_unittest.cc diff --git a/src/bin/auth/tests/config_unittest.cc b/src/bin/auth/tests/config_unittest.cc index 7b4a2250b9..d471a53c9a 100644 --- a/src/bin/auth/tests/config_unittest.cc +++ b/src/bin/auth/tests/config_unittest.cc @@ -21,6 +21,7 @@ #include +#include #include #include @@ -29,14 +30,20 @@ #include #include +#include "datasrc_util.h" + #include #include #include +#include + +using namespace std; using namespace isc::dns; using namespace isc::data; using namespace isc::datasrc; using namespace isc::asiodns; +using namespace isc::auth::unittest; using namespace isc::testutils; namespace { @@ -201,17 +208,44 @@ TEST_F(MemoryDatasrcConfigTest, addOneZone) { RRType::A())->code); } -TEST_F(MemoryDatasrcConfigTest, addOneWithFiletype) { - // Until #1792 is completed, only "text" filetype is allowed. +// This test uses dynamic load of a data source module, and won't work when +// statically linked. +TEST_F(MemoryDatasrcConfigTest, +#ifdef USE_STATIC_LINK + DISABLED_addOneWithFiletypeSQLite3 +#else + addOneWithFiletypeSQLite3 +#endif + ) +{ + const string test_db = TEST_DATA_BUILDDIR "/auth_test.sqlite3.copied"; + stringstream ss("example.org. 3600 IN SOA . . 0 0 0 0 0\n"); + createSQLite3DB(rrclass, Name("example.org"), test_db.c_str(), ss); + + // In-memory with an SQLite3 data source as the backend. + parser->build(Element::fromJSON( + "[{\"type\": \"memory\"," + " \"zones\": [{\"origin\": \"example.org\"," + " \"file\": \"" + + test_db + "\"," + " \"filetype\": \"sqlite3\"}]}]")); + parser->commit(); + EXPECT_EQ(1, server.getInMemoryClient(rrclass)->getZoneCount()); + + // Failure case: the specified zone doesn't exist in the DB file. + delete parser; + parser = createAuthConfigParser(server, "datasources"); EXPECT_THROW(parser->build( Element::fromJSON( "[{\"type\": \"memory\"," " \"zones\": [{\"origin\": \"example.com\"," " \"file\": \"" - TEST_DATA_DIR "/example.zone\"," + + test_db + "\"," " \"filetype\": \"sqlite3\"}]}]")), - AuthConfigError); + DataSourceError); +} +TEST_F(MemoryDatasrcConfigTest, addOneWithFiletypeText) { // Explicitly specifying "text" is okay. parser->build(Element::fromJSON( "[{\"type\": \"memory\","