From: Michal 'vorner' Vaner Date: Sat, 30 Jun 2012 21:00:16 +0000 (+0200) Subject: [1976] Enable some tests for in-memory from master files X-Git-Tag: trac2351_base~97^2~7^2~2^2~21^2~2^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=90593cc3f05fbd272f11fc57c876487f9dbc3813;p=thirdparty%2Fkea.git [1976] Enable some tests for in-memory from master files Some of the previously disabled tests that needed #2046 are now enabled. Some ripping out of internals (the old in-memory) happened on the way. This led to temporarily commenting out some test code, but it was in disabled tests anyway. --- diff --git a/src/bin/auth/auth_srv.cc b/src/bin/auth/auth_srv.cc index e4016c59af..ce2f00ce17 100644 --- a/src/bin/auth/auth_srv.cc +++ b/src/bin/auth/auth_srv.cc @@ -43,7 +43,6 @@ #include #include -#include #include #include #include @@ -249,9 +248,6 @@ public: AbstractSession* xfrin_session_; /// In-memory data source. Currently class IN only for simplicity. - const RRClass memory_client_class_; - isc::datasrc::DataSourceClientContainerPtr memory_client_container_; - /// Hot spot cache isc::datasrc::HotCache cache_; @@ -322,7 +318,6 @@ AuthSrvImpl::AuthSrvImpl(const bool use_cache, BaseSocketSessionForwarder& ddns_forwarder) : config_session_(NULL), xfrin_session_(NULL), - memory_client_class_(RRClass::IN()), statistics_timer_(io_service_), counters_(), keyring_(NULL), @@ -505,48 +500,6 @@ AuthSrv::getConfigSession() const { return (impl_->config_session_); } -isc::datasrc::DataSourceClientContainerPtr -AuthSrv::getInMemoryClientContainer(const RRClass& rrclass) { - if (rrclass != impl_->memory_client_class_) { - isc_throw(InvalidParameter, - "Memory data source is not supported for RR class " - << rrclass); - } - return (impl_->memory_client_container_); -} - -isc::datasrc::DataSourceClient* -AuthSrv::getInMemoryClient(const RRClass& rrclass) { - if (hasInMemoryClient()) { - return (&getInMemoryClientContainer(rrclass)->getInstance()); - } else { - return (NULL); - } -} - -bool -AuthSrv::hasInMemoryClient() const { - return (impl_->memory_client_container_); -} - -void -AuthSrv::setInMemoryClient(const isc::dns::RRClass& rrclass, - DataSourceClientContainerPtr memory_client) -{ - if (rrclass != impl_->memory_client_class_) { - isc_throw(InvalidParameter, - "Memory data source is not supported for RR class " - << rrclass); - } else if (!impl_->memory_client_container_ && memory_client) { - LOG_DEBUG(auth_logger, DBG_AUTH_OPS, AUTH_MEM_DATASRC_ENABLED) - .arg(rrclass); - } else if (impl_->memory_client_container_ && !memory_client) { - LOG_DEBUG(auth_logger, DBG_AUTH_OPS, AUTH_MEM_DATASRC_DISABLED) - .arg(rrclass); - } - impl_->memory_client_container_ = memory_client; -} - uint32_t AuthSrv::getStatisticsTimerInterval() const { return (impl_->statistics_timer_.getInterval() / 1000); @@ -713,8 +666,6 @@ AuthSrvImpl::processNormalQuery(const IOMessage& io_message, Message& message, } try { - // If a memory data source is configured call the separate - // Query::process() const ConstQuestionPtr question = *message.beginQuestion(); const boost::shared_ptr list(getClientList(question->getClass())); diff --git a/src/bin/auth/auth_srv.h b/src/bin/auth/auth_srv.h index ee8edc98e9..ef2f121562 100644 --- a/src/bin/auth/auth_srv.h +++ b/src/bin/auth/auth_srv.h @@ -43,7 +43,6 @@ class BaseSocketSessionForwarder; } } namespace datasrc { -class InMemoryClient; class ConfigurableClientList; } namespace xfr { @@ -130,20 +129,7 @@ public: isc::util::OutputBuffer& buffer, isc::asiodns::DNSServer* server); - /// \brief Updates the data source for the \c AuthSrv object. - /// - /// This method installs or replaces the data source that the \c AuthSrv - /// object refers to for query processing. - /// Although the method name is generic, the only thing it does is to - /// update the data source information. - /// If there is a data source installed, it will be replaced with the - /// new one. - /// - /// In the current implementation, the SQLite data source and InMemoryClient - /// are assumed. - /// We can enable memory data source and get the path of SQLite database by - /// the \c config parameter. If we disabled memory data source, the SQLite - /// data source will be used. + /// \brief Updates the configuration for the \c AuthSrv object. /// /// On success this method returns a data \c Element (in the form of a /// pointer like object) indicating the successful result, @@ -239,71 +225,6 @@ public: /// void setXfrinSession(isc::cc::AbstractSession* xfrin_session); - /// Returns the in-memory data source configured for the \c AuthSrv, - /// if any, as a pointer. - /// - /// This is mostly a convenience function around - /// \c getInMemoryClientContainer, which saves the caller the step - /// of having to call getInstance(). - /// The pointer is of course only valid as long as the container - /// exists. - /// - /// The in-memory data source is configured per RR class. However, - /// the data source may not be available for all RR classes. - /// If it is not available for the specified RR class, an exception of - /// class \c InvalidParameter will be thrown. - /// This method never throws an exception otherwise. - /// - /// Even for supported RR classes, the in-memory data source is not - /// configured by default. In that case a NULL (shared) pointer will - /// be returned. - /// - /// \param rrclass The RR class of the requested in-memory data source. - /// \return A pointer to the in-memory data source, if configured; - /// otherwise NULL. - isc::datasrc::DataSourceClient* getInMemoryClient( - const isc::dns::RRClass& rrclass); - - /// Returns the DataSourceClientContainer of the in-memory datasource - /// - /// \exception InvalidParameter if the given class does not match - /// the one in the memory data source, or if the memory - /// datasource has not been set (callers can check with - /// \c hasMemoryDataSource()) - /// - /// \param rrclass The RR class of the requested in-memory data source. - /// \return A shared pointer to the in-memory data source, if configured; - /// otherwise an empty shared pointer. - isc::datasrc::DataSourceClientContainerPtr getInMemoryClientContainer( - const isc::dns::RRClass& rrclass); - - /// Checks if the in-memory data source has been set. - /// - /// Right now, only one datasource at a time is effectively supported. - /// This is a helper method to check whether it is the in-memory one. - /// This is mostly useful for current testing, and is expected to be - /// removed (or changed in behaviour) soon, when the general - /// multi-data-source framework is completed. - /// - /// \return True if the in-memory datasource has been set. - bool hasInMemoryClient() const; - - /// Sets or replaces the in-memory data source of the specified RR class. - /// - /// Some RR classes may not be supported, in which case an exception - /// of class \c InvalidParameter will be thrown. - /// This method never throws an exception otherwise. - /// - /// If there is already an in memory data source configured, it will be - /// replaced with the newly specified one. - /// \c memory_client can be an empty shared pointer, in which case it - /// will (re)disable the in-memory data source. - /// - /// \param rrclass The RR class of the in-memory data source to be set. - /// \param memory_client A (shared) pointer to \c InMemoryClient to be set. - void setInMemoryClient(const isc::dns::RRClass& rrclass, - isc::datasrc::DataSourceClientContainerPtr memory_client); - /// \brief Set the communication session with Statistics. /// /// This function never throws an exception as far as diff --git a/src/bin/auth/command.cc b/src/bin/auth/command.cc index e1ddc393f3..2036ff34d6 100644 --- a/src/bin/auth/command.cc +++ b/src/bin/auth/command.cc @@ -185,7 +185,9 @@ private: // On success, it sets 'old_zone_finder_' to the zone to be updated. // It returns true if everything is okay; and false if the command is // valid but there's no need for further process. - bool validate(AuthSrv& server, isc::data::ConstElementPtr args) { + bool validate(AuthSrv& , isc::data::ConstElementPtr ) { +#if 0 + TODO: Rewrite if (args == NULL) { isc_throw(AuthCommandError, "Null argument"); } @@ -235,6 +237,7 @@ private: old_zone_finder_ = boost::static_pointer_cast( result.zone_finder); +#endif return (true); } diff --git a/src/bin/auth/tests/auth_srv_unittest.cc b/src/bin/auth/tests/auth_srv_unittest.cc index f00adfc472..4953301e0e 100644 --- a/src/bin/auth/tests/auth_srv_unittest.cc +++ b/src/bin/auth/tests/auth_srv_unittest.cc @@ -82,10 +82,7 @@ const char* const BADCONFIG_TESTDB = // This is a configuration that uses the in-memory data source containing // a signed example zone. -const char* const CONFIG_INMEMORY_EXAMPLE = - "{\"datasources\": [{\"type\": \"memory\"," - "\"zones\": [{\"origin\": \"example\"," - "\"file\": \"" TEST_DATA_DIR "/rfc5155-example.zone.signed\"}]}]}"; +const char* const CONFIG_INMEMORY_EXAMPLE = TEST_DATA_DIR "/rfc5155-example.zone.signed"; class AuthSrvTest : public SrvTestBase { protected: @@ -850,6 +847,19 @@ updateDatabase(AuthSrv* server, const char* params) { DataSourceConfigurator::testReconfigure(server, config); } +void +updateInMemory(AuthSrv* server, const char* origin, const char* filename) { + const ConstElementPtr config(Element::fromJSON("{" + "\"IN\": [{" + " \"type\": \"MasterFiles\"," + " \"params\": {" + " \"" + string(origin) + "\": \"" + string(filename) + "\"" + " }," + " \"cache-enable\": true" + "}]}")); + DataSourceConfigurator::testReconfigure(server, config); +} + // Install a Sqlite3 data source with testing data. #ifdef USE_STATIC_LINK TEST_F(AuthSrvTest, DISABLED_updateConfig) { @@ -905,28 +915,23 @@ TEST_F(AuthSrvTest, DISABLED_updateConfigFail) { server.processMessage(*io_message, *parse_message, *response_obuffer, &dnsserv); EXPECT_TRUE(dnsserv.hasAnswer()); - headerCheck(*parse_message, default_qid, Rcode::NOERROR(), opcode.getCode(), - QR_FLAG | AA_FLAG, 1, 1, 1, 0); + headerCheck(*parse_message, default_qid, Rcode::NOERROR(), + opcode.getCode(), QR_FLAG | AA_FLAG, 1, 1, 1, 0); } -TEST_F(AuthSrvTest, -#ifdef USE_STATIC_LINK - DISABLED_updateWithInMemoryClient -#else - DISABLED_updateWithInMemoryClient // Needs #2046 -#endif - ) -{ +TEST_F(AuthSrvTest, updateWithInMemoryClient) { // Test configuring memory data source. Detailed test cases are covered // in the configuration tests. We only check the AuthSrv interface here. - // By default memory data source isn't enabled - EXPECT_FALSE(server.hasInMemoryClient()); - updateConfig(&server, - "{\"datasources\": [{\"type\": \"memory\"}]}", true); + // Create an empty in-memory + const ConstElementPtr config(Element::fromJSON("{" + "\"IN\": [{" + " \"type\": \"MasterFiles\"," + " \"params\": {}," + " \"cache-enable\": true" + "}]}")); + DataSourceConfigurator::testReconfigure(&server, config); // after successful configuration, we should have one (with empty zoneset). - EXPECT_TRUE(server.hasInMemoryClient()); - EXPECT_EQ(0, server.getInMemoryClient(rrclass)->getZoneCount()); // The memory data source is empty, should return REFUSED rcode. createDataFromFile("examplequery_fromWire.wire"); @@ -937,21 +942,12 @@ TEST_F(AuthSrvTest, opcode.getCode(), QR_FLAG, 1, 0, 0, 0); } -TEST_F(AuthSrvTest, -#ifdef USE_STATIC_LINK - DISABLED_queryWithInMemoryClientNoDNSSEC -#else - DISABLED_queryWithInMemoryClientNoDNSSEC // Needs #2046 -#endif - ) -{ +TEST_F(AuthSrvTest, queryWithInMemoryClientNoDNSSEC) { // In this example, we do simple check that query is handled from the // query handler class, and confirm it returns no error and a non empty // answer section. Detailed examination on the response content // for various types of queries are tested in the query tests. - updateConfig(&server, CONFIG_INMEMORY_EXAMPLE, true); - EXPECT_TRUE(server.hasInMemoryClient()); - EXPECT_EQ(1, server.getInMemoryClient(rrclass)->getZoneCount()); + updateInMemory(&server, "example.", CONFIG_INMEMORY_EXAMPLE); createDataFromFile("nsec3query_nodnssec_fromWire.wire"); server.processMessage(*io_message, *parse_message, *response_obuffer, @@ -962,20 +958,11 @@ TEST_F(AuthSrvTest, opcode.getCode(), QR_FLAG | AA_FLAG, 1, 1, 2, 1); } -TEST_F(AuthSrvTest, -#ifdef USE_STATIC_LINK - DISABLED_queryWithInMemoryClientDNSSEC -#else - DISABLED_queryWithInMemoryClientDNSSEC // Needs #2046 -#endif - ) -{ +TEST_F(AuthSrvTest, queryWithInMemoryClientDNSSEC) { // Similar to the previous test, but the query has the DO bit on. // The response should contain RRSIGs, and should have more RRs than // the previous case. - updateConfig(&server, CONFIG_INMEMORY_EXAMPLE, true); - EXPECT_TRUE(server.hasInMemoryClient()); - EXPECT_EQ(1, server.getInMemoryClient(rrclass)->getZoneCount()); + updateInMemory(&server, "example.", CONFIG_INMEMORY_EXAMPLE); createDataFromFile("nsec3query_fromWire.wire"); server.processMessage(*io_message, *parse_message, *response_obuffer, @@ -1405,6 +1392,7 @@ private: // // Set the proxies to never throw, this should have the same result as // queryWithInMemoryClientNoDNSSEC, and serves to test the two proxy classes +#if 0 TEST_F(AuthSrvTest, #ifdef USE_STATIC_LINK DISABLED_queryWithInMemoryClientProxy @@ -1415,7 +1403,6 @@ TEST_F(AuthSrvTest, { // Set real inmem client to proxy updateConfig(&server, CONFIG_INMEMORY_EXAMPLE, true); - EXPECT_TRUE(server.hasInMemoryClient()); isc::datasrc::DataSourceClientContainerPtr fake_client_container( new FakeContainer(server.getInMemoryClientContainer(rrclass), @@ -1553,6 +1540,7 @@ TEST_F(AuthSrvTest, headerCheck(*parse_message, default_qid, Rcode::SERVFAIL(), opcode.getCode(), QR_FLAG, 1, 0, 0, 0); } +#endif // // DDNS related tests diff --git a/src/bin/auth/tests/command_unittest.cc b/src/bin/auth/tests/command_unittest.cc index 1114a32321..a5130ff1bf 100644 --- a/src/bin/auth/tests/command_unittest.cc +++ b/src/bin/auth/tests/command_unittest.cc @@ -177,6 +177,9 @@ TEST_F(AuthCommandTest, shutdownIncorrectPID) { EXPECT_EQ(0, rcode_); } +#if 0 +TODO: This needs to be rewritten +Also, reenable everywhere // A helper function commonly used for the "loadzone" command tests. // It configures the server with a memory data source containing two // zones, and checks the zones are correctly loaded. @@ -196,6 +199,7 @@ zoneChecks(AuthSrv& server) { findZone(Name("ns.test2.example")).zone_finder-> find(Name("ns.test2.example"), RRType::AAAA())->code); } +#endif void configureZones(AuthSrv& server) { @@ -214,9 +218,11 @@ configureZones(AuthSrv& server) { " \"file\": \"" TEST_DATA_BUILDDIR "/test2.zone.copied\"}" "]}]}")); - zoneChecks(server); + //TODO: zoneChecks(server); } +#if 0 +TODO: This needs to be rewritten and re-enabled void newZoneChecks(AuthSrv& server) { EXPECT_TRUE(server.getInMemoryClient(RRClass::IN())); @@ -236,6 +242,7 @@ newZoneChecks(AuthSrv& server) { findZone(Name("ns.test2.example")).zone_finder-> find(Name("ns.test2.example"), RRType::AAAA())->code); } +#endif TEST_F(AuthCommandTest, #ifdef USE_STATIC_LINK @@ -258,7 +265,7 @@ TEST_F(AuthCommandTest, Element::fromJSON( "{\"origin\": \"test1.example\"}")); checkAnswer(0); - newZoneChecks(server_); + //TODO: newZoneChecks(server_); } TEST_F(AuthCommandTest, @@ -306,11 +313,14 @@ TEST_F(AuthCommandTest, server_.updateConfig(map); +#if 0 + FIXME: This needs to be done slightly differently // Check that the A record at www.example.org does not exist ASSERT_TRUE(server_.hasInMemoryClient()); EXPECT_EQ(ZoneFinder::NXDOMAIN, server_.getInMemoryClient(RRClass::IN())-> findZone(Name("example.org")).zone_finder-> find(Name("www.example.org"), RRType::A())->code); +#endif // Add the record to the underlying sqlite database, by loading // it as a separate datasource, and updating it @@ -328,11 +338,14 @@ TEST_F(AuthCommandTest, sql_updater->addRRset(*rrset); sql_updater->commit(); +#if 0 + TODO: // This new record is in the database now, but should not be in the // memory-datasource yet, so check again EXPECT_EQ(ZoneFinder::NXDOMAIN, server_.getInMemoryClient(RRClass::IN())-> findZone(Name("example.org")).zone_finder-> find(Name("www.example.org"), RRType::A())->code); +#endif // Now send the command to reload it result_ = execAuthServerCommand(server_, "loadzone", @@ -340,19 +353,24 @@ TEST_F(AuthCommandTest, "{\"origin\": \"example.org\"}")); checkAnswer(0); +#if 0 // And now it should be present too. EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())-> findZone(Name("example.org")).zone_finder-> find(Name("www.example.org"), RRType::A())->code); +#endif // Some error cases. First, the zone has no configuration. (note .com here) result_ = execAuthServerCommand(server_, "loadzone", Element::fromJSON("{\"origin\": \"example.com\"}")); checkAnswer(1); +#if 0 + FIXME // The previous zone is not hurt in any way EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())-> findZone(Name("example.org")).zone_finder-> find(Name("example.org"), RRType::SOA())->code); +#endif module_session.setLocalConfig(Element::fromJSON("{\"datasources\": []}")); result_ = execAuthServerCommand(server_, "loadzone", @@ -360,10 +378,13 @@ TEST_F(AuthCommandTest, "{\"origin\": \"example.org\"}")); checkAnswer(1); +#if 0 + FIXME // The previous zone is not hurt in any way EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())-> findZone(Name("example.org")).zone_finder-> find(Name("example.org"), RRType::SOA())->code); +#endif // Configure an unreadable zone. Should fail, but leave the original zone // data there const ElementPtr @@ -383,10 +404,13 @@ TEST_F(AuthCommandTest, result_ = execAuthServerCommand(server_, "loadzone", Element::fromJSON("{\"origin\": \"example.com\"}")); checkAnswer(1); +#if 0 + FIXME // The previous zone is not hurt in any way EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())-> findZone(Name("example.org")).zone_finder-> find(Name("example.org"), RRType::SOA())->code); +#endif // Broken configuration (not valid against the spec) const ElementPtr @@ -398,10 +422,13 @@ TEST_F(AuthCommandTest, "]}")); module_session.setLocalConfig(broken); checkAnswer(1); +#if 0 + FIXME // The previous zone is not hurt in any way EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())-> findZone(Name("example.org")).zone_finder-> find(Name("example.org"), RRType::SOA())->code); +#endif } TEST_F(AuthCommandTest, @@ -421,7 +448,7 @@ TEST_F(AuthCommandTest, Element::fromJSON( "{\"origin\": \"test1.example\"}")); checkAnswer(1); - zoneChecks(server_); // zone shouldn't be replaced + //zoneChecks(server_); // zone shouldn't be replaced } TEST_F(AuthCommandTest, @@ -442,7 +469,7 @@ TEST_F(AuthCommandTest, Element::fromJSON( "{\"origin\": \"test1.example\"}")); checkAnswer(1); - zoneChecks(server_); // zone shouldn't be replaced + //zoneChecks(server_); // zone shouldn't be replaced } TEST_F(AuthCommandTest, loadZoneWithoutDataSrc) { diff --git a/src/bin/auth/tests/config_unittest.cc b/src/bin/auth/tests/config_unittest.cc index fd6b9a3952..748e63b46e 100644 --- a/src/bin/auth/tests/config_unittest.cc +++ b/src/bin/auth/tests/config_unittest.cc @@ -80,7 +80,8 @@ TEST_F(AuthConfigTest, versionConfig) { } TEST_F(AuthConfigTest, exceptionGuarantee) { - EXPECT_FALSE(server.hasInMemoryClient()); + server.setStatisticsTimerInterval(1234); + EXPECT_EQ(1234, server.getStatisticsTimerInterval()); // This configuration contains an invalid item, which will trigger // an exception. EXPECT_THROW(configureAuthServer( @@ -89,7 +90,7 @@ TEST_F(AuthConfigTest, exceptionGuarantee) { "{ \"no_such_config_var\": 1}")), AuthConfigError); // The server state shouldn't change - EXPECT_FALSE(server.hasInMemoryClient()); + EXPECT_EQ(1234, server.getStatisticsTimerInterval()); } TEST_F(AuthConfigTest, badConfig) {