Browse Source

[5108] Addressed review comments.

Added unit tests that check that configuration of various servers can
coexist.
Marcin Siodelski 7 years ago
parent
commit
dce538b356

+ 48 - 0
src/bin/agent/tests/parser_unittests.cc

@@ -117,6 +117,54 @@ TEST(ParserTest, keywordJSON) {
     testParser(txt, ParserContext::PARSER_JSON);
 }
 
+// This test checks that the DhcpDdns configuration is accepted
+// by the parser.
+TEST(ParserTest, keywordDhcpDdns) {
+    string txt =
+        "{ \"DhcpDdns\" : \n"
+           "{ \n"
+            " \"ip-address\": \"192.168.77.1\", \n"
+            " \"port\": 777 , \n "
+            " \"ncr-protocol\": \"UDP\", \n"
+            "\"tsig-keys\": [], \n"
+            "\"forward-ddns\" : {}, \n"
+            "\"reverse-ddns\" : {} \n"
+            "} \n"
+         "} \n";
+     testParser(txt, ParserContext::PARSER_AGENT);
+}
+
+// This test checks that the Dhcp6 configuration is accepted
+// by the parser.
+TEST(ParserTest, keywordDhcp6) {
+     string txt = "{ \"Dhcp6\": { \"interfaces-config\": {"
+                  " \"interfaces\": [ \"type\", \"htype\" ] },\n"
+                  "\"preferred-lifetime\": 3000,\n"
+                  "\"rebind-timer\": 2000, \n"
+                  "\"renew-timer\": 1000, \n"
+                  "\"subnet6\": [ { "
+                  "    \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+                  "    \"subnet\": \"2001:db8:1::/48\", "
+                  "    \"interface\": \"test\" } ],\n"
+                   "\"valid-lifetime\": 4000 } }";
+     testParser(txt, ParserContext::PARSER_AGENT);
+}
+
+// This test checks that the Dhcp4 configuration is accepted
+// by the parser.
+TEST(ParserTest, keywordDhcp4) {
+    string txt = "{ \"Dhcp4\": { \"interfaces-config\": {"
+                  " \"interfaces\": [ \"type\", \"htype\" ] },\n"
+                  "\"rebind-timer\": 2000, \n"
+                  "\"renew-timer\": 1000, \n"
+                  "\"subnet4\": [ { "
+                  "  \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
+                  "  \"subnet\": \"192.0.2.0/24\", "
+                  "  \"interface\": \"test\" } ],\n"
+                   "\"valid-lifetime\": 4000 } }";
+     testParser(txt, ParserContext::PARSER_AGENT);
+}
+
 // This test checks if full config (with top level and Control-agent objects) can
 // be parsed with syntactic checking (and as pure JSON).
 TEST(ParserTest, keywordAgent) {

+ 5 - 0
src/bin/d2/tests/parser_unittest.cc

@@ -159,6 +159,11 @@ TEST(ParserTest, keywordDhcp4) {
      testParser(txt, D2ParserContext::PARSER_DHCPDDNS);
 }
 
+TEST(ParserTest, keywordControlAgent) {
+    string txt = "{ \"Control-agent\": { } }";
+    testParser(txt, D2ParserContext::PARSER_DHCPDDNS);
+}
+
 TEST(ParserTest, Logging) {
     string txt = "{ \"Logging\": { \n"
                  "    \"loggers\": [ \n"

+ 25 - 0
src/bin/dhcp4/tests/kea_controller_unittest.cc

@@ -183,6 +183,31 @@ TEST_F(JSONFileBackendTest, jsonFile) {
     EXPECT_EQ(Lease::TYPE_V4, pools3.at(0)->getType());
 }
 
+// This test verifies that the configurations for various servers
+// can coexist and that the DHCPv4 configuration parsers will simply
+// ignore them.
+TEST_F(JSONFileBackendTest, serverConfigurationsCoexistence) {
+    std::string config = "{ \"Dhcp4\": {"
+        "\"rebind-timer\": 2000, "
+        "\"renew-timer\": 1000, \n"
+        "\"valid-lifetime\": 4000 }, "
+        "\"Dhcp6\": { },"
+        "\"DhcpDdns\": { },"
+        "\"Control-agent\": { }"
+        "}";
+
+    writeFile(TEST_FILE, config);
+
+    // Now initialize the server
+    boost::scoped_ptr<ControlledDhcpv4Srv> srv;
+    ASSERT_NO_THROW(
+        srv.reset(new ControlledDhcpv4Srv(0))
+    );
+
+    // And configure it using the config file.
+    EXPECT_NO_THROW(srv->init(TEST_FILE));
+}
+
 // This test checks if configuration can be read from a JSON file
 // using hash (#) line comments
 TEST_F(JSONFileBackendTest, hashComments) {

+ 26 - 0
src/bin/dhcp6/tests/kea_controller_unittest.cc

@@ -169,6 +169,32 @@ TEST_F(JSONFileBackendTest, jsonFile) {
     EXPECT_EQ(Lease::TYPE_NA, pools3.at(0)->getType());
 }
 
+// This test verifies that the configurations for various servers
+// can coexist and that the DHCPv6 configuration parsers will simply
+// ignore them.
+TEST_F(JSONFileBackendTest, serverConfigurationsCoexistence) {
+    std::string config = "{ \"Dhcp6\": {"
+        "\"rebind-timer\": 2000, "
+        "\"renew-timer\": 1000, \n"
+        "\"preferred-lifetime\": 1000, \n"
+        "\"valid-lifetime\": 4000 }, "
+        "\"Dhcp4\": { },"
+        "\"DhcpDdns\": { },"
+        "\"Control-agent\": { }"
+        "}";
+
+    writeFile(TEST_FILE, config);
+
+    // Now initialize the server
+    boost::scoped_ptr<ControlledDhcpv6Srv> srv;
+    ASSERT_NO_THROW(
+        srv.reset(new ControlledDhcpv6Srv(0))
+    );
+
+    // And configure it using the config file.
+    EXPECT_NO_THROW(srv->init(TEST_FILE));
+}
+
 // This test checks if configuration can be read from a JSON file
 // using hash (#) line comments
 TEST_F(JSONFileBackendTest, hashComments) {