Browse Source

[3464] Compilation fix, 2 extra tests for multiple leases added

Tomek Mrugalski 10 years ago
parent
commit
a17acb3c73

+ 57 - 0
src/bin/dhcp4/tests/config_parser_unittest.cc

@@ -1102,6 +1102,63 @@ TEST_F(Dhcp4ParserTest, subnetLocal) {
     EXPECT_EQ(4, subnet->getValid());
 }
 
+// This test checks that multiple pools can be defined and handled properly.
+// The test defines 2 subnets, each with 2 pools.
+TEST_F(Dhcp4ParserTest, multiplePools) {
+
+    // Collection with two subnets, each with 2 pools.
+    string config = "{ \"interfaces\": [ \"*\" ],"
+        "\"rebind-timer\": 2000, "
+        "\"renew-timer\": 1000, "
+        "\"subnet4\": [ { "
+        "    \"pools\": [ "
+        "        { \"pool\": \"192.0.2.0/28\" },"
+        "        { \"pool\": \"192.0.2.200-192.0.2.255\" }"
+        "    ],"
+        "    \"subnet\": \"192.0.2.0/24\" "
+        " },"
+        " {"
+        "    \"pools\": [ "
+        "    { \"pool\": \"192.0.3.0/25\" },"
+        "    { \"pool\": \"192.0.3.128/25\" }"
+        "    ],"
+        "    \"subnet\": \"192.0.3.0/24\""
+        " } ],"
+        "\"valid-lifetime\": 4000 }";
+    ElementPtr json;
+    ASSERT_NO_THROW(json = Element::fromJSON(config));
+
+    ConstElementPtr status;
+    ASSERT_NO_THROW(status = configureDhcp4Server(*srv_, json));
+    checkResult(status, 0);
+
+    const Subnet4Collection* subnets = CfgMgr::instance().getSubnets4();
+    ASSERT_TRUE(subnets);
+    ASSERT_EQ(2, subnets->size()); // We expect 2 subnets
+
+    // Check the first subnet
+    const PoolCollection& pools1 = subnets->at(0)->getPools(Lease::TYPE_V4);
+    ASSERT_EQ(2, pools1.size());
+    EXPECT_EQ("type=V4, 192.0.2.0-192.0.2.15",
+              pools1[0]->toText());
+    EXPECT_EQ("type=V4, 192.0.2.200-192.0.2.255",
+              pools1[1]->toText());
+    // There shouldn't be any TA or PD pools
+    EXPECT_THROW(subnets->at(0)->getPools(Lease::TYPE_TA), BadValue);
+    EXPECT_THROW(subnets->at(0)->getPools(Lease::TYPE_PD), BadValue);
+
+    // Check the second subnet
+    const PoolCollection& pools2 = subnets->at(1)->getPools(Lease::TYPE_V4);
+    ASSERT_EQ(2, pools2.size());
+    EXPECT_EQ("type=V4, 192.0.3.0-192.0.3.127",
+              pools2[0]->toText());
+    EXPECT_EQ("type=V4, 192.0.3.128-192.0.3.255",
+              pools2[1]->toText());
+    // There shouldn't be any TA or PD pools
+    EXPECT_THROW(subnets->at(0)->getPools(Lease::TYPE_TA).empty(), BadValue);
+    EXPECT_THROW(subnets->at(0)->getPools(Lease::TYPE_PD).empty(), BadValue);
+}
+
 // Test verifies that a subnet with pool values that do not belong to that
 // pool are rejected.
 TEST_F(Dhcp4ParserTest, poolOutOfSubnet) {

+ 57 - 0
src/bin/dhcp6/tests/config_parser_unittest.cc

@@ -562,6 +562,7 @@ TEST_F(Dhcp6ParserTest, subnetGlobalDefaults) {
     EXPECT_EQ(1, subnet->getID());
 }
 
+// This test checks that multiple subnets can be defined and handled properly.
 TEST_F(Dhcp6ParserTest, multipleSubnets) {
     ConstElementPtr x;
     // Collection of four subnets for which ids should be autogenerated
@@ -1046,6 +1047,62 @@ TEST_F(Dhcp6ParserTest, subnetInterfaceAndInterfaceId) {
     EXPECT_TRUE(errorContainsPosition(status, "<string>"));
 }
 
+// This test checks that multiple pools can be defined and handled properly.
+// The test defines 2 subnets, each with 2 pools.
+TEST_F(Dhcp6ParserTest, multiplePools) {
+    // Collection with two subnets, each with 2 pools.
+    string config = "{ \"interfaces\": [ \"*\" ],"
+        "\"preferred-lifetime\": 3000,"
+        "\"rebind-timer\": 2000, "
+        "\"renew-timer\": 1000, "
+        "\"subnet6\": [ { "
+        "    \"pools\": [ "
+        "        { \"pool\": \"2001:db8:1::/96\" },"
+        "        { \"pool\": \"2001:db8:1:0:abcd::/112\" }"
+        "    ],"
+        "    \"subnet\": \"2001:db8:1::/64\" "
+        " },"
+        " {"
+        "    \"pools\": [ "
+        "    { \"pool\": \"2001:db8:2::1 - 2001:db8:2::ff\" },"
+        "    { \"pool\": \"2001:db8:2::300 - 2001:db8:2::3ff\" }"
+        "    ],"
+        "    \"subnet\": \"2001:db8:2::/64\""
+        " } ],"
+        "\"valid-lifetime\": 4000 }";
+    ElementPtr json;
+    ASSERT_NO_THROW(json = Element::fromJSON(config));
+
+    ConstElementPtr status;
+    ASSERT_NO_THROW(status = configureDhcp6Server(srv_, json));
+    checkResult(status, 0);
+
+    const Subnet6Collection* subnets = CfgMgr::instance().getSubnets6();
+    ASSERT_TRUE(subnets);
+    ASSERT_EQ(2, subnets->size()); // We expect 2 subnets
+
+    // Check the first subnet
+    const PoolCollection& pools1 = subnets->at(0)->getPools(Lease::TYPE_NA);
+    ASSERT_EQ(2, pools1.size());
+    EXPECT_EQ("type=IA_NA, 2001:db8:1::-2001:db8:1::ffff:ffff, delegated_len=128",
+              pools1[0]->toText());
+    EXPECT_EQ("type=IA_NA, 2001:db8:1:0:abcd::-2001:db8:1:0:abcd::ffff, delegated_len=128",
+              pools1[1]->toText());
+    // There shouldn't be any TA or PD pools
+    EXPECT_TRUE(subnets->at(0)->getPools(Lease::TYPE_TA).empty());
+    EXPECT_TRUE(subnets->at(0)->getPools(Lease::TYPE_PD).empty());
+
+    // Check the second subnet
+    const PoolCollection& pools2 = subnets->at(1)->getPools(Lease::TYPE_NA);
+    ASSERT_EQ(2, pools2.size());
+    EXPECT_EQ("type=IA_NA, 2001:db8:2::1-2001:db8:2::ff, delegated_len=128",
+              pools2[0]->toText());
+    EXPECT_EQ("type=IA_NA, 2001:db8:2::300-2001:db8:2::3ff, delegated_len=128",
+              pools2[1]->toText());
+    // There shouldn't be any TA or PD pools
+    EXPECT_TRUE(subnets->at(0)->getPools(Lease::TYPE_TA).empty());
+    EXPECT_TRUE(subnets->at(0)->getPools(Lease::TYPE_PD).empty());
+}
 
 
 // Test verifies that a subnet with pool values that do not belong to that

+ 1 - 1
src/lib/dhcpsrv/dhcp_parsers.cc

@@ -944,7 +944,7 @@ RelayInfoParser::commit() {
 }
 
 //****************************** PoolsListParser ********************************
-PoolsListParser::PoolsListParser(const std::string& dummy, PoolStoragePtr pools)
+PoolsListParser::PoolsListParser(const std::string&, PoolStoragePtr pools)
     :pools_(pools), local_pools_(new PoolStorage()) {
     if (!pools_) {
         isc_throw(isc::dhcp::DhcpConfigError, "parser logic error:"