]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[481-remote-subnet4-set-inconsistent-work-when-id-subnet-is-duplicated] Addressed...
authorFrancis Dupont <fdupont@isc.org>
Tue, 12 Mar 2019 14:04:29 +0000 (15:04 +0100)
committerFrancis Dupont <fdupont@isc.org>
Tue, 12 Mar 2019 22:20:47 +0000 (18:20 -0400)
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc
src/lib/mysql/mysql_binding.h
src/lib/mysql/mysql_connection.h
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in

index eeea6e9aef7a323268f694855f05f8fd65eae730..435de2bba33e07069690de53381ea5cfa53c1118 100644 (file)
@@ -622,7 +622,7 @@ TEST_F(MySqlConfigBackendDHCPv4Test, getSubnet4) {
     EXPECT_EQ(subnet2->toElement()->str(), returned_subnet->toElement()->str());
 
     // Fetching the subnet for an explicitly specified server tag should
-    // succeeed too.
+    // succeed too.
     returned_subnet = cbptr_->getSubnet4(ServerSelector::ONE("server1"),
                                          SubnetID(1024));
     EXPECT_EQ(subnet2->toElement()->str(), returned_subnet->toElement()->str());
@@ -639,19 +639,26 @@ TEST_F(MySqlConfigBackendDHCPv4Test, getSubnet4) {
 
     // Fetch this subnet by prefix and verify it matches.
     returned_subnet = cbptr_->getSubnet4(ServerSelector::ALL(),
-                                        test_subnets_[2]->toText());
+                                         test_subnets_[2]->toText());
     ASSERT_TRUE(returned_subnet);
     EXPECT_EQ(test_subnets_[2]->toElement()->str(), returned_subnet->toElement()->str());
 
-    // Update the the subnet in the database (both use the same prefix).
+    // Update the subnet in the database (both use the same prefix).
     subnet2.reset(new Subnet4(IOAddress("192.0.3.0"), 24, 30, 40, 60, 8192));
     cbptr_->createUpdateSubnet4(ServerSelector::ALL(),  subnet2);
 
     // Fetch again and verify.
     returned_subnet = cbptr_->getSubnet4(ServerSelector::ALL(),
-                                        test_subnets_[2]->toText());
+                                         test_subnets_[2]->toText());
     ASSERT_TRUE(returned_subnet);
     EXPECT_EQ(subnet2->toElement()->str(), returned_subnet->toElement()->str());
+
+    // Update the subnet when it conflicts same id and same prefix both
+    // with different subnets. This should throw.
+    // Subnets are 10.0.0.0/8 id 1024 and 192.0.3.0/24 id 8192
+    subnet2.reset(new Subnet4(IOAddress("10.0.0.0"), 8, 30, 40, 60, 8192));
+    EXPECT_THROW(cbptr_->createUpdateSubnet4(ServerSelector::ALL(),  subnet2),
+                 DbOperationError);
 }
 
 // Test that the information about unspecified optional parameters gets
index f46f45f623ab53a6aafed42d153f01fcd9ed34ce..7511bfd669aed3606b454035417ff09f29aa26ae 100644 (file)
@@ -569,7 +569,7 @@ private:
     /// created using static factory functions.
     ///
     /// @param buffer_type MySQL buffer type as defined in MySQL C API.
-    /// @param length Buffer length. 
+    /// @param length Buffer length.
     MySqlBinding(enum_field_types buffer_type, const size_t length);
 
     /// @brief Assigns new value to a buffer.
index 183934ca59bd66d63465b154b08e131a3fb8295e..2b59d8dbbbfc387b346ed0324f1cb01efbd443c6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2019 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -442,7 +442,7 @@ public:
             // Failure: check for the special case of duplicate entry.
             if (mysql_errno(mysql_) == ER_DUP_ENTRY) {
                 isc_throw(DuplicateEntry, "Database duplicate entry error");
-        }
+            }
             checkError(status, index, "unable to execute");
         }
     }
@@ -477,6 +477,10 @@ public:
         status = mysql_stmt_execute(statements_[index]);
 
         if (status != 0) {
+            // Failure: check for the special case of duplicate entry.
+            if (mysql_errno(mysql_) == ER_DUP_ENTRY) {
+                isc_throw(DuplicateEntry, "Database duplicate entry error");
+            }
             checkError(status, index, "unable to execute");
         }
 
index 6ca8a3eead626b1a7bdf93be917b059b5ff3da82..d4bfa892ce807e7f256e4ac0fdfc96abe16f1c18 100644 (file)
@@ -1909,7 +1909,7 @@ ALTER TABLE dhcp6_shared_network_server
     ON DELETE CASCADE ON UPDATE NO ACTION;
 
 -- Update dhcp4_subnet_server and dhcp6_subnet_server to allow update
--- on the prefix too.
+-- on the prefix too by setting the CASCADE action.
 
 ALTER TABLE dhcp4_subnet_server
     DROP FOREIGN KEY fk_dhcp4_subnet_server_subnet_id;
index 959f4b823a0111b49d502408e6803e3cf681954a..70ec6a67175952d2bba5f96de5f1d0538897f4bd 100644 (file)
@@ -591,7 +591,7 @@ ALTER TABLE dhcp6_shared_network_server
     ON DELETE CASCADE ON UPDATE NO ACTION;
 
 -- Update dhcp4_subnet_server and dhcp6_subnet_server to allow update
--- on the prefix too.
+-- on the prefix too by setting the CASCADE action.
 
 ALTER TABLE dhcp4_subnet_server
     DROP FOREIGN KEY fk_dhcp4_subnet_server_subnet_id;