Commit d94eb9c7 authored by Francis Dupont's avatar Francis Dupont

[master] Merged trac5145b (hooks and D2 client configs)

parents c818fd4e 6af8efb1
......@@ -24,7 +24,7 @@ CtrlAgentCfgContext::CtrlAgentCfgContext()
CtrlAgentCfgContext::CtrlAgentCfgContext(const CtrlAgentCfgContext& orig)
: DCfgContextBase(),http_host_(orig.http_host_), http_port_(orig.http_port_),
libraries_(orig.libraries_) {
hooks_config_(orig.hooks_config_) {
// We're copying pointers here only. The underlying data will be shared by
// old and new context. That's how shared pointers work and I see no reason
......@@ -74,7 +74,7 @@ CtrlAgentCfgMgr::getConfigSummary(const uint32_t /*selection*/) {
}
// Finally, print the hook libraries names
const hooks::HookLibsCollection libs = ctx->getLibraries();
const isc::hooks::HookLibsCollection libs = ctx->getHooksConfig().get();
s << ", " << libs.size() << " lib(s):";
for (auto lib = libs.begin(); lib != libs.end(); ++lib) {
s << lib->first << " ";
......
......@@ -8,9 +8,9 @@
#define CTRL_AGENT_CFG_MGR_H
#include <cc/data.h>
#include <hooks/hooks_config.h>
#include <process/d_cfg_mgr.h>
#include <boost/pointer_cast.hpp>
#include <hooks/libinfo.h>
namespace isc {
namespace agent {
......@@ -61,7 +61,7 @@ public:
///
/// @param type type of the server being controlled
/// @return pointer to the Element that holds control-socket map (or NULL)
const data::ConstElementPtr getControlSocketInfo(ServerType type) const;
const isc::data::ConstElementPtr getControlSocketInfo(ServerType type) const;
/// @brief Sets information about the control socket
///
......@@ -102,20 +102,20 @@ public:
return (http_port_);
}
/// @brief Returns a list of hook libraries
/// @return a list of hook libraries
const hooks::HookLibsCollection& getLibraries() const {
return (libraries_);
/// @brief Returns non-const reference to configured hooks libraries.
///
/// @return non-const reference to configured hooks libraries.
isc::hooks::HooksConfig& getHooksConfig() {
return (hooks_config_);
}
/// @brief Sets the list of hook libraries
/// @brief Returns const reference to configured hooks libraries.
///
/// @params libs a coolection of libraries to remember.
void setLibraries(const hooks::HookLibsCollection& libs) {
libraries_ = libs;
/// @return const reference to configured hooks libraries.
const isc::hooks::HooksConfig& getHooksConfig() const {
return (hooks_config_);
}
private:
/// @brief Private copy constructor
......@@ -132,7 +132,7 @@ private:
CtrlAgentCfgContext& operator=(const CtrlAgentCfgContext& rhs);
/// Socket information will be stored here (for all supported servers)
data::ConstElementPtr ctrl_sockets_[MAX_TYPE_SUPPORTED + 1];
isc::data::ConstElementPtr ctrl_sockets_[MAX_TYPE_SUPPORTED + 1];
/// Hostname the CA should listen on.
std::string http_host_;
......@@ -140,8 +140,8 @@ private:
/// TCP port the CA should listen on.
uint16_t http_port_;
/// List of hook libraries.
hooks::HookLibsCollection libraries_;
/// @brief Configured hooks libraries.
isc::hooks::HooksConfig hooks_config_;
};
/// @brief Ctrl Agent Configuration Manager.
......
......@@ -107,22 +107,21 @@ AgentSimpleParser::parse(const CtrlAgentCfgContextPtr& ctx,
}
// Finally, let's get the hook libs!
hooks::HooksLibrariesParser hooks_parser;
using namespace isc::hooks;
HooksConfig& libraries = ctx->getHooksConfig();
ConstElementPtr hooks = config->get("hooks-libraries");
if (hooks) {
hooks_parser.parse(hooks);
hooks_parser.verifyLibraries();
hooks::HookLibsCollection libs;
hooks_parser.getLibraries(libs);
ctx->setLibraries(libs);
HooksLibrariesParser hooks_parser;
hooks_parser.parse(libraries, hooks);
libraries.verifyLibraries(hooks->getPosition());
}
if (!check_only) {
// This occurs last as if it succeeds, there is no easy way
// revert it. As a result, the failure to commit a subsequent
// change causes problems when trying to roll back.
hooks_parser.loadLibraries();
libraries.loadLibraries();
}
}
......
......@@ -10,12 +10,12 @@
#include <process/testutils/d_test_stubs.h>
#include <process/d_cfg_mgr.h>
#include <agent/tests/test_libraries.h>
#include <hooks/libinfo.h>
#include <boost/scoped_ptr.hpp>
#include <gtest/gtest.h>
using namespace isc::agent;
using namespace isc::data;
using namespace isc::dhcp;
using namespace isc::hooks;
using namespace isc::process;
......@@ -123,11 +123,10 @@ TEST(CtrlAgentCfgMgr, contextSocketInfoCopy) {
EXPECT_NO_THROW(ctx.setHttpPort(12345));
EXPECT_NO_THROW(ctx.setHttpHost("bellatrix"));
HookLibsCollection libs;
HooksConfig& libs = ctx.getHooksConfig();
string exp_name("testlib1.so");
ConstElementPtr exp_param(new StringElement("myparam"));
libs.push_back(make_pair(exp_name, exp_param));
ctx.setLibraries(libs);
libs.add(exp_name, exp_param);
// Make a copy.
DCfgContextBasePtr copy_base(ctx.clone());
......@@ -147,7 +146,7 @@ TEST(CtrlAgentCfgMgr, contextSocketInfoCopy) {
EXPECT_EQ(socket3->str(), copy->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6)->str());
// Check hook libs
HookLibsCollection libs2 = copy->getLibraries();
const HookLibsCollection& libs2 = copy->getHooksConfig().get();
ASSERT_EQ(1, libs2.size());
EXPECT_EQ(exp_name, libs2[0].first);
ASSERT_TRUE(libs2[0].second);
......@@ -160,19 +159,18 @@ TEST(CtrlAgentCfgMgr, contextHookParams) {
CtrlAgentCfgContext ctx;
// By default there should be no hooks.
HookLibsCollection libs = ctx.getLibraries();
EXPECT_TRUE(libs.empty());
HooksConfig& libs = ctx.getHooksConfig();
EXPECT_TRUE(libs.get().empty());
libs.push_back(std::make_pair("libone.so", ConstElementPtr()));
libs.push_back(std::make_pair("libtwo.so", Element::fromJSON("{\"foo\": true}")));
libs.push_back(std::make_pair("libthree.so", Element::fromJSON("{\"bar\": 42}")));
libs.add("libone.so", ConstElementPtr());
libs.add("libtwo.so", Element::fromJSON("{\"foo\": true}"));
libs.add("libthree.so", Element::fromJSON("{\"bar\": 42}"));
ctx.setLibraries(libs);
const HooksConfig& stored_libs = ctx.getHooksConfig();
EXPECT_EQ(3, stored_libs.get().size());
HookLibsCollection stored_libs = ctx.getLibraries();
EXPECT_EQ(3, stored_libs.size());
EXPECT_EQ(libs, stored_libs);
// @todo add a == operator to HooksConfig
EXPECT_EQ(libs.get(), stored_libs.get());
}
/// Control Agent configurations used in tests.
......@@ -389,7 +387,7 @@ TEST_F(AgentParserTest, configParseHooks) {
// The context now should have the library specified.
CtrlAgentCfgContextPtr ctx = cfg_mgr_.getCtrlAgentCfgContext();
HookLibsCollection libs = ctx->getLibraries();
const HookLibsCollection libs = ctx->getHooksConfig().get();
ASSERT_EQ(1, libs.size());
EXPECT_EQ(string(BASIC_CALLOUT_LIBRARY), libs[0].first);
ASSERT_TRUE(libs[0].second);
......
This diff is collapsed.
......@@ -1018,15 +1018,6 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
}
}
\"allow-client-update\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::DHCP_DDNS:
return isc::dhcp::Dhcp4Parser::make_ALLOW_CLIENT_UPDATE(driver.loc_);
default:
return isc::dhcp::Dhcp4Parser::make_STRING("allow-client-update", driver.loc_);
}
}
\"override-no-update\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::DHCP_DDNS:
......
This diff is collapsed.
......@@ -445,40 +445,39 @@ namespace isc { namespace dhcp {
TOKEN_NCR_PROTOCOL = 354,
TOKEN_NCR_FORMAT = 355,
TOKEN_ALWAYS_INCLUDE_FQDN = 356,
TOKEN_ALLOW_CLIENT_UPDATE = 357,
TOKEN_OVERRIDE_NO_UPDATE = 358,
TOKEN_OVERRIDE_CLIENT_UPDATE = 359,
TOKEN_REPLACE_CLIENT_NAME = 360,
TOKEN_GENERATED_PREFIX = 361,
TOKEN_TCP = 362,
TOKEN_JSON = 363,
TOKEN_WHEN_PRESENT = 364,
TOKEN_NEVER = 365,
TOKEN_ALWAYS = 366,
TOKEN_WHEN_NOT_PRESENT = 367,
TOKEN_LOGGING = 368,
TOKEN_LOGGERS = 369,
TOKEN_OUTPUT_OPTIONS = 370,
TOKEN_OUTPUT = 371,
TOKEN_DEBUGLEVEL = 372,
TOKEN_SEVERITY = 373,
TOKEN_DHCP6 = 374,
TOKEN_DHCPDDNS = 375,
TOKEN_TOPLEVEL_JSON = 376,
TOKEN_TOPLEVEL_DHCP4 = 377,
TOKEN_SUB_DHCP4 = 378,
TOKEN_SUB_INTERFACES4 = 379,
TOKEN_SUB_SUBNET4 = 380,
TOKEN_SUB_POOL4 = 381,
TOKEN_SUB_RESERVATION = 382,
TOKEN_SUB_OPTION_DEF = 383,
TOKEN_SUB_OPTION_DATA = 384,
TOKEN_SUB_HOOKS_LIBRARY = 385,
TOKEN_SUB_DHCP_DDNS = 386,
TOKEN_STRING = 387,
TOKEN_INTEGER = 388,
TOKEN_FLOAT = 389,
TOKEN_BOOLEAN = 390
TOKEN_OVERRIDE_NO_UPDATE = 357,
TOKEN_OVERRIDE_CLIENT_UPDATE = 358,
TOKEN_REPLACE_CLIENT_NAME = 359,
TOKEN_GENERATED_PREFIX = 360,
TOKEN_TCP = 361,
TOKEN_JSON = 362,
TOKEN_WHEN_PRESENT = 363,
TOKEN_NEVER = 364,
TOKEN_ALWAYS = 365,
TOKEN_WHEN_NOT_PRESENT = 366,
TOKEN_LOGGING = 367,
TOKEN_LOGGERS = 368,
TOKEN_OUTPUT_OPTIONS = 369,
TOKEN_OUTPUT = 370,
TOKEN_DEBUGLEVEL = 371,
TOKEN_SEVERITY = 372,
TOKEN_DHCP6 = 373,
TOKEN_DHCPDDNS = 374,
TOKEN_TOPLEVEL_JSON = 375,
TOKEN_TOPLEVEL_DHCP4 = 376,
TOKEN_SUB_DHCP4 = 377,
TOKEN_SUB_INTERFACES4 = 378,
TOKEN_SUB_SUBNET4 = 379,
TOKEN_SUB_POOL4 = 380,
TOKEN_SUB_RESERVATION = 381,
TOKEN_SUB_OPTION_DEF = 382,
TOKEN_SUB_OPTION_DATA = 383,
TOKEN_SUB_HOOKS_LIBRARY = 384,
TOKEN_SUB_DHCP_DDNS = 385,
TOKEN_STRING = 386,
TOKEN_INTEGER = 387,
TOKEN_FLOAT = 388,
TOKEN_BOOLEAN = 389
};
};
......@@ -993,10 +992,6 @@ namespace isc { namespace dhcp {
symbol_type
make_ALWAYS_INCLUDE_FQDN (const location_type& l);
static inline
symbol_type
make_ALLOW_CLIENT_UPDATE (const location_type& l);
static inline
symbol_type
make_OVERRIDE_NO_UPDATE (const location_type& l);
......@@ -1334,12 +1329,12 @@ namespace isc { namespace dhcp {
enum
{
yyeof_ = 0,
yylast_ = 733, ///< Last index in yytable_.
yynnts_ = 307, ///< Number of nonterminal symbols.
yylast_ = 729, ///< Last index in yytable_.
yynnts_ = 306, ///< Number of nonterminal symbols.
yyfinal_ = 24, ///< Termination state number.
yyterror_ = 1,
yyerrcode_ = 256,
yyntokens_ = 136 ///< Number of tokens.
yyntokens_ = 135 ///< Number of tokens.
};
......@@ -1394,10 +1389,9 @@ namespace isc { namespace dhcp {
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135
125, 126, 127, 128, 129, 130, 131, 132, 133, 134
};
const unsigned int user_token_number_max_ = 390;
const unsigned int user_token_number_max_ = 389;
const token_number_type undef_token_ = 2;
if (static_cast<int>(t) <= yyeof_)
......@@ -1430,28 +1424,28 @@ namespace isc { namespace dhcp {
{
switch (other.type_get ())
{
case 149: // value
case 153: // map_value
case 191: // socket_type
case 200: // db_type
case 405: // ncr_protocol_value
case 414: // replace_client_name_value
case 148: // value
case 152: // map_value
case 190: // socket_type
case 199: // db_type
case 404: // ncr_protocol_value
case 412: // replace_client_name_value
value.copy< ElementPtr > (other.value);
break;
case 135: // "boolean"
case 134: // "boolean"
value.copy< bool > (other.value);
break;
case 134: // "floating point"
case 133: // "floating point"
value.copy< double > (other.value);
break;
case 133: // "integer"
case 132: // "integer"
value.copy< int64_t > (other.value);
break;
case 132: // "constant string"
case 131: // "constant string"
value.copy< std::string > (other.value);
break;
......@@ -1472,28 +1466,28 @@ namespace isc { namespace dhcp {
(void) v;
switch (this->type_get ())
{
case 149: // value
case 153: // map_value
case 191: // socket_type
case 200: // db_type
case 405: // ncr_protocol_value
case 414: // replace_client_name_value
case 148: // value
case 152: // map_value
case 190: // socket_type
case 199: // db_type
case 404: // ncr_protocol_value
case 412: // replace_client_name_value
value.copy< ElementPtr > (v);
break;
case 135: // "boolean"
case 134: // "boolean"
value.copy< bool > (v);
break;
case 134: // "floating point"
case 133: // "floating point"
value.copy< double > (v);
break;
case 133: // "integer"
case 132: // "integer"
value.copy< int64_t > (v);
break;
case 132: // "constant string"
case 131: // "constant string"
value.copy< std::string > (v);
break;
......@@ -1573,28 +1567,28 @@ namespace isc { namespace dhcp {
// Type destructor.
switch (yytype)
{
case 149: // value
case 153: // map_value
case 191: // socket_type
case 200: // db_type
case 405: // ncr_protocol_value
case 414: // replace_client_name_value
case 148: // value
case 152: // map_value
case 190: // socket_type
case 199: // db_type
case 404: // ncr_protocol_value
case 412: // replace_client_name_value
value.template destroy< ElementPtr > ();
break;
case 135: // "boolean"
case 134: // "boolean"
value.template destroy< bool > ();
break;
case 134: // "floating point"
case 133: // "floating point"
value.template destroy< double > ();
break;
case 133: // "integer"
case 132: // "integer"
value.template destroy< int64_t > ();
break;
case 132: // "constant string"
case 131: // "constant string"
value.template destroy< std::string > ();
break;
......@@ -1621,28 +1615,28 @@ namespace isc { namespace dhcp {
super_type::move(s);
switch (this->type_get ())
{
case 149: // value
case 153: // map_value
case 191: // socket_type
case 200: // db_type
case 405: // ncr_protocol_value
case 414: // replace_client_name_value
case 148: // value
case 152: // map_value
case 190: // socket_type
case 199: // db_type
case 404: // ncr_protocol_value
case 412: // replace_client_name_value
value.move< ElementPtr > (s.value);
break;
case 135: // "boolean"
case 134: // "boolean"
value.move< bool > (s.value);
break;
case 134: // "floating point"
case 133: // "floating point"
value.move< double > (s.value);
break;
case 133: // "integer"
case 132: // "integer"
value.move< int64_t > (s.value);
break;
case 132: // "constant string"
case 131: // "constant string"
value.move< std::string > (s.value);
break;
......@@ -1714,7 +1708,7 @@ namespace isc { namespace dhcp {
355, 356, 357, 358, 359, 360, 361, 362, 363, 364,
365, 366, 367, 368, 369, 370, 371, 372, 373, 374,
375, 376, 377, 378, 379, 380, 381, 382, 383, 384,
385, 386, 387, 388, 389, 390
385, 386, 387, 388, 389
};
return static_cast<token_type> (yytoken_number_[type]);
}
......@@ -2319,12 +2313,6 @@ namespace isc { namespace dhcp {
return symbol_type (token::TOKEN_ALWAYS_INCLUDE_FQDN, l);
}
Dhcp4Parser::symbol_type
Dhcp4Parser::make_ALLOW_CLIENT_UPDATE (const location_type& l)
{
return symbol_type (token::TOKEN_ALLOW_CLIENT_UPDATE, l);
}
Dhcp4Parser::symbol_type
Dhcp4Parser::make_OVERRIDE_NO_UPDATE (const location_type& l)
{
......@@ -2526,7 +2514,7 @@ namespace isc { namespace dhcp {
#line 14 "dhcp4_parser.yy" // lalr1.cc:377
} } // isc::dhcp
#line 2530 "dhcp4_parser.h" // lalr1.cc:377
#line 2518 "dhcp4_parser.h" // lalr1.cc:377
......
......@@ -155,7 +155,6 @@ using namespace std;
NCR_PROTOCOL "ncr-protocol"
NCR_FORMAT "ncr-format"
ALWAYS_INCLUDE_FQDN "always-include-fqdn"
ALLOW_CLIENT_UPDATE "allow-client-update"
OVERRIDE_NO_UPDATE "override-no-update"
OVERRIDE_CLIENT_UPDATE "override-client-update"
REPLACE_CLIENT_NAME "replace-client-name"
......@@ -1487,7 +1486,6 @@ dhcp_ddns_param: enable_updates
| ncr_protocol
| ncr_format
| always_include_fqdn
| allow_client_update
| override_no_update
| override_client_update
| replace_client_name
......@@ -1564,11 +1562,6 @@ always_include_fqdn: ALWAYS_INCLUDE_FQDN COLON BOOLEAN {
ctx.stack_.back()->set("always-include-fqdn", b);
};
allow_client_update: ALLOW_CLIENT_UPDATE COLON BOOLEAN {
ElementPtr b(new BoolElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("allow-client-update", b);
};
override_no_update: OVERRIDE_NO_UPDATE COLON BOOLEAN {
ElementPtr b(new BoolElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("override-no-update", b);
......
......@@ -42,6 +42,7 @@ using namespace isc;
using namespace isc::dhcp;
using namespace isc::data;
using namespace isc::asiolink;
using namespace isc::hooks;
namespace {
......@@ -431,11 +432,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
// for option definitions. This is equivalent to commiting empty container.
LibDHCP::setRuntimeOptionDefs(OptionDefSpaceContainer());
// Some of the parsers alter the state of the system in a way that can't
// easily be undone. (Or alter it in a way such that undoing the change has
// the same risk of failure as doing the change.)
hooks::HooksLibrariesParser hooks_parser;
// Answer will hold the result.
ConstElementPtr answer;
// Rollback informs whether error occurred and original data
......@@ -515,17 +511,17 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
}
if (config_pair.first == "hooks-libraries") {
hooks_parser.parse(config_pair.second);
hooks_parser.verifyLibraries();
HooksLibrariesParser hooks_parser;
HooksConfig& libraries = srv_cfg->getHooksConfig();
hooks_parser.parse(libraries, config_pair.second);
libraries.verifyLibraries(config_pair.second->getPosition());
continue;
}
// Legacy DhcpConfigParser stuff below
if (config_pair.first == "dhcp-ddns") {
// Apply defaults if not in short cut
if (!D2ClientConfigParser::isShortCutDisabled(config_pair.second)) {
D2ClientConfigParser::setAllDefaults(config_pair.second);
}
// Apply defaults
D2ClientConfigParser::setAllDefaults(config_pair.second);
D2ClientConfigParser parser;
D2ClientConfigPtr cfg = parser.parse(config_pair.second);
srv_cfg->setD2ClientConfig(cfg);
......@@ -637,7 +633,9 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
// This occurs last as if it succeeds, there is no easy way
// revert it. As a result, the failure to commit a subsequent
// change causes problems when trying to roll back.
hooks_parser.loadLibraries();
const HooksConfig& libraries =
CfgMgr::instance().getStagingCfg()->getHooksConfig();
libraries.loadLibraries();
}
catch (const isc::Exception& ex) {
LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_FAIL).arg(ex.what());
......
// Generated 201703010915
// Generated 201703041501
// A Bison parser, made by GNU Bison 3.0.4.
// Locations for Bison parsers in C++
......
// Generated 201703010915
// Generated 201703041501
// A Bison parser, made by GNU Bison 3.0.4.
// Positions for Bison parsers in C++
......
// Generated 201703010915
// Generated 201703041501
// A Bison parser, made by GNU Bison 3.0.4.
// Stack handling for Bison parsers in C++
......
......@@ -3414,7 +3414,6 @@ TEST_F(Dhcp4ParserTest, d2ClientConfig) {
" \"ncr-protocol\" : \"UDP\", "
" \"ncr-format\" : \"JSON\", "
" \"always-include-fqdn\" : true, "
" \"allow-client-update\" : true, "
" \"override-no-update\" : true, "
" \"override-client-update\" : true, "
" \"replace-client-name\" : \"when-present\", "
......@@ -3476,7 +3475,6 @@ TEST_F(Dhcp4ParserTest, invalidD2ClientConfig) {
" \"ncr-protocol\" : \"UDP\", "
" \"ncr-format\" : \"JSON\", "
" \"always-include-fqdn\" : true, "
" \"allow-client-update\" : true, "
" \"override-no-update\" : true, "
" \"override-client-update\" : true, "
" \"replace-client-name\" : \"when-present\", "
......
......@@ -109,7 +109,6 @@ Dhcp4SrvD2Test::configureD2(bool enable_d2, const bool exp_result,
" \"ncr-protocol\" : \"UDP\", "
" \"ncr-format\" : \"JSON\", "