From: Tomek Mrugalski Date: Fri, 28 Sep 2018 15:12:53 +0000 (+0200) Subject: [#6,!54] Obsolete code removed. X-Git-Tag: 128-netconf-config_base~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=953dd8ca4ecf59621e7a8f9436f6169308de5028;p=thirdparty%2Fkea.git [#6,!54] Obsolete code removed. --- diff --git a/src/lib/process/d_cfg_mgr.cc b/src/lib/process/d_cfg_mgr.cc index 837a90193a..aded3cbb20 100644 --- a/src/lib/process/d_cfg_mgr.cc +++ b/src/lib/process/d_cfg_mgr.cc @@ -33,65 +33,9 @@ namespace process { // *********************** DCfgContextBase ************************* -DCfgContextBase::DCfgContextBase(): - boolean_values_(new BooleanStorage()), - uint32_values_(new Uint32Storage()), - string_values_(new StringStorage()) { +DCfgContextBase::DCfgContextBase() { } -DCfgContextBase::DCfgContextBase(const DCfgContextBase& rhs): - boolean_values_(new BooleanStorage(*(rhs.boolean_values_))), - uint32_values_(new Uint32Storage(*(rhs.uint32_values_))), - string_values_(new StringStorage(*(rhs.string_values_))) { -} - -const data::Element::Position& -DCfgContextBase::getParam(const std::string& name, bool& value, bool optional) { - try { - value = boolean_values_->getParam(name); - return (boolean_values_->getPosition(name)); - } catch (DhcpConfigError& ex) { - // If the parameter is not optional, re-throw the exception. - if (!optional) { - throw; - } - } - - return (data::Element::ZERO_POSITION()); -} - -const data::Element::Position& -DCfgContextBase::getParam(const std::string& name, uint32_t& value, - bool optional) { - try { - value = uint32_values_->getParam(name); - return (uint32_values_->getPosition(name)); - } catch (DhcpConfigError& ex) { - // If the parameter is not optional, re-throw the exception. - if (!optional) { - throw; - } - } - - return (data::Element::ZERO_POSITION()); -} - -const data::Element::Position& -DCfgContextBase::getParam(const std::string& name, std::string& value, - bool optional) { - try { - value = string_values_->getParam(name); - return (string_values_->getPosition(name)); - } catch (DhcpConfigError& ex) { - // If the parameter is not optional, re-throw the exception. - if (!optional) { - throw; - } - } - - return (data::Element::ZERO_POSITION()); -} - DCfgContextBase::~DCfgContextBase() { } diff --git a/src/lib/process/d_cfg_mgr.h b/src/lib/process/d_cfg_mgr.h index ca83b48e9f..6e365e3c06 100644 --- a/src/lib/process/d_cfg_mgr.h +++ b/src/lib/process/d_cfg_mgr.h @@ -63,9 +63,6 @@ typedef boost::shared_ptr DCfgContextBasePtr; /// class DCfgContextBase : public ConfigBase { public: - /// @brief Indicator that a configuration parameter is optional. - static const bool OPTIONAL = true; - static const bool REQUIRED = false; /// @brief Constructor DCfgContextBase(); @@ -73,87 +70,6 @@ public: /// @brief Destructor virtual ~DCfgContextBase(); - /// @brief Fetches the value for a given boolean configuration parameter - /// from the context. - /// - /// @param name is the name of the parameter to retrieve. - /// @param value is an output parameter in which to return the retrieved - /// value. - /// @param optional if true, the parameter is optional and the method - /// will not throw if the parameter is not found in the context. The - /// contents of the output parameter, value, will not be altered. - /// It defaults to false if not specified. - /// - /// @return The parameter's element's position information if found, - /// otherwise it returns isc::data::Element::ZERO_POSITION(). - /// - /// @throw throws DhcpConfigError if the context does not contain the - /// parameter and optional is false. - const data::Element::Position& - getParam(const std::string& name, bool& value, bool optional=false); - - /// @brief Fetches the value for a given uint32_t configuration parameter - /// from the context. - /// - /// @param name is the name of the parameter to retrieve. - /// @param value is an output parameter in which to return the retrieved - /// value. - /// @param optional if true, the parameter is optional and the method - /// will not throw if the parameter is not found in the context. The - /// contents of the output parameter, value, will not be altered. - /// - /// @return The parameter's element's position information if found, - /// otherwise it returns isc::data::Element::ZERO_POSITION(). - /// - /// @throw throws DhcpConfigError if the context does not contain the - /// parameter and optional is false. - const data::Element::Position& - getParam(const std::string& name, uint32_t& value, - bool optional=false); - - /// @brief Fetches the value for a given string configuration parameter - /// from the context. - /// - /// @param name is the name of the parameter to retrieve. - /// @param value is an output parameter in which to return the retrieved - /// value. - /// @param optional if true, the parameter is optional and the method - /// will not throw if the parameter is not found in the context. The - /// contents of the output parameter, value, will not be altered. - /// - /// @return The parameter's element's position information if found, - /// otherwise it returns isc::data::Element::ZERO_POSITION(). - /// - /// @throw throws DhcpConfigError if the context does not contain the - /// parameter and optional is false. - const data::Element::Position& - getParam(const std::string& name, std::string& value, - bool optional=false); - - /// @brief Fetches the Boolean Storage. Typically used for passing - /// into parsers. - /// - /// @return returns a pointer to the Boolean Storage. - isc::dhcp::BooleanStoragePtr getBooleanStorage() { - return (boolean_values_); - } - - /// @brief Fetches the uint32 Storage. Typically used for passing - /// into parsers. - /// - /// @return returns a pointer to the uint32 Storage. - isc::dhcp::Uint32StoragePtr getUint32Storage() { - return (uint32_values_); - } - - /// @brief Fetches the string Storage. Typically used for passing - /// into parsers. - /// - /// @return returns a pointer to the string Storage. - isc::dhcp::StringStoragePtr getStringStorage() { - return (string_values_); - } - /// @brief Creates a clone of this context object. /// /// As mentioned in the the class brief, derivation must supply an @@ -195,22 +111,9 @@ public: /// the initial configuration object virtual isc::data::ElementPtr toElement() const = 0; -protected: - /// @brief Copy constructor for use by derivations in clone(). - DCfgContextBase(const DCfgContextBase& rhs); - private: /// @brief Private assignment operator to avoid potential for slicing. DCfgContextBase& operator=(const DCfgContextBase& rhs); - - /// @brief Storage for boolean parameters. - isc::dhcp::BooleanStoragePtr boolean_values_; - - /// @brief Storage for uint32 parameters. - isc::dhcp::Uint32StoragePtr uint32_values_; - - /// @brief Storage for string parameters. - isc::dhcp::StringStoragePtr string_values_; }; /// @brief Defines a sequence of Element IDs used to specify a parsing order. diff --git a/src/lib/process/tests/d_cfg_mgr_unittests.cc b/src/lib/process/tests/d_cfg_mgr_unittests.cc index ca51fb611f..99620dcb20 100644 --- a/src/lib/process/tests/d_cfg_mgr_unittests.cc +++ b/src/lib/process/tests/d_cfg_mgr_unittests.cc @@ -275,31 +275,6 @@ TEST_F(DStubCfgMgrTest, simpleTypesTest) { DStubContextPtr context = getStubContext(); ASSERT_TRUE(context); - // Verify that the boolean parameter was parsed correctly by retrieving - // its value from the context. - bool actual_bool = false; - EXPECT_NO_THROW(context->getParam("bool_test", actual_bool)); - EXPECT_EQ(true, actual_bool); - - // Verify that the uint32 parameter was parsed correctly by retrieving - // its value from the context. - uint32_t actual_uint32 = 0; - EXPECT_NO_THROW(context->getParam("uint32_test", actual_uint32)); - EXPECT_EQ(77, actual_uint32); - - // Verify that the string parameter was parsed correctly by retrieving - // its value from the context. - std::string actual_string = ""; - EXPECT_NO_THROW(context->getParam("string_test", actual_string)); - EXPECT_EQ("hmmm chewy", actual_string); - - isc::data::ConstElementPtr object; - EXPECT_NO_THROW(context->getObjectParam("map_test", object)); - EXPECT_TRUE(object); - - EXPECT_NO_THROW(context->getObjectParam("list_test", object)); - EXPECT_TRUE(object); - // Create a configuration which "updates" all of the parameter values. string config2 = "{ \"bool_test\": false , " " \"uint32_test\": 88 , " @@ -313,38 +288,6 @@ TEST_F(DStubCfgMgrTest, simpleTypesTest) { EXPECT_TRUE(checkAnswer(0)); context = getStubContext(); ASSERT_TRUE(context); - - // Verify that the boolean parameter was updated correctly by retrieving - // its value from the context. - actual_bool = true; - EXPECT_NO_THROW(context->getParam("bool_test", actual_bool)); - EXPECT_FALSE(actual_bool); - - // Verify that the uint32 parameter was updated correctly by retrieving - // its value from the context. - actual_uint32 = 0; - EXPECT_NO_THROW(context->getParam("uint32_test", actual_uint32)); - EXPECT_EQ(88, actual_uint32); - - // Verify that the string parameter was updated correctly by retrieving - // its value from the context. - actual_string = ""; - EXPECT_NO_THROW(context->getParam("string_test", actual_string)); - EXPECT_EQ("ewww yuk!", actual_string); - - // Verify previous objects are not there. - EXPECT_THROW(context->getObjectParam("map_test", object), - isc::dhcp::DhcpConfigError); - EXPECT_THROW(context->getObjectParam("list_test", object), - isc::dhcp::DhcpConfigError); - - // Verify new map object is there. - EXPECT_NO_THROW(context->getObjectParam("map_test2", object)); - EXPECT_TRUE(object); - - // Verify new list object is there. - EXPECT_NO_THROW(context->getObjectParam("list_test2", object)); - EXPECT_TRUE(object); } /// @brief Tests that the configuration context is preserved after failure @@ -365,26 +308,6 @@ TEST_F(DStubCfgMgrTest, rollBackTest) { DStubContextPtr context = getStubContext(); ASSERT_TRUE(context); - // Verify that all of parameters have the expected values. - bool actual_bool = false; - EXPECT_NO_THROW(context->getParam("bool_test", actual_bool)); - EXPECT_EQ(true, actual_bool); - - uint32_t actual_uint32 = 0; - EXPECT_NO_THROW(context->getParam("uint32_test", actual_uint32)); - EXPECT_EQ(77, actual_uint32); - - std::string actual_string = ""; - EXPECT_NO_THROW(context->getParam("string_test", actual_string)); - EXPECT_EQ("hmmm chewy", actual_string); - - isc::data::ConstElementPtr object; - EXPECT_NO_THROW(context->getObjectParam("map_test", object)); - EXPECT_TRUE(object); - - EXPECT_NO_THROW(context->getObjectParam("list_test", object)); - EXPECT_TRUE(object); - // Create a configuration which "updates" all of the parameter values // plus one unknown at the end. string config2 = "{ \"bool_test\": false , " @@ -401,25 +324,6 @@ TEST_F(DStubCfgMgrTest, rollBackTest) { EXPECT_TRUE(checkAnswer(1)); context = getStubContext(); ASSERT_TRUE(context); - - // Verify that all of parameters have the original values. - actual_bool = false; - EXPECT_NO_THROW(context->getParam("bool_test", actual_bool)); - EXPECT_EQ(true, actual_bool); - - actual_uint32 = 0; - EXPECT_NO_THROW(context->getParam("uint32_test", actual_uint32)); - EXPECT_EQ(77, actual_uint32); - - actual_string = ""; - EXPECT_NO_THROW(context->getParam("string_test", actual_string)); - EXPECT_EQ("hmmm chewy", actual_string); - - EXPECT_NO_THROW(context->getObjectParam("map_test", object)); - EXPECT_TRUE(object); - - EXPECT_NO_THROW(context->getObjectParam("list_test", object)); - EXPECT_TRUE(object); } /// @brief Tests that the configuration context is preserved during @@ -439,25 +343,6 @@ TEST_F(DStubCfgMgrTest, checkOnly) { DStubContextPtr context = getStubContext(); ASSERT_TRUE(context); - // Verify that all of parameters have the expected values. - bool actual_bool = false; - EXPECT_NO_THROW(context->getParam("bool_test", actual_bool)); - EXPECT_EQ(true, actual_bool); - - uint32_t actual_uint32 = 0; - EXPECT_NO_THROW(context->getParam("uint32_test", actual_uint32)); - EXPECT_EQ(77, actual_uint32); - - std::string actual_string = ""; - EXPECT_NO_THROW(context->getParam("string_test", actual_string)); - EXPECT_EQ("hmmm chewy", actual_string); - - isc::data::ConstElementPtr object; - EXPECT_NO_THROW(context->getObjectParam("map_test", object)); - EXPECT_TRUE(object); - - EXPECT_NO_THROW(context->getObjectParam("list_test", object)); - EXPECT_TRUE(object); // Create a configuration which "updates" all of the parameter values. string config2 = "{ \"bool_test\": false , " @@ -472,24 +357,6 @@ TEST_F(DStubCfgMgrTest, checkOnly) { context = getStubContext(); ASSERT_TRUE(context); - // Verify that all of parameters have the original values. - actual_bool = false; - EXPECT_NO_THROW(context->getParam("bool_test", actual_bool)); - EXPECT_EQ(true, actual_bool); - - actual_uint32 = 0; - EXPECT_NO_THROW(context->getParam("uint32_test", actual_uint32)); - EXPECT_EQ(77, actual_uint32); - - actual_string = ""; - EXPECT_NO_THROW(context->getParam("string_test", actual_string)); - EXPECT_EQ("hmmm chewy", actual_string); - - EXPECT_NO_THROW(context->getObjectParam("map_test", object)); - EXPECT_TRUE(object); - - EXPECT_NO_THROW(context->getObjectParam("list_test", object)); - EXPECT_TRUE(object); } // Tests that configuration element position is returned by getParam variants. @@ -507,34 +374,6 @@ TEST_F(DStubCfgMgrTest, paramPosition) { DStubContextPtr context = getStubContext(); ASSERT_TRUE(context); - // Verify that the boolean parameter was parsed correctly by retrieving - // its value from the context. - bool actual_bool = false; - isc::data::Element::Position pos; - EXPECT_NO_THROW(pos = context->getParam("bool_test", actual_bool)); - EXPECT_EQ(true, actual_bool); - EXPECT_EQ(1, pos.line_); - - // Verify that the uint32 parameter was parsed correctly by retrieving - // its value from the context. - uint32_t actual_uint32 = 0; - EXPECT_NO_THROW(pos = context->getParam("uint32_test", actual_uint32)); - EXPECT_EQ(77, actual_uint32); - EXPECT_EQ(2, pos.line_); - - // Verify that the string parameter was parsed correctly by retrieving - // its value from the context. - std::string actual_string = ""; - EXPECT_NO_THROW(pos = context->getParam("string_test", actual_string)); - EXPECT_EQ("hmmm chewy", actual_string); - EXPECT_EQ(3, pos.line_); - - // Verify that an optional parameter that is not defined, returns the - // zero position. - pos = isc::data::Element::ZERO_POSITION(); - EXPECT_NO_THROW(pos = context->getParam("bogus_value", - actual_string, true)); - EXPECT_EQ(pos.file_, isc::data::Element::ZERO_POSITION().file_); } // This tests if some aspects of simpleParseConfig are behaving properly. diff --git a/src/lib/process/tests/d_controller_unittests.cc b/src/lib/process/tests/d_controller_unittests.cc index 2559b5ba87..c6f611f875 100644 --- a/src/lib/process/tests/d_controller_unittests.cc +++ b/src/lib/process/tests/d_controller_unittests.cc @@ -328,12 +328,6 @@ TEST_F(DStubControllerTest, invalidConfigReload) { time_duration elapsed_time; runWithConfig("{ \"string_test\": \"first value\" }", 500, elapsed_time); - // Context is still available post launch. Check to see that our - // configuration value is still the original value. - std::string actual_value = ""; - ASSERT_NO_THROW(getContext()->getParam("string_test", actual_value)); - EXPECT_EQ("first value", actual_value); - // Verify that we saw the signal. std::vector& signals = controller_->getProcessedSignals(); ASSERT_EQ(1, signals.size()); @@ -355,12 +349,6 @@ TEST_F(DStubControllerTest, alternateParsing) { time_duration elapsed_time; runWithConfig("{ \"string_test\": \"first value\" }", 500, elapsed_time); - // Context is still available post launch. Check to see that our - // configuration value is still the original value. - std::string actual_value = ""; - ASSERT_NO_THROW(getContext()->getParam("string_test", actual_value)); - EXPECT_EQ("alt value", actual_value); - // Verify that we saw the signal. std::vector& signals = controller_->getProcessedSignals(); ASSERT_EQ(1, signals.size()); @@ -384,12 +372,6 @@ TEST_F(DStubControllerTest, validConfigReload) { time_duration elapsed_time; runWithConfig("{ \"string_test\": \"first value\" }", 800, elapsed_time); - // Context is still available post launch. - // Check to see that our configuration value is what we expect. - std::string actual_value = ""; - ASSERT_NO_THROW(getContext()->getParam("string_test", actual_value)); - EXPECT_EQ("second value", actual_value); - // Verify that we saw two occurrences of the signal. std::vector& signals = controller_->getProcessedSignals(); ASSERT_EQ(2, signals.size()); diff --git a/src/lib/process/testutils/d_test_stubs.cc b/src/lib/process/testutils/d_test_stubs.cc index 8fe236f2c6..0b573c402d 100644 --- a/src/lib/process/testutils/d_test_stubs.cc +++ b/src/lib/process/testutils/d_test_stubs.cc @@ -263,30 +263,18 @@ const char* DControllerTest::CFG_TEST_FILE = "d2-test-config.json"; //************************** DStubContext ************************* -DStubContext::DStubContext(): object_values_(new ObjectStorage()) { +DStubContext::DStubContext() { } DStubContext::~DStubContext() { } -void -DStubContext::getObjectParam(const std::string& name, - isc::data::ConstElementPtr& value) { - value = object_values_->getParam(name); -} - -ObjectStoragePtr& -DStubContext::getObjectStorage() { - return (object_values_); -} - DCfgContextBasePtr DStubContext::clone() { return (DCfgContextBasePtr(new DStubContext(*this))); } -DStubContext::DStubContext(const DStubContext& rhs): DCfgContextBase(rhs), - object_values_(new ObjectStorage(*(rhs.object_values_))) { +DStubContext::DStubContext(const DStubContext& rhs): DCfgContextBase(rhs) { } isc::data::ElementPtr @@ -314,32 +302,13 @@ DStubCfgMgr::parseElement(const std::string& element_id, DStubContextPtr context = boost::dynamic_pointer_cast(getContext()); - if (element_id == "bool_test") { - bool value = element->boolValue(); - context->getBooleanStorage()->setParam(element_id, value, - element->getPosition()); - } else if (element_id == "uint32_test") { - uint32_t value = element->intValue(); - context->getUint32Storage()->setParam(element_id, value, - element->getPosition()); - - } else if (element_id == "string_test") { - std::string value = element->stringValue(); - context->getStringStorage()->setParam(element_id, value, - element->getPosition()); - } else { - // Fail only if SimFailure dictates we should. This makes it easier - // to test parse ordering, by permitting a wide range of element ids - // to "succeed" without specifically supporting them. - if (SimFailure::shouldFailOn(SimFailure::ftElementUnknown)) { - isc_throw(DCfgMgrBaseError, - "Configuration parameter not supported: " << element_id - << element->getPosition()); - } - - // Going to assume anything else is an object element. - context->getObjectStorage()->setParam(element_id, element, - element->getPosition()); + // Fail only if SimFailure dictates we should. This makes it easier + // to test parse ordering, by permitting a wide range of element ids + // to "succeed" without specifically supporting them. + if (SimFailure::shouldFailOn(SimFailure::ftElementUnknown)) { + isc_throw(DCfgMgrBaseError, + "Configuration parameter not supported: " << element_id + << element->getPosition()); } parsed_order_.push_back(element_id); diff --git a/src/lib/process/testutils/d_test_stubs.h b/src/lib/process/testutils/d_test_stubs.h index 0c76a4a1d8..92d56eaf06 100644 --- a/src/lib/process/testutils/d_test_stubs.h +++ b/src/lib/process/testutils/d_test_stubs.h @@ -580,19 +580,6 @@ public: /// @return returns a pointer to the new clone. virtual DCfgContextBasePtr clone(); - /// @brief Fetches the value for a given "extra" configuration parameter - /// from the context. - /// - /// @param name is the name of the parameter to retrieve. - /// @param value is an output parameter in which to return the retrieved - /// value. - /// @throw throws DhcpConfigError if the context does not contain the - /// parameter. - void getObjectParam(const std::string& name, - isc::data::ConstElementPtr& value); - - ObjectStoragePtr& getObjectStorage(); - protected: /// @brief Copy constructor DStubContext(const DStubContext& rhs); @@ -601,9 +588,6 @@ private: /// @brief Private assignment operator, not implemented. DStubContext& operator=(const DStubContext& rhs); - /// @brief Stores non-scalar configuration elements - ObjectStoragePtr object_values_; - /// @brief Unparse a configuration object /// /// @return a pointer to a configuration