2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-01 06:25:34 +00:00

[2203] pass server obj to configurator's reconfigure().

now the configurator class is completely stateless.
This commit is contained in:
JINMEI Tatuya
2012-10-03 15:44:29 -07:00
parent 05136b55f9
commit 746376902a
6 changed files with 75 additions and 106 deletions

View File

@@ -81,7 +81,6 @@ protected:
QueryBenchMark(const BenchQueries& queries, Message& query_message, QueryBenchMark(const BenchQueries& queries, Message& query_message,
OutputBuffer& buffer) : OutputBuffer& buffer) :
server_(new AuthSrv(xfrout_client, ddns_forwarder)), server_(new AuthSrv(xfrout_client, ddns_forwarder)),
datasrc_configurator_(server_.get()),
queries_(queries), queries_(queries),
query_message_(query_message), query_message_(query_message),
buffer_(buffer), buffer_(buffer),
@@ -128,6 +127,7 @@ public:
QueryBenchMark(queries, query_message, buffer) QueryBenchMark(queries, query_message, buffer)
{ {
datasrc_configurator_.reconfigure( datasrc_configurator_.reconfigure(
*server_,
Element::fromJSON("{\"IN\":" Element::fromJSON("{\"IN\":"
" [{\"type\": \"sqlite3\"," " [{\"type\": \"sqlite3\","
" \"params\": {" " \"params\": {"
@@ -146,6 +146,7 @@ public:
QueryBenchMark(queries, query_message, buffer) QueryBenchMark(queries, query_message, buffer)
{ {
datasrc_configurator_.reconfigure( datasrc_configurator_.reconfigure(
*server_,
Element::fromJSON("{\"IN\":" Element::fromJSON("{\"IN\":"
" [{\"type\": \"MasterFiles\"," " [{\"type\": \"MasterFiles\","
" \"cache-enable\": true, " " \"cache-enable\": true, "

View File

@@ -18,8 +18,6 @@
#include "auth_srv.h" #include "auth_srv.h"
#include <datasrc/client_list.h> #include <datasrc/client_list.h>
#include <config/ccsession.h>
#include <cc/data.h>
#include <util/threads/lock.h> #include <util/threads/lock.h>
#include <set> #include <set>
@@ -36,48 +34,10 @@
template<class Server, class List> template<class Server, class List>
class DataSourceConfiguratorGeneric { class DataSourceConfiguratorGeneric {
private: private:
Server* server_;
typedef boost::shared_ptr<List> ListPtr; typedef boost::shared_ptr<List> ListPtr;
public: public:
/// \brief Constructor. /// \brief Default constructor.
/// DataSourceConfiguratorGeneric() {}
/// \throw isc::InvalidParameter if server is NULL
/// \param server The server to configure.
DataSourceConfiguratorGeneric(Server* server) : server_(server) {
if (server == NULL) {
isc_throw(isc::InvalidParameter, "The server must not be NULL");
}
}
/// \brief Initializes the class.
///
/// This configures which session and server should be used.
/// It hooks to the session now and downloads the configuration.
/// It is synchronous (it may block for some time).
///
/// Note that you need to call cleanup before the server or
/// session dies, otherwise it might access them after they
/// are destroyed.
///
/// \param server It is the server to configure.
/// \throw isc::InvalidOperation if this is called when already
/// initialized.
/// \throw isc::InvalidParameter if any of the parameters is NULL
/// \throw isc::config::ModuleCCError if the remote configuration is not
/// available for some reason.
void init() {
}
/// \brief Deinitializes the class.
///
/// This detaches from the session and removes the server from internal
/// storage. The current configuration in the server is preserved.
///
/// This can be called even if it is not initialized currently. You
/// can initialize it again after this.
void cleanup() {
server_ = NULL;
}
/// \brief Reads new configuration and replaces the old one. /// \brief Reads new configuration and replaces the old one.
/// ///
@@ -86,16 +46,15 @@ public:
/// is unknown and it would be questionable at least). It is called /// is unknown and it would be questionable at least). It is called
/// automatically on normal updates. /// automatically on normal updates.
/// ///
/// \param server The server for which the data sources are to be
/// configured.
/// \param config The configuration value to parse. It is in the form /// \param config The configuration value to parse. It is in the form
/// as an update from the config manager. /// as an update from the config manager.
/// \throw InvalidOperation if it is called when not initialized. void reconfigure(Server& server,
void reconfigure(const isc::data::ConstElementPtr& config) { const isc::data::ConstElementPtr& config)
if (server_ == NULL) { {
isc_throw(isc::InvalidOperation,
"Can't reconfigure while not initialized by init()");
}
// Lock the client lists, we're going to manipulate them. // Lock the client lists, we're going to manipulate them.
isc::util::thread::Mutex::Locker locker(server_->getClientListMutex()); isc::util::thread::Mutex::Locker locker(server.getClientListMutex());
typedef std::map<std::string, isc::data::ConstElementPtr> Map; typedef std::map<std::string, isc::data::ConstElementPtr> Map;
typedef std::pair<isc::dns::RRClass, ListPtr> RollbackPair; typedef std::pair<isc::dns::RRClass, ListPtr> RollbackPair;
typedef std::pair<isc::dns::RRClass, isc::data::ConstElementPtr> typedef std::pair<isc::dns::RRClass, isc::data::ConstElementPtr>
@@ -107,14 +66,14 @@ public:
// Get the configuration and current state. // Get the configuration and current state.
const Map& map(config->mapValue()); const Map& map(config->mapValue());
const std::vector<isc::dns::RRClass> const std::vector<isc::dns::RRClass>
activeVector(server_->getClientListClasses()); activeVector(server.getClientListClasses());
std::set<isc::dns::RRClass> active(activeVector.begin(), std::set<isc::dns::RRClass> active(activeVector.begin(),
activeVector.end()); activeVector.end());
// Go through the configuration and change everything. // Go through the configuration and change everything.
for (Map::const_iterator it(map.begin()); it != map.end(); ++it) { for (Map::const_iterator it(map.begin()); it != map.end(); ++it) {
isc::dns::RRClass rrclass(it->first); isc::dns::RRClass rrclass(it->first);
active.erase(rrclass); active.erase(rrclass);
ListPtr list(server_->getClientList(rrclass)); ListPtr list(server.getClientList(rrclass));
bool need_set(false); bool need_set(false);
if (list) { if (list) {
rollback_configurations. rollback_configurations.
@@ -127,7 +86,7 @@ public:
} }
list->configure(it->second, true); list->configure(it->second, true);
if (need_set) { if (need_set) {
server_->setClientList(rrclass, list); server.setClientList(rrclass, list);
} }
} }
// Remove the ones that are not in the configuration. // Remove the ones that are not in the configuration.
@@ -137,20 +96,20 @@ public:
// But this is just to make sure in case it did to restore // But this is just to make sure in case it did to restore
// the original. // the original.
rollback_sets.push_back( rollback_sets.push_back(
RollbackPair(*it, server_->getClientList(*it))); RollbackPair(*it, server.getClientList(*it)));
server_->setClientList(*it, ListPtr()); server.setClientList(*it, ListPtr());
} }
} catch (...) { } catch (...) {
// Perform a rollback of the changes. The old configuration should // Perform a rollback of the changes. The old configuration should
// work. // work.
for (typename std::vector<RollbackPair>::const_iterator for (typename std::vector<RollbackPair>::const_iterator
it(rollback_sets.begin()); it != rollback_sets.end(); ++it) { it(rollback_sets.begin()); it != rollback_sets.end(); ++it) {
server_->setClientList(it->first, it->second); server.setClientList(it->first, it->second);
} }
for (typename std::vector<RollbackConfiguration>::const_iterator for (typename std::vector<RollbackConfiguration>::const_iterator
it(rollback_configurations.begin()); it(rollback_configurations.begin());
it != rollback_configurations.end(); ++it) { it != rollback_configurations.end(); ++it) {
server_->getClientList(it->first)->configure(it->second, true); server.getClientList(it->first)->configure(it->second, true);
} }
throw; throw;
} }

View File

@@ -73,7 +73,7 @@ namespace {
/* need global var for config/command handlers. /* need global var for config/command handlers.
* todo: turn this around, and put handlers in the authserver * todo: turn this around, and put handlers in the authserver
* class itself? */ * class itself? */
AuthSrv *auth_server; AuthSrv* auth_server;
ConstElementPtr ConstElementPtr
my_config_handler(ConstElementPtr new_config) { my_config_handler(ConstElementPtr new_config) {
@@ -87,12 +87,13 @@ my_command_handler(const string& command, ConstElementPtr args) {
} }
void void
datasrcConfigHandler(DataSourceConfigurator* configurator, const std::string&, datasrcConfigHandler(AuthSrv* server, DataSourceConfigurator* configurator,
isc::data::ConstElementPtr config, const std::string&, isc::data::ConstElementPtr config,
const isc::config::ConfigData&) const isc::config::ConfigData&)
{ {
assert(server != NULL);
if (config->contains("classes")) { if (config->contains("classes")) {
configurator->reconfigure(config->get("classes")); configurator->reconfigure(*server, config->get("classes"));
} }
} }
@@ -206,9 +207,10 @@ main(int argc, char* argv[]) {
auth_server->setTSIGKeyRing(&isc::server_common::keyring); auth_server->setTSIGKeyRing(&isc::server_common::keyring);
// Start the data source configuration // Start the data source configuration
datasrc_configurator.reset(new DataSourceConfigurator(auth_server)); datasrc_configurator.reset(new DataSourceConfigurator);
config_session->addRemoteConfig("data_sources", config_session->addRemoteConfig("data_sources",
boost::bind(datasrcConfigHandler, boost::bind(datasrcConfigHandler,
auth_server,
datasrc_configurator.get(), datasrc_configurator.get(),
_1, _2, _3), _1, _2, _3),
false); false);
@@ -217,6 +219,7 @@ main(int argc, char* argv[]) {
// get the default (or, current value). Further updates will work // get the default (or, current value). Further updates will work
// the usual way. // the usual way.
datasrc_configurator->reconfigure( datasrc_configurator->reconfigure(
*auth_server,
config_session->getRemoteConfigValue("data_sources", "classes")); config_session->getRemoteConfigValue("data_sources", "classes"));
// Now start asynchronous read. // Now start asynchronous read.

View File

@@ -98,8 +98,7 @@ protected:
// The empty string is expected value of the parameter of // The empty string is expected value of the parameter of
// requestSocket, not the app_name (there's no fallback, it checks // requestSocket, not the app_name (there's no fallback, it checks
// the empty string is passed). // the empty string is passed).
sock_requestor_(dnss_, address_store_, 53210, ""), sock_requestor_(dnss_, address_store_, 53210, "")
datasrc_configurator_(&server)
{ {
server.setDNSService(dnss_); server.setDNSService(dnss_);
server.setXfrinSession(&notify_session); server.setXfrinSession(&notify_session);
@@ -724,7 +723,7 @@ TEST_F(AuthSrvTest, notifyWithSessionMessageError) {
} }
void void
updateDatabase(DataSourceConfigurator& datasrc_configurator, updateDatabase(AuthSrv& server, DataSourceConfigurator& datasrc_configurator,
const char* params) const char* params)
{ {
const ConstElementPtr config(Element::fromJSON("{" const ConstElementPtr config(Element::fromJSON("{"
@@ -732,11 +731,11 @@ updateDatabase(DataSourceConfigurator& datasrc_configurator,
" \"type\": \"sqlite3\"," " \"type\": \"sqlite3\","
" \"params\": " + string(params) + " \"params\": " + string(params) +
"}]}")); "}]}"));
datasrc_configurator.reconfigure(config); datasrc_configurator.reconfigure(server, config);
} }
void void
updateInMemory(DataSourceConfigurator& datasrc_configurator, updateInMemory(AuthSrv& server, DataSourceConfigurator& datasrc_configurator,
const char* origin, const char* filename) const char* origin, const char* filename)
{ {
const ConstElementPtr config(Element::fromJSON("{" const ConstElementPtr config(Element::fromJSON("{"
@@ -751,17 +750,17 @@ updateInMemory(DataSourceConfigurator& datasrc_configurator,
" \"type\": \"static\"," " \"type\": \"static\","
" \"params\": \"" + string(STATIC_DSRC_FILE) + "\"" " \"params\": \"" + string(STATIC_DSRC_FILE) + "\""
"}]}")); "}]}"));
datasrc_configurator.reconfigure(config); datasrc_configurator.reconfigure(server, config);
} }
void void
updateBuiltin(DataSourceConfigurator& datasrc_configurator) { updateBuiltin(AuthSrv& server, DataSourceConfigurator& datasrc_configurator) {
const ConstElementPtr config(Element::fromJSON("{" const ConstElementPtr config(Element::fromJSON("{"
"\"CH\": [{" "\"CH\": [{"
" \"type\": \"static\"," " \"type\": \"static\","
" \"params\": \"" + string(STATIC_DSRC_FILE) + "\"" " \"params\": \"" + string(STATIC_DSRC_FILE) + "\""
"}]}")); "}]}"));
datasrc_configurator.reconfigure(config); datasrc_configurator.reconfigure(server, config);
} }
// Try giving the server a TSIG signed request and see it can anwer signed as // Try giving the server a TSIG signed request and see it can anwer signed as
@@ -772,7 +771,7 @@ TEST_F(AuthSrvTest, DISABLED_TSIGSigned) { // Needs builtin
TEST_F(AuthSrvTest, TSIGSigned) { TEST_F(AuthSrvTest, TSIGSigned) {
#endif #endif
// Prepare key, the client message, etc // Prepare key, the client message, etc
updateBuiltin(datasrc_configurator_); updateBuiltin(server, datasrc_configurator_);
const TSIGKey key("key:c2VjcmV0Cg==:hmac-sha1"); const TSIGKey key("key:c2VjcmV0Cg==:hmac-sha1");
TSIGContext context(key); TSIGContext context(key);
UnitTestUtil::createRequestMessage(request_message, opcode, default_qid, UnitTestUtil::createRequestMessage(request_message, opcode, default_qid,
@@ -820,7 +819,7 @@ TEST_F(AuthSrvTest, DISABLED_builtInQueryViaDNSServer) {
#else #else
TEST_F(AuthSrvTest, builtInQueryViaDNSServer) { TEST_F(AuthSrvTest, builtInQueryViaDNSServer) {
#endif #endif
updateBuiltin(datasrc_configurator_); updateBuiltin(server, datasrc_configurator_);
UnitTestUtil::createRequestMessage(request_message, Opcode::QUERY(), UnitTestUtil::createRequestMessage(request_message, Opcode::QUERY(),
default_qid, Name("VERSION.BIND."), default_qid, Name("VERSION.BIND."),
RRClass::CH(), RRType::TXT()); RRClass::CH(), RRType::TXT());
@@ -852,7 +851,7 @@ TEST_F(AuthSrvTest, DISABLED_builtInQuery) {
#else #else
TEST_F(AuthSrvTest, builtInQuery) { TEST_F(AuthSrvTest, builtInQuery) {
#endif #endif
updateBuiltin(datasrc_configurator_); updateBuiltin(server, datasrc_configurator_);
UnitTestUtil::createRequestMessage(request_message, Opcode::QUERY(), UnitTestUtil::createRequestMessage(request_message, Opcode::QUERY(),
default_qid, Name("VERSION.BIND."), default_qid, Name("VERSION.BIND."),
RRClass::CH(), RRType::TXT()); RRClass::CH(), RRType::TXT());
@@ -873,7 +872,7 @@ TEST_F(AuthSrvTest, DISABLED_iqueryViaDNSServer) { // Needs builtin
#else #else
TEST_F(AuthSrvTest, iqueryViaDNSServer) { // Needs builtin TEST_F(AuthSrvTest, iqueryViaDNSServer) { // Needs builtin
#endif #endif
updateBuiltin(datasrc_configurator_); updateBuiltin(server, datasrc_configurator_);
createDataFromFile("iquery_fromWire.wire"); createDataFromFile("iquery_fromWire.wire");
(*server.getDNSLookupProvider())(*io_message, parse_message, (*server.getDNSLookupProvider())(*io_message, parse_message,
response_message, response_message,
@@ -895,7 +894,7 @@ TEST_F(AuthSrvTest, DISABLED_updateConfig) {
#else #else
TEST_F(AuthSrvTest, updateConfig) { TEST_F(AuthSrvTest, updateConfig) {
#endif #endif
updateDatabase(datasrc_configurator_, CONFIG_TESTDB); updateDatabase(server, datasrc_configurator_, CONFIG_TESTDB);
// query for existent data in the installed data source. The resulting // query for existent data in the installed data source. The resulting
// response should have the AA flag on, and have an RR in each answer // response should have the AA flag on, and have an RR in each answer
@@ -913,7 +912,7 @@ TEST_F(AuthSrvTest, DISABLED_datasourceFail) {
#else #else
TEST_F(AuthSrvTest, datasourceFail) { TEST_F(AuthSrvTest, datasourceFail) {
#endif #endif
updateDatabase(datasrc_configurator_, CONFIG_TESTDB); updateDatabase(server, datasrc_configurator_, CONFIG_TESTDB);
// This query will hit a corrupted entry of the data source (the zoneload // This query will hit a corrupted entry of the data source (the zoneload
// tool and the data source itself naively accept it). This will result // tool and the data source itself naively accept it). This will result
@@ -933,10 +932,11 @@ TEST_F(AuthSrvTest, DISABLED_updateConfigFail) {
TEST_F(AuthSrvTest, updateConfigFail) { TEST_F(AuthSrvTest, updateConfigFail) {
#endif #endif
// First, load a valid data source. // First, load a valid data source.
updateDatabase(datasrc_configurator_, CONFIG_TESTDB); updateDatabase(server, datasrc_configurator_, CONFIG_TESTDB);
// Next, try to update it with a non-existent one. This should fail. // Next, try to update it with a non-existent one. This should fail.
EXPECT_THROW(updateDatabase(datasrc_configurator_, BADCONFIG_TESTDB), EXPECT_THROW(updateDatabase(server, datasrc_configurator_,
BADCONFIG_TESTDB),
isc::datasrc::DataSourceError); isc::datasrc::DataSourceError);
// The original data source should still exist. // The original data source should still exist.
@@ -959,7 +959,7 @@ TEST_F(AuthSrvTest, updateWithInMemoryClient) {
" \"params\": {}," " \"params\": {},"
" \"cache-enable\": true" " \"cache-enable\": true"
"}]}")); "}]}"));
datasrc_configurator_.reconfigure(config); datasrc_configurator_.reconfigure(server, config);
// after successful configuration, we should have one (with empty zoneset). // after successful configuration, we should have one (with empty zoneset).
// The memory data source is empty, should return REFUSED rcode. // The memory data source is empty, should return REFUSED rcode.
@@ -980,7 +980,8 @@ TEST_F(AuthSrvTest, queryWithInMemoryClientNoDNSSEC) {
// query handler class, and confirm it returns no error and a non empty // query handler class, and confirm it returns no error and a non empty
// answer section. Detailed examination on the response content // answer section. Detailed examination on the response content
// for various types of queries are tested in the query tests. // for various types of queries are tested in the query tests.
updateInMemory(datasrc_configurator_, "example.", CONFIG_INMEMORY_EXAMPLE); updateInMemory(server, datasrc_configurator_, "example.",
CONFIG_INMEMORY_EXAMPLE);
createDataFromFile("nsec3query_nodnssec_fromWire.wire"); createDataFromFile("nsec3query_nodnssec_fromWire.wire");
server.processMessage(*io_message, *parse_message, *response_obuffer, server.processMessage(*io_message, *parse_message, *response_obuffer,
@@ -999,7 +1000,8 @@ TEST_F(AuthSrvTest, queryWithInMemoryClientDNSSEC) {
// Similar to the previous test, but the query has the DO bit on. // 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 response should contain RRSIGs, and should have more RRs than
// the previous case. // the previous case.
updateInMemory(datasrc_configurator_, "example.", CONFIG_INMEMORY_EXAMPLE); updateInMemory(server, datasrc_configurator_, "example.",
CONFIG_INMEMORY_EXAMPLE);
createDataFromFile("nsec3query_fromWire.wire"); createDataFromFile("nsec3query_fromWire.wire");
server.processMessage(*io_message, *parse_message, *response_obuffer, server.processMessage(*io_message, *parse_message, *response_obuffer,
@@ -1019,7 +1021,8 @@ TEST_F(AuthSrvTest,
) )
{ {
// Set up the in-memory // Set up the in-memory
updateInMemory(datasrc_configurator_, "example.", CONFIG_INMEMORY_EXAMPLE); updateInMemory(server, datasrc_configurator_, "example.",
CONFIG_INMEMORY_EXAMPLE);
// This shouldn't affect the result of class CH query // This shouldn't affect the result of class CH query
UnitTestUtil::createRequestMessage(request_message, Opcode::QUERY(), UnitTestUtil::createRequestMessage(request_message, Opcode::QUERY(),
@@ -1431,7 +1434,8 @@ TEST_F(AuthSrvTest,
) )
{ {
// Set real inmem client to proxy // Set real inmem client to proxy
updateInMemory(datasrc_configurator_, "example.", CONFIG_INMEMORY_EXAMPLE); updateInMemory(server, datasrc_configurator_, "example.",
CONFIG_INMEMORY_EXAMPLE);
{ {
isc::util::thread::Mutex::Locker locker(server.getClientListMutex()); isc::util::thread::Mutex::Locker locker(server.getClientListMutex());
boost::shared_ptr<isc::datasrc::ConfigurableClientList> boost::shared_ptr<isc::datasrc::ConfigurableClientList>
@@ -1456,17 +1460,18 @@ TEST_F(AuthSrvTest,
// If non null rrset is given, it will be passed to the proxy so it can // If non null rrset is given, it will be passed to the proxy so it can
// return some faked response. // return some faked response.
void void
setupThrow(AuthSrv* server, DataSourceConfigurator& datasrc_configurator, setupThrow(AuthSrv& server, DataSourceConfigurator& datasrc_configurator,
ThrowWhen throw_when, bool isc_exception, ThrowWhen throw_when, bool isc_exception,
ConstRRsetPtr rrset = ConstRRsetPtr()) ConstRRsetPtr rrset = ConstRRsetPtr())
{ {
updateInMemory(datasrc_configurator, "example.", CONFIG_INMEMORY_EXAMPLE); updateInMemory(server, datasrc_configurator, "example.",
CONFIG_INMEMORY_EXAMPLE);
isc::util::thread::Mutex::Locker locker(server->getClientListMutex()); isc::util::thread::Mutex::Locker locker(server.getClientListMutex());
boost::shared_ptr<isc::datasrc::ConfigurableClientList> boost::shared_ptr<isc::datasrc::ConfigurableClientList>
list(new FakeList(server->getClientList(RRClass::IN()), throw_when, list(new FakeList(server.getClientList(RRClass::IN()), throw_when,
isc_exception, rrset)); isc_exception, rrset));
server->setClientList(RRClass::IN(), list); server.setClientList(RRClass::IN(), list);
} }
TEST_F(AuthSrvTest, TEST_F(AuthSrvTest,
@@ -1489,11 +1494,11 @@ TEST_F(AuthSrvTest,
RRClass::IN(), RRType::TXT()); RRClass::IN(), RRType::TXT());
for (ThrowWhen* when(throws); *when != THROW_NEVER; ++when) { for (ThrowWhen* when(throws); *when != THROW_NEVER; ++when) {
createRequestPacket(request_message, IPPROTO_UDP); createRequestPacket(request_message, IPPROTO_UDP);
setupThrow(&server, datasrc_configurator_, *when, true); setupThrow(server, datasrc_configurator_, *when, true);
processAndCheckSERVFAIL(); processAndCheckSERVFAIL();
// To be sure, check same for non-isc-exceptions // To be sure, check same for non-isc-exceptions
createRequestPacket(request_message, IPPROTO_UDP); createRequestPacket(request_message, IPPROTO_UDP);
setupThrow(&server, datasrc_configurator_, *when, false); setupThrow(server, datasrc_configurator_, *when, false);
processAndCheckSERVFAIL(); processAndCheckSERVFAIL();
} }
} }
@@ -1509,7 +1514,7 @@ TEST_F(AuthSrvTest,
) )
{ {
createDataFromFile("nsec3query_nodnssec_fromWire.wire"); createDataFromFile("nsec3query_nodnssec_fromWire.wire");
setupThrow(&server, datasrc_configurator_, THROW_AT_GET_CLASS, true); setupThrow(server, datasrc_configurator_, THROW_AT_GET_CLASS, true);
// getClass is not called so it should just answer // getClass is not called so it should just answer
server.processMessage(*io_message, *parse_message, *response_obuffer, server.processMessage(*io_message, *parse_message, *response_obuffer,
@@ -1533,7 +1538,7 @@ TEST_F(AuthSrvTest,
ConstRRsetPtr empty_rrset(new RRset(Name("foo.example"), ConstRRsetPtr empty_rrset(new RRset(Name("foo.example"),
RRClass::IN(), RRType::TXT(), RRClass::IN(), RRType::TXT(),
RRTTL(0))); RRTTL(0)));
setupThrow(&server, datasrc_configurator_, THROW_NEVER, true, empty_rrset); setupThrow(server, datasrc_configurator_, THROW_NEVER, true, empty_rrset);
// Repeat the query processing two times. Due to the faked RRset, // Repeat the query processing two times. Due to the faked RRset,
// toWire() should throw, and it should result in SERVFAIL. // toWire() should throw, and it should result in SERVFAIL.

View File

@@ -64,7 +64,6 @@ class AuthCommandTest : public ::testing::Test {
protected: protected:
AuthCommandTest() : AuthCommandTest() :
server_(xfrout_, ddns_forwarder_), server_(xfrout_, ddns_forwarder_),
datasrc_configurator_(&server_),
rcode_(-1), rcode_(-1),
expect_rcode_(0), expect_rcode_(0),
itimer_(server_.getIOService()) itimer_(server_.getIOService())
@@ -210,7 +209,7 @@ configureZones(AuthSrv& server, DataSourceConfigurator& datasrc_configurator) {
" \"cache-enable\": true" " \"cache-enable\": true"
"}]}")); "}]}"));
datasrc_configurator.reconfigure(config); datasrc_configurator.reconfigure(server, config);
zoneChecks(server); zoneChecks(server);
} }
@@ -273,7 +272,7 @@ TEST_F(AuthCommandTest,
" \"cache-enable\": true," " \"cache-enable\": true,"
" \"cache-zones\": [\"example.org\"]" " \"cache-zones\": [\"example.org\"]"
"}]}")); "}]}"));
datasrc_configurator_.reconfigure(config); datasrc_configurator_.reconfigure(server_, config);
{ {
isc::util::thread::Mutex::Locker locker(server_.getClientListMutex()); isc::util::thread::Mutex::Locker locker(server_.getClientListMutex());
@@ -337,7 +336,7 @@ TEST_F(AuthCommandTest,
" \"cache-enable\": true," " \"cache-enable\": true,"
" \"cache-zones\": [\"example.com\"]" " \"cache-zones\": [\"example.com\"]"
"}]}")); "}]}"));
EXPECT_THROW(datasrc_configurator_.reconfigure(config2), EXPECT_THROW(datasrc_configurator_.reconfigure(server_, config2),
ConfigurableClientList::ConfigurationError); ConfigurableClientList::ConfigurationError);
result_ = execAuthServerCommand(server_, "loadzone", result_ = execAuthServerCommand(server_, "loadzone",

View File

@@ -66,12 +66,13 @@ typedef DataSourceConfiguratorGeneric<DatasrcConfiguratorTest,
FakeList> Configurator; FakeList> Configurator;
void void
datasrcConfigHandler(Configurator* configurator, const std::string&, datasrcConfigHandler(DatasrcConfiguratorTest* fake_server,
Configurator* configurator, const std::string&,
isc::data::ConstElementPtr config, isc::data::ConstElementPtr config,
const isc::config::ConfigData&) const isc::config::ConfigData&)
{ {
if (config->contains("classes")) { if (config->contains("classes")) {
configurator->reconfigure(config->get("classes")); configurator->reconfigure(*fake_server, config->get("classes"));
} }
} }
@@ -102,7 +103,6 @@ protected:
DatasrcConfiguratorTest() : DatasrcConfiguratorTest() :
session(ElementPtr(new ListElement), ElementPtr(new ListElement), session(ElementPtr(new ListElement), ElementPtr(new ListElement),
ElementPtr(new ListElement)), ElementPtr(new ListElement)),
configurator_(this),
specfile(string(TEST_OWN_DATA_DIR) + "/spec.spec") specfile(string(TEST_OWN_DATA_DIR) + "/spec.spec")
{ {
initSession(); initSession();
@@ -129,7 +129,8 @@ protected:
add(createAnswer(0, ElementPtr(new MapElement))); add(createAnswer(0, ElementPtr(new MapElement)));
} }
mccs->addRemoteConfig("data_sources", mccs->addRemoteConfig("data_sources",
boost::bind(datasrcConfigHandler, &configurator_, boost::bind(datasrcConfigHandler,
this, &configurator_,
_1, _2, _3), false); _1, _2, _3), false);
} }
void SetUp() { void SetUp() {
@@ -168,10 +169,11 @@ TEST_F(DatasrcConfiguratorTest, DISABLED_initialization) {
EXPECT_TRUE(session.haveSubscription("data_sources", "*")); EXPECT_TRUE(session.haveSubscription("data_sources", "*"));
EXPECT_FALSE(session.haveSubscription("data_sources", "*")); EXPECT_FALSE(session.haveSubscription("data_sources", "*"));
// We can't reconfigure now (not even manually) // We can't reconfigure now (not even manually)
EXPECT_THROW(configurator_.reconfigure(ElementPtr(new MapElement())), EXPECT_THROW(configurator_.reconfigure(*this,
ElementPtr(new MapElement())),
InvalidOperation); InvalidOperation);
// If the server param is NULL, it does not work // If the server param is NULL, it does not work
EXPECT_THROW(Configurator(NULL), InvalidParameter); EXPECT_THROW(Configurator configurator, InvalidParameter);
EXPECT_FALSE(session.haveSubscription("data_sources", "*")); // TBD EXPECT_FALSE(session.haveSubscription("data_sources", "*")); // TBD
// But we can initialize it again now // But we can initialize it again now
EXPECT_NO_THROW(init()); EXPECT_NO_THROW(init());
@@ -281,7 +283,7 @@ TEST_F(DatasrcConfiguratorTest, rollbackDeletion) {
const ElementPtr const ElementPtr
config1(Element::fromJSON("{\"IN\": [{\"type\": \"yyy\"}], " config1(Element::fromJSON("{\"IN\": [{\"type\": \"yyy\"}], "
"\"CH\": [{\"type\": \"xxx\"}]}")); "\"CH\": [{\"type\": \"xxx\"}]}"));
configurator_.reconfigure(config1); configurator_.reconfigure(*this, config1);
const ElementPtr const ElementPtr
config2(Element::fromJSON("{\"IN\": [{\"type\": 13}]}")); config2(Element::fromJSON("{\"IN\": [{\"type\": 13}]}"));
// This would delete CH. However, the IN one fails. // This would delete CH. However, the IN one fails.
@@ -289,7 +291,7 @@ TEST_F(DatasrcConfiguratorTest, rollbackDeletion) {
// and there's no known way to cause an exception during the // and there's no known way to cause an exception during the
// deletions, it is not a true rollback, but the result should // deletions, it is not a true rollback, but the result should
// be the same. // be the same.
EXPECT_THROW(configurator_.reconfigure(config2), TypeError); EXPECT_THROW(configurator_.reconfigure(*this, config2), TypeError);
EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf()); EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
EXPECT_EQ("xxx", lists_[RRClass::CH()]->getConf()); EXPECT_EQ("xxx", lists_[RRClass::CH()]->getConf());
} }
@@ -302,13 +304,13 @@ TEST_F(DatasrcConfiguratorTest, rollbackConfiguration) {
const ElementPtr const ElementPtr
config1(Element::fromJSON("{\"IN\": [{\"type\": \"yyy\"}], " config1(Element::fromJSON("{\"IN\": [{\"type\": \"yyy\"}], "
"\"CH\": [{\"type\": \"xxx\"}]}")); "\"CH\": [{\"type\": \"xxx\"}]}"));
configurator_.reconfigure(config1); configurator_.reconfigure(*this, config1);
// Now, the CH happens first. But nevertheless, it should be // Now, the CH happens first. But nevertheless, it should be
// restored to the previoeus version. // restored to the previoeus version.
const ElementPtr const ElementPtr
config2(Element::fromJSON("{\"IN\": [{\"type\": 13}], " config2(Element::fromJSON("{\"IN\": [{\"type\": 13}], "
"\"CH\": [{\"type\": \"yyy\"}]}")); "\"CH\": [{\"type\": \"yyy\"}]}"));
EXPECT_THROW(configurator_.reconfigure(config2), TypeError); EXPECT_THROW(configurator_.reconfigure(*this, config2), TypeError);
EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf()); EXPECT_EQ("yyy", lists_[RRClass::IN()]->getConf());
EXPECT_EQ("xxx", lists_[RRClass::CH()]->getConf()); EXPECT_EQ("xxx", lists_[RRClass::CH()]->getConf());
} }