From ac3a0692711cd6586ed6e7e3670b5f47515efb46 Mon Sep 17 00:00:00 2001 From: Tomek Mrugalski Date: Wed, 13 Sep 2017 10:52:57 +0200 Subject: [PATCH] [5357] Added test for multiple shared-networks --- src/bin/dhcp4/tests/config_parser_unittest.cc | 35 ++++++++++++++++--- src/bin/dhcp6/tests/config_parser_unittest.cc | 30 +++++++++++++--- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/bin/dhcp4/tests/config_parser_unittest.cc b/src/bin/dhcp4/tests/config_parser_unittest.cc index 6e9857a581..a8fce5b4b7 100644 --- a/src/bin/dhcp4/tests/config_parser_unittest.cc +++ b/src/bin/dhcp4/tests/config_parser_unittest.cc @@ -5207,11 +5207,12 @@ TEST_F(Dhcp4ParserTest, sharedNetworks3subnets) { // This test checks if parameters are derived properly: // - global to shared network // - shared network to subnet +// Also, it tests that more than one shared network can be defined. TEST_F(Dhcp4ParserTest, sharedNetworksDerive) { string config = "{\n" - "\"valid-lifetime\": 4, \n" - "\"rebind-timer\": 2, \n" "\"renew-timer\": 1, \n" + "\"rebind-timer\": 2, \n" + "\"valid-lifetime\": 4, \n" "\"shared-networks\": [ {\n" " \"name\": \"foo\"\n," " \"renew-timer\": 10,\n" @@ -5226,6 +5227,17 @@ TEST_F(Dhcp4ParserTest, sharedNetworksDerive) { " \"renew-timer\": 100\n" " }\n" " ]\n" + + " },\n" + "{ // second shared-network starts here\n" + " \"name\": \"bar\",\n" + " \"subnet4\": [\n" + " {\n" + " \"subnet\": \"192.0.3.0/24\",\n" + " \"pools\": [ { \"pool\": \"192.0.3.1-192.0.3.10\" } ]\n" + " }\n" + " ]\n" + " } ]\n" "} \n"; @@ -5235,15 +5247,16 @@ TEST_F(Dhcp4ParserTest, sharedNetworksDerive) { CfgSharedNetworks4Ptr cfg_net = CfgMgr::instance().getStagingCfg() ->getCfgSharedNetworks4(); - // There is expected one shared subnet. + // Two shared networks are expected. ASSERT_TRUE(cfg_net); const SharedNetwork4Collection* nets = cfg_net->getAll(); ASSERT_TRUE(nets); - ASSERT_EQ(1, nets->size()); + ASSERT_EQ(2, nets->size()); - SharedNetwork4Ptr net = *(nets->begin()); + SharedNetwork4Ptr net = nets->at(0); ASSERT_TRUE(net); + // The first shared network has two subnets. const Subnet4Collection * subs = net->getAllSubnets(); ASSERT_TRUE(subs); EXPECT_EQ(2, subs->size()); @@ -5259,6 +5272,18 @@ TEST_F(Dhcp4ParserTest, sharedNetworksDerive) { // from global scope to shared-network level and later again to // subnet4 level. checkSubnet(*subs, "192.0.2.0/24", 100, 2, 4); + + // Ok, now check the second shared subnet. + net = nets->at(1); + ASSERT_TRUE(net); + + subs = net->getAllSubnets(); + ASSERT_TRUE(subs); + EXPECT_EQ(1, subs->size()); + + // This subnet should derive its renew-timer from global scope. + checkSubnet(*subs, "192.0.3.0/24", 1, 2, 4); + } diff --git a/src/bin/dhcp6/tests/config_parser_unittest.cc b/src/bin/dhcp6/tests/config_parser_unittest.cc index e71ae989af..3f3c1a2908 100644 --- a/src/bin/dhcp6/tests/config_parser_unittest.cc +++ b/src/bin/dhcp6/tests/config_parser_unittest.cc @@ -5556,6 +5556,7 @@ TEST_F(Dhcp6ParserTest, sharedNetworks3subnets) { // This test checks if parameters are derived properly: // - global to shared network // - shared network to subnet +// Also, it tests that more than one shared network can be defined. TEST_F(Dhcp6ParserTest, sharedNetworksDerive) { string config = "{\n" "\"renew-timer\": 1, \n" @@ -5576,7 +5577,16 @@ TEST_F(Dhcp6ParserTest, sharedNetworksDerive) { " \"renew-timer\": 100\n" " }\n" " ]\n" - " } ]\n" + " },\n" + "{ // second shared-network starts here\n" + " \"name\": \"bar\",\n" + " \"subnet6\": [\n" + " {\n" + " \"subnet\": \"2001:db3::/48\",\n" + " \"pools\": [ { \"pool\": \"2001:db3::/64\" } ]\n" + " }\n" + " ]\n" + "} ]\n" "} \n"; configure(config, CONTROL_RESULT_SUCCESS, ""); @@ -5585,13 +5595,14 @@ TEST_F(Dhcp6ParserTest, sharedNetworksDerive) { CfgSharedNetworks6Ptr cfg_net = CfgMgr::instance().getStagingCfg() ->getCfgSharedNetworks6(); - // There is expected one shared subnet. + // Two shared networks are expeced. ASSERT_TRUE(cfg_net); const SharedNetwork6Collection* nets = cfg_net->getAll(); ASSERT_TRUE(nets); - ASSERT_EQ(1, nets->size()); + ASSERT_EQ(2, nets->size()); - SharedNetwork6Ptr net = *(nets->begin()); + // Let's check the first one. + SharedNetwork6Ptr net = nets->at(0); ASSERT_TRUE(net); const Subnet6Collection * subs = net->getAllSubnets(); @@ -5609,6 +5620,17 @@ TEST_F(Dhcp6ParserTest, sharedNetworksDerive) { // from global scope to shared-network level and later again to // subnet6 level. checkSubnet(*subs, "2001:db2::/48", 100, 2, 3, 4); + + // Ok, now check the second shared subnet. + net = nets->at(1); + ASSERT_TRUE(net); + + subs = net->getAllSubnets(); + ASSERT_TRUE(subs); + EXPECT_EQ(1, subs->size()); + + // This subnet should derive its renew-timer from global scope. + checkSubnet(*subs, "2001:db3::/48", 1, 2, 3, 4); } }; -- 2.47.2