]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#32,!23] SrvConfig::toElement now outputs config-control
authorThomas Markwalder <tmark@isc.org>
Fri, 28 Sep 2018 19:36:21 +0000 (15:36 -0400)
committerThomas Markwalder <tmark@isc.org>
Fri, 5 Oct 2018 13:05:44 +0000 (09:05 -0400)
src/lib/dhcpsrv/srv_config.cc
    SrvConfig::toElement() - added logic to output config-control

src/lib/dhcpsrv/tests/srv_config_unittest.cc
    TEST_F(SrvConfigTest, unparseConfigControlInfo) - new test

src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/srv_config.h
src/lib/dhcpsrv/tests/srv_config_unittest.cc

index 4e4571761e9c0aaf288ffaeab74f529088b6be6d..5e8990711b7cbb22a69f15c24ddbcd3215940cf7 100644 (file)
@@ -131,11 +131,12 @@ SrvConfig::copy(SrvConfig& new_config) const {
 bool
 SrvConfig::equals(const SrvConfig& other) const {
 
+    // Checks common elements: logging & config control
     if (!ConfigBase::equals(other)) {
         return (false);
     }
 
-    // Logging information is equal between objects, so check other values.
+    // Common information is equal between objects, so check other values.
     if ((*cfg_iface_ != *other.cfg_iface_) ||
         (*cfg_option_def_ != *other.cfg_option_def_) ||
         (*cfg_option_ != *other.cfg_option_) ||
@@ -382,6 +383,13 @@ SrvConfig::toElement() const {
     ConstElementPtr cfg_consist = cfg_consist_->toElement();
     dhcp->set("sanity-checks", cfg_consist);
 
+    // Set config-control (if it exists)
+    ConstConfigControlInfoPtr info = getConfigControlInfo();
+    if (info) {
+        ConstElementPtr info_elem = info->toElement();
+        dhcp->set("config-control", info_elem);
+    }
+
     return (result);
 }
 
index e4fbe2f8ae68f56defc1f12a592628e982bfbe1e..f0024e8bfec4963251f583937340b7549a14c694 100644 (file)
@@ -62,6 +62,8 @@ public:
     static const uint32_t CFGSEL_SUBNET  = 0x00000003;
     /// Configured globals
     static const uint32_t CFGSEL_GLOBALS = 0x00000020;
+    /// Config control info
+    static const uint32_t CFGSEL_CFG_CTL = 0x00000040;
     /// IPv4 related config
     static const uint32_t CFGSEL_ALL4    = 0x00000035;
     /// IPv6 related config
index 0b555bc27bc07a2b91b73431df13e2a6a7c56a47..7df32a422b9dcca5a96158e8b53bec5658f9bcfe 100644 (file)
@@ -590,7 +590,7 @@ TEST_F(SrvConfigTest, unparseHR) {
 
     // Add a v4 global host reservation to the plain subnet
     HostPtr ghost4(new Host("AA:01:02:03:04:05", "hw-address",
-                            SUBNET_ID_GLOBAL, SUBNET_ID_UNUSED, 
+                            SUBNET_ID_GLOBAL, SUBNET_ID_UNUSED,
                             IOAddress("192.0.3.1")));
     conf4.getCfgHosts()->add(ghost4);
 
@@ -751,7 +751,7 @@ TEST_F(SrvConfigTest, unparseHR) {
     conf6.getCfgHosts()->add(phost6);
 
     // Add a host reservation to the shared subnet
-    HostPtr shost6(new Host("f6:e5:d4:c3:b2:a1", "duid", SUBNET_ID_UNUSED, 
+    HostPtr shost6(new Host("f6:e5:d4:c3:b2:a1", "duid", SUBNET_ID_UNUSED,
                             s_id, IOAddress::IPV4_ZERO_ADDRESS(),
                             "bar.example.org"));
     conf6.getCfgHosts()->add(shost6);
@@ -870,4 +870,49 @@ TEST_F(SrvConfigTest, unparseHR) {
     EXPECT_EQ("bar.example.org", check->stringValue());
 }
 
+// Verifies that the toElement method does not miss config control info
+TEST_F(SrvConfigTest, unparseConfigControlInfo) {
+    // DHCPv4 version
+    CfgMgr::instance().setFamily(AF_INET);
+    SrvConfig conf4(32);
+
+    // Unparse the config
+    ConstElementPtr unparsed4 = conf4.toElement();
+    ASSERT_TRUE(unparsed4);
+    ASSERT_EQ(Element::map, unparsed4->getType());
+
+    // Get Dhcp4 entry
+    ConstElementPtr dhcp4;
+    ASSERT_NO_THROW(dhcp4 = unparsed4->get("Dhcp4"));
+    ASSERT_TRUE(dhcp4);
+    ASSERT_EQ(Element::map, dhcp4->getType());
+
+    // Config control should not be present.
+    ConstElementPtr check;
+    ASSERT_NO_THROW(check = dhcp4->get("config-control"));
+    EXPECT_FALSE(check);
+
+    // Now let's create the info and add it to the configuration
+    ConfigControlInfoPtr info(new ConfigControlInfo());
+    ASSERT_NO_THROW(info->addConfigDatabase("type=mysql"));
+    ASSERT_NO_THROW(conf4.setConfigControlInfo(info));
+
+    // Unparse the config again
+    unparsed4 = conf4.toElement();
+    ASSERT_NO_THROW(dhcp4 = unparsed4->get("Dhcp4"));
+    ASSERT_TRUE(dhcp4);
+    ASSERT_EQ(Element::map, dhcp4->getType());
+
+    // Config control should be present.
+    ASSERT_NO_THROW(check = dhcp4->get("config-control"));
+    ASSERT_TRUE(check);
+    ASSERT_EQ(Element::map, check->getType());
+
+    // Unparse the info object and compare its elements to
+    // that in unparsed config.  They should be equal.
+    ElementPtr info_elem = info->toElement();
+    EXPECT_TRUE(info_elem->equals(*check));
+}
+
+
 } // end of anonymous namespace