mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 05:55:28 +00:00
[2203] refactoring 1st step: move session obj outside of datasrc configurator.
This commit is contained in:
@@ -54,7 +54,6 @@ private:
|
||||
}
|
||||
}
|
||||
static Server* server_;
|
||||
static isc::config::ModuleCCSession* session_;
|
||||
typedef boost::shared_ptr<List> ListPtr;
|
||||
public:
|
||||
/// \brief Initializes the class.
|
||||
@@ -74,12 +73,7 @@ public:
|
||||
/// \throw isc::InvalidParameter if any of the parameters is NULL
|
||||
/// \throw isc::config::ModuleCCError if the remote configuration is not
|
||||
/// available for some reason.
|
||||
static void init(isc::config::ModuleCCSession* session,
|
||||
Server* server)
|
||||
{
|
||||
if (session == NULL) {
|
||||
isc_throw(isc::InvalidParameter, "The session must not be NULL");
|
||||
}
|
||||
static void init(Server* server) {
|
||||
if (server == NULL) {
|
||||
isc_throw(isc::InvalidParameter, "The server must not be NULL");
|
||||
}
|
||||
@@ -88,9 +82,8 @@ public:
|
||||
"The configurator is already initialized");
|
||||
}
|
||||
server_ = server;
|
||||
session_ = session;
|
||||
session->addRemoteConfig("data_sources", reconfigureInternal, false);
|
||||
}
|
||||
|
||||
/// \brief Deinitializes the class.
|
||||
///
|
||||
/// This detaches from the session and removes the server from internal
|
||||
@@ -99,12 +92,9 @@ public:
|
||||
/// This can be called even if it is not initialized currently. You
|
||||
/// can initialize it again after this.
|
||||
static void cleanup() {
|
||||
if (session_ != NULL) {
|
||||
session_->removeRemoteConfig("data_sources");
|
||||
}
|
||||
session_ = NULL;
|
||||
server_ = NULL;
|
||||
}
|
||||
|
||||
/// \brief Reads new configuration and replaces the old one.
|
||||
///
|
||||
/// It instructs the server to replace the lists with new ones as needed.
|
||||
@@ -210,10 +200,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template<class Server, class List>
|
||||
isc::config::ModuleCCSession*
|
||||
DataSourceConfiguratorGeneric<Server, List>::session_(NULL);
|
||||
|
||||
template<class Server, class List>
|
||||
Server* DataSourceConfiguratorGeneric<Server, List>::server_(NULL);
|
||||
|
||||
@@ -224,3 +210,7 @@ typedef DataSourceConfiguratorGeneric<AuthSrv,
|
||||
DataSourceConfigurator;
|
||||
|
||||
#endif
|
||||
|
||||
// Local Variables:
|
||||
// mode: c++
|
||||
// End:
|
||||
|
@@ -83,6 +83,16 @@ my_command_handler(const string& command, ConstElementPtr args) {
|
||||
return (execAuthServerCommand(*auth_server, command, args));
|
||||
}
|
||||
|
||||
void
|
||||
datasrcConfigHandler(const std::string&,
|
||||
isc::data::ConstElementPtr config,
|
||||
const isc::config::ConfigData&)
|
||||
{
|
||||
if (config->contains("classes")) {
|
||||
DataSourceConfigurator::reconfigure(config->get("classes"));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
usage() {
|
||||
cerr << "Usage: b10-auth [-v]"
|
||||
@@ -192,7 +202,9 @@ main(int argc, char* argv[]) {
|
||||
auth_server->setTSIGKeyRing(&isc::server_common::keyring);
|
||||
|
||||
// Start the data source configuration
|
||||
DataSourceConfigurator::init(config_session, auth_server);
|
||||
DataSourceConfigurator::init(auth_server);
|
||||
config_session->addRemoteConfig("data_sources", datasrcConfigHandler,
|
||||
false);
|
||||
// HACK: The default is not passed to the handler. This one will
|
||||
// get the default (or, current value). Further updates will work
|
||||
// the usual way.
|
||||
@@ -221,7 +233,8 @@ main(int argc, char* argv[]) {
|
||||
xfrin_session->disconnect();
|
||||
}
|
||||
|
||||
DataSourceConfigurator::cleanup();
|
||||
//DataSourceConfigurator::cleanup();
|
||||
config_session->removeRemoteConfig("data_sources");
|
||||
delete xfrin_session;
|
||||
delete config_session;
|
||||
delete cc_session;
|
||||
|
@@ -62,6 +62,16 @@ typedef shared_ptr<FakeList> ListPtr;
|
||||
typedef DataSourceConfiguratorGeneric<DatasrcConfiguratorTest,
|
||||
FakeList> Configurator;
|
||||
|
||||
void
|
||||
datasrcConfigHandler(const std::string&,
|
||||
isc::data::ConstElementPtr config,
|
||||
const isc::config::ConfigData&)
|
||||
{
|
||||
if (config->contains("classes")) {
|
||||
Configurator::reconfigure(config->get("classes"));
|
||||
}
|
||||
}
|
||||
|
||||
class DatasrcConfiguratorTest : public ::testing::Test {
|
||||
public:
|
||||
// These pretend to be the server
|
||||
@@ -100,6 +110,7 @@ protected:
|
||||
}
|
||||
void TearDown() {
|
||||
// Make sure no matter what we did, it is cleaned up.
|
||||
mccs->removeRemoteConfig("data_sources");
|
||||
Configurator::cleanup();
|
||||
}
|
||||
void init(const ElementPtr& config = ElementPtr()) {
|
||||
@@ -114,7 +125,8 @@ protected:
|
||||
session.getMessages()->
|
||||
add(createAnswer(0, ElementPtr(new MapElement)));
|
||||
}
|
||||
Configurator::init(mccs.get(), this);
|
||||
Configurator::init(this);
|
||||
mccs->addRemoteConfig("data_sources", datasrcConfigHandler, false);
|
||||
}
|
||||
void SetUp() {
|
||||
init();
|
||||
@@ -126,10 +138,10 @@ protected:
|
||||
return (external);
|
||||
}
|
||||
void initializeINList() {
|
||||
const ElementPtr
|
||||
const ConstElementPtr
|
||||
config(buildConfig("{\"IN\": [{\"type\": \"xxx\"}]}"));
|
||||
session.addMessage(createCommand("config_update", config), "data_sources",
|
||||
"*");
|
||||
session.addMessage(createCommand("config_update", config),
|
||||
"data_sources", "*");
|
||||
mccs->checkCommand();
|
||||
// Check it called the correct things (check that there's no IN yet and
|
||||
// set a new one.
|
||||
@@ -150,15 +162,14 @@ TEST_F(DatasrcConfiguratorTest, initialization) {
|
||||
EXPECT_THROW(init(), InvalidOperation);
|
||||
EXPECT_TRUE(session.haveSubscription("data_sources", "*"));
|
||||
// Deinitialize to make the tests reasonable
|
||||
mccs->removeRemoteConfig("data_sources");
|
||||
Configurator::cleanup();
|
||||
EXPECT_FALSE(session.haveSubscription("data_sources", "*"));
|
||||
// We can't reconfigure now (not even manually)
|
||||
EXPECT_THROW(Configurator::reconfigure(ElementPtr(new MapElement())),
|
||||
InvalidOperation);
|
||||
// If one of them is NULL, it does not work
|
||||
EXPECT_THROW(Configurator::init(NULL, this), InvalidParameter);
|
||||
EXPECT_FALSE(session.haveSubscription("data_sources", "*"));
|
||||
EXPECT_THROW(Configurator::init(mccs.get(), NULL), InvalidParameter);
|
||||
// If the server param is NULL, it does not work
|
||||
EXPECT_THROW(Configurator::init(NULL), InvalidParameter);
|
||||
EXPECT_FALSE(session.haveSubscription("data_sources", "*"));
|
||||
// But we can initialize it again now
|
||||
EXPECT_NO_THROW(init());
|
||||
|
Reference in New Issue
Block a user