option_defs = LibDHCP::getOptionDefs(Option::V4);
} else if (!option_space.empty()) {
OptionDefContainerPtr option_defs_ptr = CfgMgr::instance()
- .getCurrentCfg()->getCfgOptionDef().getAll(option_space);
+ .getCurrentCfg()->getCfgOptionDef()->getAll(option_space);
if (option_defs_ptr != NULL) {
option_defs = *option_defs_ptr;
}
srv_.reset(new Dhcpv4Srv(0));
// Create fresh context.
globalContext()->copyContext(ParserContext(Option::V4));
+ resetConfiguration();
}
// Check that no hooks libraries are loaded. This is a pre-condition for
void resetConfiguration() {
string config = "{ \"interfaces\": [ \"*\" ],"
"\"hooks-libraries\": [ ], "
- "\"rebind-timer\": 2000, "
- "\"renew-timer\": 1000, "
"\"valid-lifetime\": 4000, "
"\"subnet4\": [ ], "
"\"dhcp-ddns\": { \"enable-updates\" : false }, "
"\"option-data\": [ ] }";
static_cast<void>(executeConfiguration(config,
"reset configuration database"));
+ CfgMgr::instance().clear();
}
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
- OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()
- ->getCfgOptionDef().get("isc", 100);
+ OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
- def = CfgMgr::instance().getCurrentCfg()->getCfgOptionDef().get("isc", 100);
+ def = CfgMgr::instance().getStagingCfg()->getCfgOptionDef()->get("isc", 100);
ASSERT_TRUE(def);
// Verify that the option definition data is valid.
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
- OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100);
+ OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
- def = CfgMgr::instance().getCurrentCfg()->getCfgOptionDef().get("isc", 100);
+ def = CfgMgr::instance().getStagingCfg()->getCfgOptionDef()->get("isc", 100);
ASSERT_TRUE(def);
// Check the option data.
ElementPtr json = Element::fromJSON(config);
// Make sure that the option definitions do not exist yet.
- ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100));
- ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 101));
+ ASSERT_FALSE(CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100));
+ ASSERT_FALSE(CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 101));
// Use the configuration string to create new option definitions.
ConstElementPtr status;
checkResult(status, 0);
// Check the first definition we have created.
- OptionDefinitionPtr def1 = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100);
+ OptionDefinitionPtr def1 = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100);
ASSERT_TRUE(def1);
// Check the option data.
EXPECT_TRUE(def1->getEncapsulatedSpace().empty());
// Check the second option definition we have created.
- OptionDefinitionPtr def2 = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 101);
+ OptionDefinitionPtr def2 = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 101);
ASSERT_TRUE(def2);
// Check the option data.
ElementPtr json = Element::fromJSON(config);
// Make sure that the option definition does not exist yet.
- ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100));
+ ASSERT_FALSE(CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100));
// Use the configuration string to create new option definitions.
ConstElementPtr status;
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
- OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100);
+ OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
- def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100);
+ def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100);
ASSERT_TRUE(def);
// Check the option data.
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
- OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100);
+ OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
- def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100);
+ def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100);
ASSERT_TRUE(def);
// Check the option data.
"}";
ElementPtr json = Element::fromJSON(config);
- OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("dhcp4", 109);
+ OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("dhcp4", 109);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
- def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("dhcp4", 109);
+ def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("dhcp4", 109);
ASSERT_TRUE(def);
// Check the option data.
// Expecting success.
checkResult(status, 0);
- def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("dhcp4", 65);
+ def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("dhcp4", 65);
ASSERT_TRUE(def);
// Check the option data.
ASSERT_TRUE(status);
checkResult(status, 0);
+ CfgMgr::instance().clear();
+
// Stage 2. Configure base option and a subnet. Please note that
// the configuration from the stage 2 is repeated because BIND
// configuration manager sends whole configuration for the lists
ASSERT_TRUE(status);
checkResult(status, 0);
+ CfgMgr::instance().clear();
+
// Once the definitions have been added we can configure the
// standard option #17. This option comprises an enterprise
// number and sub options. By convention (introduced in
EXPECT_TRUE(checkMarkerFile(LOAD_MARKER_FILE, "12"));
EXPECT_FALSE(checkMarkerFileExists(UNLOAD_MARKER_FILE));
+ // Commit the changes so as we get the fresh configuration for the
+ // second part of this test.
+ CfgMgr::instance().commit();
+
// Unload the libraries. The load file should not have changed, but
// the unload one should indicate the unload() functions have been run.
config = buildHooksLibrariesConfig();
#include <dhcp/dhcp4.h>
#include <dhcp4/ctrl_dhcp4_srv.h>
#include <dhcpsrv/cfgmgr.h>
+#include <log/logger_unittest_support.h>
#include <boost/scoped_ptr.hpp>
#include <gtest/gtest.h>
}
~JSONFileBackendTest() {
+ isc::log::resetUnitTestRootLogger();
static_cast<void>(unlink(TEST_FILE));
};
option_defs = LibDHCP::getOptionDefs(Option::V6);
} else if (!option_space.empty()) {
OptionDefContainerPtr option_defs_ptr =
- CfgMgr::instance().getCurrentCfg()->getCfgOptionDef()
- .getAll(option_space);
+ CfgMgr::instance().getCurrentCfg()->getCfgOptionDef()->
+ getAll(option_space);
if (option_defs_ptr != NULL) {
option_defs = *option_defs_ptr;
}
try {
ElementPtr json = Element::fromJSON(config);
status = configureDhcp6Server(srv_, json);
+
} catch (const std::exception& ex) {
ADD_FAILURE() << "Unable to " << operation << ". "
<< "The following configuration was used: " << std::endl
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
checkResult(x, 1);
EXPECT_TRUE(errorContainsPosition(x, "<string>"));
+ CfgMgr::instance().clear();
}
/// @brief Test invalid option paramater value.
EXPECT_NO_THROW(x = configureDhcp6Server(srv_, json));
checkResult(x, 1);
EXPECT_TRUE(errorContainsPosition(x, "<string>"));
+ CfgMgr::instance().clear();
}
/// @brief Test option against given code and data.
const size_t expected_data_len) {
std::string config = createConfigWithOption(params);
ASSERT_TRUE(executeConfiguration(config, "parse option configuration"));
+
// The subnet should now hold one option with the specified code.
Subnet::OptionDescriptor desc =
getOptionFromSubnet(IOAddress("2001:db8:1::5"), option_code);
ASSERT_TRUE(desc.option);
testOption(desc, option_code, expected_data, expected_data_len);
+ CfgMgr::instance().clear();
}
int rcode_; ///< Return code (see @ref isc::config::parseAnswer)
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
- OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100);
+ OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
ASSERT_TRUE(status);
// The option definition should now be available in the CfgMgr.
- def = CfgMgr::instance().getCurrentCfg()->getCfgOptionDef().get("isc", 100);
+ def = CfgMgr::instance().getStagingCfg()->getCfgOptionDef()->get("isc", 100);
ASSERT_TRUE(def);
// Verify that the option definition data is valid.
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
- OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100);
+ OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
- def = CfgMgr::instance().getCurrentCfg()->getCfgOptionDef().get("isc", 100);
+ def = CfgMgr::instance().getStagingCfg()->getCfgOptionDef()->get("isc", 100);
ASSERT_TRUE(def);
// Check the option data.
ElementPtr json = Element::fromJSON(config);
// Make sure that the option definitions do not exist yet.
- ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100));
- ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 101));
+ ASSERT_FALSE(CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100));
+ ASSERT_FALSE(CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 101));
// Use the configuration string to create new option definitions.
ConstElementPtr status;
checkResult(status, 0);
// Check the first definition we have created.
- OptionDefinitionPtr def1 = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100);
+ OptionDefinitionPtr def1 = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100);
ASSERT_TRUE(def1);
// Check the option data.
EXPECT_FALSE(def1->getArrayType());
// Check the second option definition we have created.
- OptionDefinitionPtr def2 = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 101);
+ OptionDefinitionPtr def2 = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 101);
ASSERT_TRUE(def2);
// Check the option data.
ElementPtr json = Element::fromJSON(config);
// Make sure that the option definition does not exist yet.
- ASSERT_FALSE(CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100));
+ ASSERT_FALSE(CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100));
// Use the configuration string to create new option definitions.
ConstElementPtr status;
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
- OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100);
+ OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
- def = CfgMgr::instance().getCurrentCfg()->getCfgOptionDef().get("isc", 100);
+ def = CfgMgr::instance().getStagingCfg()->getCfgOptionDef()->get("isc", 100);
ASSERT_TRUE(def);
// Check the option data.
ElementPtr json = Element::fromJSON(config);
// Make sure that the particular option definition does not exist.
- OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("isc", 100);
+ OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("isc", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
- def = CfgMgr::instance().getCurrentCfg()->getCfgOptionDef().get("isc", 100);
+ def = CfgMgr::instance().getStagingCfg()->getCfgOptionDef()->get("isc", 100);
ASSERT_TRUE(def);
// Check the option data.
"}";
ElementPtr json = Element::fromJSON(config);
- OptionDefinitionPtr def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("dhcp6", 100);
+ OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("dhcp6", 100);
ASSERT_FALSE(def);
// Use the configuration string to create new option definition.
checkResult(status, 0);
// The option definition should now be available in the CfgMgr.
- def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("dhcp6", 100);
+ def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("dhcp6", 100);
ASSERT_TRUE(def);
// Check the option data.
// Expecting success.
checkResult(status, 0);
- def = CfgMgr::instance().getCurrentCfg()->
- getCfgOptionDef().get("dhcp6", 59);
+ def = CfgMgr::instance().getStagingCfg()->
+ getCfgOptionDef()->get("dhcp6", 59);
ASSERT_TRUE(def);
// Check the option data.
ASSERT_TRUE(status);
checkResult(status, 0);
+ CfgMgr::instance().clear();
+
// Stage 2. Configure base option and a subnet. Please note that
// the configuration from the stage 2 is repeated because BIND
// configuration manager sends whole configuration for the lists
ASSERT_TRUE(executeConfiguration(config, "parse configuration with a"
" boolean value"));
+ CfgMgr::instance().commit();
+
// The subnet should now hold one option with the code 1000.
Subnet::OptionDescriptor desc =
getOptionFromSubnet(IOAddress("2001:db8:1::5"), 1000);
ASSERT_TRUE(status);
checkResult(status, 0);
+ CfgMgr::instance().clear();
+
// Once the definitions have been added we can configure the
// standard option #17. This option comprises an enterprise
// number and sub options. By convention (introduced in
EXPECT_TRUE(checkMarkerFile(LOAD_MARKER_FILE, "12"));
EXPECT_FALSE(checkMarkerFileExists(UNLOAD_MARKER_FILE));
+ CfgMgr::instance().commit();
+
// Unload the libraries. The load file should not have changed, but
// the unload one should indicate the unload() functions have been run.
config = buildHooksLibrariesConfig();
#include <dhcp/dhcp6.h>
#include <dhcp6/ctrl_dhcp6_srv.h>
#include <dhcpsrv/cfgmgr.h>
+#include <log/logger_unittest_support.h>
#include <boost/scoped_ptr.hpp>
#include <gtest/gtest.h>
}
~JSONFileBackendTest() {
+ isc::log::resetUnitTestRootLogger();
static_cast<void>(unlink(TEST_FILE));
};
};
+/// @name Pointers to the @c CfgOptionDef objects.
+//@{
+/// @brief Non-const pointer.
+typedef boost::shared_ptr<CfgOptionDef> CfgOptionDefPtr;
+
+/// @brief Const pointer.
+typedef boost::shared_ptr<const CfgOptionDef> ConstCfgOptionDefPtr;
+
+//@}
+
}
}
// options. They are expected to be in the global storage
// already.
OptionDefContainerPtr defs =
- CfgMgr::instance().getStagingCfg()->getCfgOptionDef().getAll(space);
+ CfgMgr::instance().getStagingCfg()->getCfgOptionDef()->getAll(space);
// The getItems() should never return the NULL pointer. If there are
// no option definitions for the particular option space a pointer
// Create an instance of option definition.
createOptionDef(option_def);
- CfgOptionDef cfg = CfgMgr::instance().getStagingCfg()->getCfgOptionDef();
try {
- cfg.add(option_definition_, option_space_name_);
+ CfgMgr::instance().getStagingCfg()->getCfgOptionDef()->
+ add(option_definition_, option_space_name_);
} catch (const std::exception& ex) {
- // Append position
+ // Append position if there is a failure.
isc_throw(DhcpConfigError, ex.what() << " ("
<< option_def->getPosition() << ")");
}
- CfgMgr::instance().getStagingCfg()->setCfgOptionDef(cfg);
}
void
}
} else {
OptionDefContainerPtr defs = CfgMgr::instance().getStagingCfg()
- ->getCfgOptionDef().getAll(option_space);
+ ->getCfgOptionDef()->getAll(option_space);
const OptionDefContainerTypeIndex& idx = defs->get<1>();
const OptionDefContainerTypeRange& range =
namespace dhcp {
SrvConfig::SrvConfig()
- : sequence_(0) {
+ : sequence_(0), cfg_option_def_(new CfgOptionDef()) {
}
SrvConfig::SrvConfig(uint32_t sequence)
- : sequence_(sequence) {
+ : sequence_(sequence), cfg_option_def_(new CfgOptionDef()) {
}
std::string
// Replace interface configuration.
new_config.setCfgIface(cfg_iface_);
// Replace option definitions.
- new_config.setCfgOptionDef(cfg_option_def_);
+ new_config.setCfgOptionDef(*cfg_option_def_);
}
void
}
// Logging information is equal between objects, so check other values.
return ((cfg_iface_ == other.cfg_iface_) &&
- (cfg_option_def_ == other.cfg_option_def_));
+ (*cfg_option_def_ == *other.cfg_option_def_));
}
}
cfg_iface_ = cfg_iface;
}
- /// @brief Returns object which represents user-defined option definitions.
+ /// @brief Return pointer to non-const object representing user-defined
+ /// option definitions.
///
- /// This function returns a reference to the object which represents the
+ /// This function returns a pointer to the object which represents the
+ /// user defined option definitions grouped by option space name.
+ ///
+ /// @return Pointer to an object holding option definitions.
+ CfgOptionDefPtr getCfgOptionDef() {
+ return (cfg_option_def_);
+ }
+
+ /// @brief Returns pointer to the const object representing user-defined
+ /// option definitions.
+ ///
+ /// This function returns a pointer to the object which represents the
/// user defined option definitions grouped by option space name.
///
- /// @return Reference to an object holding option definitions.
- const CfgOptionDef& getCfgOptionDef() const {
+ /// @return Pointer to an object holding option definitions.
+ ConstCfgOptionDefPtr getCfgOptionDef() const {
return (cfg_option_def_);
}
///
/// @param cfg_option_def New object representing option definitions.
void setCfgOptionDef(const CfgOptionDef& cfg_option_def) {
- cfg_option_def_ = cfg_option_def;
+ *cfg_option_def_ = cfg_option_def;
}
//@}
/// queries.
CfgIface cfg_iface_;
- /// @brief Option definitions configuration.
+ /// @brief Pointer to option definitions configuration.
///
/// This object holds the user-defined option definitions grouped
/// by option space name.
- CfgOptionDef cfg_option_def_;
+ CfgOptionDefPtr cfg_option_def_;
};
// Verify that the option definition can be retrieved.
OptionDefinitionPtr def =
- CfgMgr::instance().getStagingCfg()->getCfgOptionDef().get("isc", 100);
+ CfgMgr::instance().getStagingCfg()->getCfgOptionDef()->get("isc", 100);
ASSERT_TRUE(def);
// Verify that the option definition is correct.