From 5a652baaba6a15aaa757a10dcadd1c882b21c4e5 Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Wed, 3 Apr 2019 16:39:08 +0200 Subject: [PATCH] [#552,!295] Updated MySQL CB to not inherit network params to subnet. --- src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc | 56 +++++++++---------- .../mysql_cb/tests/mysql_cb_dhcp4_unittest.cc | 11 +++- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index fa2c7f7882..786fe0ebaf 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -746,7 +746,7 @@ public: // Create binding for host reservation mode. MySqlBindingPtr hr_mode_binding; - auto hr_mode = subnet->getHostReservationMode(); + auto hr_mode = subnet->getHostReservationMode(Network::Inheritance::NONE); if (!hr_mode.unspecified()) { hr_mode_binding = MySqlBinding::createInteger(static_cast (hr_mode.get())); @@ -788,25 +788,25 @@ public: MySqlBinding::condCreateString(subnet->get4o6().getIface4o6()), dhcp4o6_interface_id_binding, MySqlBinding::condCreateString(dhcp4o6_subnet), - MySqlBinding::condCreateString(subnet->getFilename()), - MySqlBinding::condCreateString(subnet->getClientClass()), - MySqlBinding::condCreateString(subnet->getIface()), - MySqlBinding::condCreateBool(subnet->getMatchClientId()), + MySqlBinding::condCreateString(subnet->getFilename(Network::Inheritance::NONE)), + MySqlBinding::condCreateString(subnet->getClientClass(Network::Inheritance::NONE)), + MySqlBinding::condCreateString(subnet->getIface(Network::Inheritance::NONE)), + MySqlBinding::condCreateBool(subnet->getMatchClientId(Network::Inheritance::NONE)), MySqlBinding::createTimestamp(subnet->getModificationTime()), - MySqlBinding::condCreateIPv4Address(subnet->getSiaddr()), - createBinding(subnet->getT2()), + MySqlBinding::condCreateIPv4Address(subnet->getSiaddr(Network::Inheritance::NONE)), + createBinding(subnet->getT2(Network::Inheritance::NONE)), createInputRelayBinding(subnet), - createBinding(subnet->getT1()), + createBinding(subnet->getT1(Network::Inheritance::NONE)), createInputRequiredClassesBinding(subnet), hr_mode_binding, - MySqlBinding::condCreateString(subnet->getSname()), + MySqlBinding::condCreateString(subnet->getSname(Network::Inheritance::NONE)), shared_network_binding, createInputContextBinding(subnet), - createBinding(subnet->getValid()), - MySqlBinding::condCreateBool(subnet->getCalculateTeeTimes()), - MySqlBinding::condCreateFloat(subnet->getT1Percent()), - MySqlBinding::condCreateFloat(subnet->getT2Percent()), - MySqlBinding::condCreateBool(subnet->getAuthoritative()) + createBinding(subnet->getValid(Network::Inheritance::NONE)), + MySqlBinding::condCreateBool(subnet->getCalculateTeeTimes(Network::Inheritance::NONE)), + MySqlBinding::condCreateFloat(subnet->getT1Percent(Network::Inheritance::NONE)), + MySqlBinding::condCreateFloat(subnet->getT2Percent(Network::Inheritance::NONE)), + MySqlBinding::condCreateBool(subnet->getAuthoritative(Network::Inheritance::NONE)) }; MySqlTransaction transaction(conn_); @@ -1251,7 +1251,7 @@ public: // Create binding for host reservation mode. MySqlBindingPtr hr_mode_binding; - auto hr_mode = shared_network->getHostReservationMode(); + auto hr_mode = shared_network->getHostReservationMode(Network::Inheritance::NONE); if (!hr_mode.unspecified()) { hr_mode_binding = MySqlBinding::createInteger(static_cast (hr_mode.get())); @@ -1261,24 +1261,24 @@ public: MySqlBindingCollection in_bindings = { MySqlBinding::createString(shared_network->getName()), - MySqlBinding::condCreateString(shared_network->getClientClass()), - MySqlBinding::condCreateString(shared_network->getIface()), - MySqlBinding::condCreateBool(shared_network->getMatchClientId()), + MySqlBinding::condCreateString(shared_network->getClientClass(Network::Inheritance::NONE)), + MySqlBinding::condCreateString(shared_network->getIface(Network::Inheritance::NONE)), + MySqlBinding::condCreateBool(shared_network->getMatchClientId(Network::Inheritance::NONE)), MySqlBinding::createTimestamp(shared_network->getModificationTime()), - createBinding(shared_network->getT2()), + createBinding(shared_network->getT2(Network::Inheritance::NONE)), createInputRelayBinding(shared_network), - createBinding(shared_network->getT1()), + createBinding(shared_network->getT1(Network::Inheritance::NONE)), createInputRequiredClassesBinding(shared_network), hr_mode_binding, createInputContextBinding(shared_network), - createBinding(shared_network->getValid()), - MySqlBinding::condCreateBool(shared_network->getCalculateTeeTimes()), - MySqlBinding::condCreateFloat(shared_network->getT1Percent()), - MySqlBinding::condCreateFloat(shared_network->getT2Percent()), - MySqlBinding::condCreateBool(shared_network->getAuthoritative()), - MySqlBinding::condCreateString(shared_network->getFilename()), - MySqlBinding::condCreateIPv4Address(shared_network->getSiaddr()), - MySqlBinding::condCreateString(shared_network->getSname()) + createBinding(shared_network->getValid(Network::Inheritance::NONE)), + MySqlBinding::condCreateBool(shared_network->getCalculateTeeTimes(Network::Inheritance::NONE)), + MySqlBinding::condCreateFloat(shared_network->getT1Percent(Network::Inheritance::NONE)), + MySqlBinding::condCreateFloat(shared_network->getT2Percent(Network::Inheritance::NONE)), + MySqlBinding::condCreateBool(shared_network->getAuthoritative(Network::Inheritance::NONE)), + MySqlBinding::condCreateString(shared_network->getFilename(Network::Inheritance::NONE)), + MySqlBinding::condCreateIPv4Address(shared_network->getSiaddr(Network::Inheritance::NONE)), + MySqlBinding::condCreateString(shared_network->getSname(Network::Inheritance::NONE)) }; MySqlTransaction transaction(conn_); diff --git a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc index 8cb1541e1c..6036d020b9 100644 --- a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc +++ b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc @@ -668,8 +668,17 @@ TEST_F(MySqlConfigBackendDHCPv4Test, getSubnet4) { // Test that the information about unspecified optional parameters gets // propagated to the database. TEST_F(MySqlConfigBackendDHCPv4Test, getSubnet4WithOptionalUnspecified) { - // Insert new subnet. + // Create a subnet and wrap it within a shared network. It is important + // to have the shared network to verify that the subnet doesn't inherit + // the values of the shared network but stores the NULL values in the + // for those parameters that are unspecified on the subnet level. Subnet4Ptr subnet = test_subnets_[2]; + SharedNetwork4Ptr shared_network = test_networks_[0]; + shared_network->add(subnet); + + // Need to add the shared network to the database because otherwise + // the subnet foreign key would fail. + cbptr_->createUpdateSharedNetwork4(ServerSelector::ALL(), shared_network); cbptr_->createUpdateSubnet4(ServerSelector::ALL(), subnet); // Fetch this subnet by subnet identifier. -- 2.47.2