]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5134_rebase] Changes after review:
authorTomek Mrugalski <tomasz@isc.org>
Thu, 2 Mar 2017 01:36:09 +0000 (02:36 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Thu, 2 Mar 2017 01:36:09 +0000 (02:36 +0100)
 - stub implementation for parse added
 - unit-test for simpleParseConfig added
 - isc::hooks namespace added

src/lib/hooks/hooks_parser.cc
src/lib/process/d_cfg_mgr.cc
src/lib/process/tests/d_cfg_mgr_unittests.cc
src/lib/process/testutils/d_test_stubs.cc
src/lib/process/testutils/d_test_stubs.h

index 5c50d9997b50030b1be3eea6c31a4b0c739051c6..4c4d9057fe5f0bdd4e3e1dc589c4ed7cbd2ba43b 100644 (file)
@@ -20,6 +20,9 @@ using namespace isc::data;
 using namespace isc::hooks;
 using namespace isc::dhcp;
 
+namespace isc {
+namespace hooks {
+
 // ******************** HooksLibrariesParser *************************
 void
 HooksLibrariesParser::parse(ConstElementPtr value) {
@@ -152,3 +155,6 @@ void
 HooksLibrariesParser::getLibraries(isc::hooks::HookLibsCollection& libraries) {
     libraries = libraries_;
 }
+
+}
+}
index 5ba2e6e22a6ad34e33d7382cb82d574f7c43c5f9..0442e5878e8534b0c325e3df6fe13c668636698d 100644 (file)
@@ -258,13 +258,12 @@ DCfgMgrBase::parseConfig(isc::data::ConstElementPtr config_set) {
 isc::data::ConstElementPtr
 DCfgMgrBase::simpleParseConfig(isc::data::ConstElementPtr config_set,
                                bool check_only) {
-    LOG_DEBUG(dctl_logger, DBGLVL_COMMAND,
-                DCTL_CONFIG_START).arg(config_set->str());
-
     if (!config_set) {
         return (isc::config::createAnswer(1,
                                     std::string("Can't parse NULL config")));
     }
+    LOG_DEBUG(dctl_logger, DBGLVL_COMMAND,
+                DCTL_CONFIG_START).arg(config_set->str());
 
     // The parsers implement data inheritance by directly accessing
     // configuration context. For this reason the data parsers must store
index fe37fe5e6c7b6f2fe910e5ad017d543f3e37a7bb..0877f9a0101a6a054825378e9f9d326789cb5b7f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -477,5 +477,30 @@ TEST_F(DStubCfgMgrTest, paramPosition) {
     EXPECT_EQ(pos.file_, isc::data::Element::ZERO_POSITION().file_);
 }
 
+// This tests if some aspects of simpleParseConfig are behaving properly.
+// Thorough testing is only possible for specific implementations. This
+// is done for control agent (see CtrlAgentControllerTest tests in
+// src/bin/agent/tests/ctrl_agent_controller_unittest.cc for example).
+// Also, shell tests in src/bin/agent/ctrl_agent_process_tests.sh test
+// the whole CA process that uses simpleParseConfig. The alternative
+// would be to implement whole parser that would set the context
+// properly. The ROI for this is not worth the effort.
+TEST_F(DStubCfgMgrTest, simpleParseConfig) {
+    using namespace isc::data;
+
+    // Passing just null pointer should result in error return code
+    answer_ = cfg_mgr_->simpleParseConfig(ConstElementPtr(), false);
+    EXPECT_TRUE(checkAnswer(1));
+
+    // Ok, now try with a dummy, but valid json code
+    string config = "{ \"bool_test\": true , \n"
+                    "  \"uint32_test\": 77 , \n"
+                    "  \"string_test\": \"hmmm chewy\" }";
+    ASSERT_NO_THROW(fromJSON(config));
+
+    answer_ = cfg_mgr_->simpleParseConfig(config_set_, false);
+    EXPECT_TRUE(checkAnswer(0));
+}
+
 
 } // end of anonymous namespace
index 4d9f34caef7eb5d45602fd6f96e94f1e455780e1..501198f4831c93604f828c16cb5d6df3bcc51a73 100644 (file)
@@ -9,6 +9,7 @@
 #include <process/d_log.h>
 #include <process/spec_config.h>
 #include <process/testutils/d_test_stubs.h>
+#include <cc/command_interpreter.h>
 
 using namespace boost::asio;
 
@@ -428,5 +429,10 @@ DStubCfgMgr::createConfigParser(const std::string& element_id,
     return (parser);
 }
 
+isc::data::ConstElementPtr
+DStubCfgMgr::parse(isc::data::ConstElementPtr /*config*/, bool /*check_only*/) {
+    return (isc::config::createAnswer(0, "It all went fine. I promise"));
+}
+
 }; // namespace isc::process
 }; // namespace isc
index e6e6d623355d5e54947f82261afa7638c1623197..d8fa797889f139648b274937552fa6c49740447e 100644 (file)
@@ -706,6 +706,19 @@ public:
                        const isc::data::Element::Position& pos
                        = isc::data::Element::Position());
 
+    /// @brief Pretends to parse the config
+    ///
+    /// This method pretends to parse the configuration specified on input
+    /// and returns a positive answer. The check_only flag is currently ignored.
+    ///
+    /// @param config configuration specified
+    /// @param check_only whether it's real configuration (false) or just
+    ///                configuration check (true)
+    /// @return always positive answer
+    ///
+    isc::data::ConstElementPtr
+    parse(isc::data::ConstElementPtr config, bool check_only);
+
     /// @brief Returns a summary of the configuration in the textual format.
     ///
     /// @return Always an empty string.