Commit d3bfac33 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[5122] Obsolete ParserContext class removed.

parent 8acb6790
......@@ -423,9 +423,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_COMMAND,
DHCP4_CONFIG_START).arg(config_set->str());
// Reset global context.
globalContext().reset(new ParserContext(Option::V4));
// Before starting any subnet operations, let's reset the subnet-id counter,
// so newly recreated configuration starts with first subnet-id equal 1.
Subnet::resetSubnetID();
......@@ -444,15 +441,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
// the same risk of failure as doing the change.)
HooksLibrariesParser hooks_parser;
// The subnet parsers implement data inheritance by directly
// accessing global storage. For this reason the global data
// parsers must store the parsed data into global storages
// immediately. This may cause data inconsistency if the
// parsing operation fails after the global storage has been
// modified. We need to preserve the original global data here
// so as we can rollback changes when an error occurs.
ParserContext original_context(*globalContext());
// Answer will hold the result.
ConstElementPtr answer;
// Rollback informs whether error occurred and original data
......@@ -661,7 +649,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
// Rollback changes as the configuration parsing failed.
if (rollback) {
globalContext().reset(new ParserContext(original_context));
// Revert to original configuration of runtime option definitions
// in the libdhcp++.
LibDHCP::revertRuntimeOptionDefs();
......@@ -677,10 +664,5 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
return (answer);
}
ParserContextPtr& globalContext() {
static ParserContextPtr global_context_ptr(new ParserContext(Option::V4));
return (global_context_ptr);
}
}; // end of isc::dhcp namespace
}; // end of isc namespace
......@@ -53,11 +53,6 @@ isc::data::ConstElementPtr
configureDhcp4Server(Dhcpv4Srv&,
isc::data::ConstElementPtr config_set);
/// @brief Returns the global context
///
/// @return a reference to the global context
ParserContextPtr& globalContext();
}; // end of isc::dhcp namespace
}; // end of isc namespace
......
......@@ -166,23 +166,10 @@ public:
// is sane.
srv_.reset(new Dhcpv4Srv(0));
// Create fresh context.
globalContext()->copyContext(ParserContext(Option::V4));
resetConfiguration();
}
public:
// Checks if global parameter of name have expected_value
void checkGlobalUint32(string name, uint32_t expected_value) {
const Uint32StoragePtr uint32_defaults =
globalContext()->uint32_values_;
try {
uint32_t actual_value = uint32_defaults->getParam(name);
EXPECT_EQ(expected_value, actual_value);
} catch (DhcpConfigError) {
ADD_FAILURE() << "Expected uint32 with name " << name
<< " not found";
}
}
// Checks if the result of DHCP server configuration has
// expected code (0 for success, other for failures).
......@@ -2864,26 +2851,23 @@ TEST_F(Dhcp4ParserTest, DISABLED_Uint32Parser) {
// CASE 1: 0 - minimum value, should work
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_,
parseDHCP4("{\"version\": 0,"
"\"renew-timer\": 0}")));
parseDHCP4("{\"renew-timer\": 0}")));
// returned value must be ok (0 is a proper value)
checkResult(status, 0);
checkGlobalUint32("renew-timer", 0);
/// @todo: check that the renew-timer is really 0
// CASE 2: 4294967295U (UINT_MAX) should work as well
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_,
parseDHCP4("{\"version\": 0,"
"\"renew-timer\": 4294967295}")));
parseDHCP4("{\"renew-timer\": 4294967295}")));
// returned value must be ok (0 is a proper value)
checkResult(status, 0);
checkGlobalUint32("renew-timer", 4294967295U);
/// @todo: check that the renew-timer is really 4294967295U
// CASE 3: 4294967296U (UINT_MAX + 1) should not work
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_,
parseJSON("{\"version\": 0,"
"\"renew-timer\": 4294967296}")));
parseJSON("{\"renew-timer\": 4294967296}")));
// returned value must be rejected (1 configuration error)
checkResult(status, 1);
......@@ -2891,8 +2875,7 @@ TEST_F(Dhcp4ParserTest, DISABLED_Uint32Parser) {
// CASE 4: -1 (UINT_MIN -1 ) should not work
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_,
parseJSON("{\"version\": 0,"
"\"renew-timer\": -1}")));
parseJSON("{\"renew-timer\": -1}")));
// returned value must be rejected (1 configuration error)
checkResult(status, 1);
......
......@@ -701,9 +701,6 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_COMMAND,
DHCP6_CONFIG_START).arg(config_set->str());
// Reset global context.
globalContext().reset(new ParserContext(Option::V6));
// Before starting any subnet operations, let's reset the subnet-id counter,
// so newly recreated configuration starts with first subnet-id equal 1.
Subnet::resetSubnetID();
......@@ -722,15 +719,6 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
// has the same risk of failure as doing the change.)
HooksLibrariesParser hooks_parser;
// The subnet parsers implement data inheritance by directly
// accessing global storage. For this reason the global data
// parsers must store the parsed data into global storages
// immediately. This may cause data inconsistency if the
// parsing operation fails after the global storage has been
// modified. We need to preserve the original global data here
// so as we can rollback changes when an error occurs.
ParserContext original_context(*globalContext());
// This is a way to convert ConstElementPtr to ElementPtr.
// We need a config that can be edited, because we will insert
// default values and will insert derived values as well.
......@@ -958,7 +946,6 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
// Rollback changes as the configuration parsing failed.
if (rollback) {
globalContext().reset(new ParserContext(original_context));
// Revert to original configuration of runtime option definitions
// in the libdhcp++.
LibDHCP::revertRuntimeOptionDefs();
......@@ -974,10 +961,5 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
return (answer);
}
ParserContextPtr& globalContext() {
static ParserContextPtr global_context_ptr(new ParserContext(Option::V6));
return (global_context_ptr);
}
}; // end of isc::dhcp namespace
}; // end of isc namespace
......@@ -38,11 +38,6 @@ class Dhcpv6Srv;
isc::data::ConstElementPtr
configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set);
/// @brief Returns the global context
///
/// @returns a reference to the global context
ParserContextPtr& globalContext();
}; // end of isc::dhcp namespace
}; // end of isc namespace
......
......@@ -524,8 +524,6 @@ public:
// all interfaces before each test and later check that this setting
// has been overridden by the configuration used in the test.
CfgMgr::instance().clear();
// Create fresh context.
globalContext()->copyContext(ParserContext(Option::V6));
}
/// @brief Retrieve an option associated with a host.
......
......@@ -34,61 +34,6 @@ using namespace isc::util;
namespace isc {
namespace dhcp {
// *********************** ParserContext *************************
ParserContext::ParserContext(Option::Universe universe):
boolean_values_(new BooleanStorage()),
uint32_values_(new Uint32Storage()),
string_values_(new StringStorage()),
hooks_libraries_(),
universe_(universe)
{
}
ParserContext::ParserContext(const ParserContext& rhs):
boolean_values_(),
uint32_values_(),
string_values_(),
hooks_libraries_(),
universe_(rhs.universe_)
{
copyContext(rhs);
}
ParserContext&
// The cppcheck version 1.56 doesn't recognize that copyContext
// copies all context fields.
// cppcheck-suppress operatorEqVarError
ParserContext::operator=(const ParserContext& rhs) {
if (this != &rhs) {
copyContext(rhs);
}
return (*this);
}
void
ParserContext::copyContext(const ParserContext& ctx) {
copyContextPointer(ctx.boolean_values_, boolean_values_);
copyContextPointer(ctx.uint32_values_, uint32_values_);
copyContextPointer(ctx.string_values_, string_values_);
copyContextPointer(ctx.hooks_libraries_, hooks_libraries_);
// Copy universe.
universe_ = ctx.universe_;
}
template<typename T>
void
ParserContext::copyContextPointer(const boost::shared_ptr<T>& source_ptr,
boost::shared_ptr<T>& dest_ptr) {
if (source_ptr) {
dest_ptr.reset(new T(*source_ptr));
} else {
dest_ptr.reset();
}
}
// **************************** DebugParser *************************
DebugParser::DebugParser(const std::string& param_name)
......
......@@ -183,68 +183,6 @@ typedef boost::shared_ptr<StringStorage> StringStoragePtr;
typedef ValueStorage<bool> BooleanStorage;
typedef boost::shared_ptr<BooleanStorage> BooleanStoragePtr;
/// @brief Container for the current parsing context. It provides a
/// single enclosure for the storage of configuration parameters,
/// options, option definitions, and other context specific information
/// that needs to be accessible throughout the parsing and parsing
/// constructs.
class ParserContext {
public:
/// @brief Constructor
///
/// @param universe is the Option::Universe value of this
/// context.
ParserContext(Option::Universe universe);
/// @brief Copy constructor
ParserContext(const ParserContext& rhs);
/// @brief Storage for boolean parameters.
BooleanStoragePtr boolean_values_;
/// @brief Storage for uint32 parameters.
Uint32StoragePtr uint32_values_;
/// @brief Storage for string parameters.
StringStoragePtr string_values_;
/// @brief Hooks libraries pointer.
///
/// The hooks libraries information is a vector of strings, each containing
/// the name of a library. Hooks libraries should only be reloaded if the
/// list of names has changed, so the list of current DHCP parameters
/// (in isc::dhcp::CfgMgr) contains an indication as to whether the list has
/// altered. This indication is implemented by storing a pointer to the
/// list of library names which is cleared when the libraries are loaded.
/// So either the pointer is null (meaning don't reload the libraries and
/// the list of current names can be obtained from the HooksManager) or it
/// is non-null (this is the new list of names, reload the libraries when
/// possible).
isc::hooks::HookLibsCollectionPtr hooks_libraries_;
/// @brief The parsing universe of this context.
Option::Universe universe_;
/// @brief Assignment operator
ParserContext& operator=(const ParserContext& rhs);
/// @brief Copy the context fields.
///
/// This class method initializes the context data by copying the data
/// stored in the context instance provided as an argument. Note that
/// this function will also handle copying the NULL pointers.
///
/// @param ctx context to be copied.
void copyContext(const ParserContext& ctx);
template<typename T>
void copyContextPointer(const boost::shared_ptr<T>& source_ptr,
boost::shared_ptr<T>& dest_ptr);
};
/// @brief Pointer to various parser context.
typedef boost::shared_ptr<ParserContext> ParserContextPtr;
/// @brief Simple data-type parser template class
///
/// This is the template class for simple data-type parsers. It supports
......@@ -629,10 +567,6 @@ private:
uint16_t address_family_;
};
///@brief Function pointer for OptionDataParser factory methods
typedef OptionDataParser *OptionDataParserFactory(const std::string&,
OptionStoragePtr options, ParserContextPtr global_context);
/// @brief Parser for option data values within a subnet.
///
/// This parser iterates over all entries that define options
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment