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