]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#680,!426] Delete embedded shared network options when network is deleted.
authorMarcin Siodelski <marcin@isc.org>
Mon, 22 Jul 2019 12:15:33 +0000 (14:15 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 25 Jul 2019 07:58:11 +0000 (03:58 -0400)
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc
src/share/database/scripts/mysql/dhcpdb_create.mysql

index bd4de446da36bab6ae1bf6af7ca1f5ada9129de8..ac9a5304ad17f7bc44143005db557f8746049412 100644 (file)
@@ -2754,6 +2754,29 @@ TEST_F(MySqlConfigBackendDHCPv4Test, sharedNetworkLifetime) {
               returned_network->toElement()->str());
 }
 
+// Test that deleting a shared network triggers deletion of the options
+// associated with the shared network.
+TEST_F(MySqlConfigBackendDHCPv4Test, sharedNetworkOptions) {
+    EXPECT_NO_THROW(cbptr_->createUpdateSharedNetwork4(ServerSelector::ALL(), test_networks_[0]));
+    EXPECT_EQ(3, countRows("dhcp4_options"));
+
+    EXPECT_NO_THROW(cbptr_->createUpdateSharedNetwork4(ServerSelector::ALL(), test_networks_[1]));
+    EXPECT_EQ(0, countRows("dhcp4_options"));
+
+    EXPECT_NO_THROW(cbptr_->deleteSharedNetwork4(ServerSelector::ALL(),
+                                                 test_networks_[1]->getName()));
+    EXPECT_EQ(0, countRows("dhcp4_shared_network"));
+    EXPECT_EQ(0, countRows("dhcp4_options"));
+
+    EXPECT_NO_THROW(cbptr_->createUpdateSharedNetwork4(ServerSelector::ALL(), test_networks_[0]));
+    EXPECT_EQ(3, countRows("dhcp4_options"));
+
+    EXPECT_NO_THROW(cbptr_->deleteSharedNetwork4(ServerSelector::ALL(),
+                                                 test_networks_[0]->getName()));
+    EXPECT_EQ(0, countRows("dhcp4_shared_network"));
+    EXPECT_EQ(0, countRows("dhcp4_options"));
+}
+
 // Test that option definition can be inserted, fetched, updated and then
 // fetched again.
 TEST_F(MySqlConfigBackendDHCPv4Test, getOptionDef4) {
index 9a0e26c246f531e7cca15aaf8466ca8fac56da15..c0aedf423d47b463fb1f0d17669dbbe8ec2dc6e6 100644 (file)
@@ -2772,6 +2772,29 @@ TEST_F(MySqlConfigBackendDHCPv6Test, sharedNetworkLifetime) {
               returned_network->toElement()->str());
 }
 
+// Test that deleting a shared network triggers deletion of the options
+// associated with the shared network.
+TEST_F(MySqlConfigBackendDHCPv6Test, sharedNetworkOptions) {
+    EXPECT_NO_THROW(cbptr_->createUpdateSharedNetwork6(ServerSelector::ALL(), test_networks_[0]));
+    EXPECT_EQ(3, countRows("dhcp6_options"));
+
+    EXPECT_NO_THROW(cbptr_->createUpdateSharedNetwork6(ServerSelector::ALL(), test_networks_[1]));
+    EXPECT_EQ(0, countRows("dhcp6_options"));
+
+    EXPECT_NO_THROW(cbptr_->deleteSharedNetwork6(ServerSelector::ALL(),
+                                                 test_networks_[1]->getName()));
+    EXPECT_EQ(0, countRows("dhcp6_shared_network"));
+    EXPECT_EQ(0, countRows("dhcp6_options"));
+
+    EXPECT_NO_THROW(cbptr_->createUpdateSharedNetwork6(ServerSelector::ALL(), test_networks_[0]));
+    EXPECT_EQ(3, countRows("dhcp6_options"));
+
+    EXPECT_NO_THROW(cbptr_->deleteSharedNetwork6(ServerSelector::ALL(),
+                                                 test_networks_[0]->getName()));
+    EXPECT_EQ(0, countRows("dhcp6_shared_network"));
+    EXPECT_EQ(0, countRows("dhcp6_options"));
+}
+
 // Test that option definition can be inserted, fetched, updated and then
 // fetched again.
 TEST_F(MySqlConfigBackendDHCPv6Test, getOptionDef6) {
index 599fdbd3785305282bd49da0a52bcf3f98c356fc..7fae77ac53d79be47420d0ff2b04c52c3c1eda9b 100644 (file)
@@ -2377,6 +2377,35 @@ SET version = '8', minor = '1';
 
 # This line concludes database upgrade to version 8.1.
 
+# Drop existing trigger on the dhcp4_shared_network table.
+DROP TRIGGER dhcp4_shared_network_ADEL;
+
+# Create new trigger which will delete options associated with the shared
+# network.
+DELIMITER $$
+CREATE TRIGGER dhcp4_shared_network_BDEL BEFORE DELETE ON dhcp4_shared_network
+    FOR EACH ROW
+    BEGIN
+        CALL createAuditEntryDHCP4('dhcp4_shared_network', OLD.id, "delete");
+        DELETE FROM dhcp4_options WHERE shared_network_name = OLD.name;
+    END $$
+DELIMITER ;
+
+# Drop existing trigger on the dhcp4_subnet table.
+DROP TRIGGER dhcp4_subnet_ADEL;
+
+# Create new trigger which will delete pools associated with the subnet and
+# the options associated with the subnet.
+DELIMITER $$
+CREATE TRIGGER dhcp4_subnet_BDEL BEFORE DELETE ON dhcp4_subnet
+    FOR EACH ROW
+    BEGIN
+        CALL createAuditEntryDHCP4('dhcp4_subnet', OLD.subnet_id, "delete");
+        DELETE FROM dhcp4_pool WHERE subnet_id = OLD.subnet_id;
+        DELETE FROM dhcp4_options WHERE dhcp4_subnet_id = OLD.subnet_id;
+    END $$
+DELIMITER ;
+
 # Do not perform cascade deletion of the data in the dhcp4_pool because
 # the cascade deletion does not execute triggers associated with the table.
 # Instead we are going to use triggers on the dhcp4_subnet table.
@@ -2388,19 +2417,33 @@ ALTER TABLE dhcp4_pool
     REFERENCES dhcp4_subnet (subnet_id)
     ON DELETE NO ACTION ON UPDATE CASCADE;
 
+# Drop existing trigger on the dhcp6_shared_network table.
+DROP TRIGGER dhcp6_shared_network_ADEL;
 
-# Drop existing trigger on the dhcp4_subnet table.
-DROP TRIGGER dhcp4_subnet_ADEL;
+# Create new trigger which will delete options associated with the shared
+# network.
+DELIMITER $$
+CREATE TRIGGER dhcp6_shared_network_BDEL BEFORE DELETE ON dhcp6_shared_network
+    FOR EACH ROW
+    BEGIN
+        CALL createAuditEntryDHCP6('dhcp6_shared_network', OLD.id, "delete");
+        DELETE FROM dhcp6_options WHERE shared_network_name = OLD.name;
+    END $$
+DELIMITER ;
+
+# Drop existing trigger on the dhcp6_subnet table.
+DROP TRIGGER dhcp6_subnet_ADEL;
 
 # Create new trigger which will delete pools associated with the subnet and
 # the options associated with the subnet.
 DELIMITER $$
-CREATE TRIGGER dhcp4_subnet_BDEL BEFORE DELETE ON dhcp4_subnet
+CREATE TRIGGER dhcp6_subnet_BDEL BEFORE DELETE ON dhcp6_subnet
     FOR EACH ROW
     BEGIN
-        CALL createAuditEntryDHCP4('dhcp4_subnet', OLD.subnet_id, "delete");
-        DELETE FROM dhcp4_pool WHERE subnet_id = OLD.subnet_id;
-        DELETE FROM dhcp4_options WHERE dhcp4_subnet_id = OLD.subnet_id;
+        CALL createAuditEntryDHCP6('dhcp6_subnet', OLD.subnet_id, "delete");
+        DELETE FROM dhcp6_pool WHERE subnet_id = OLD.subnet_id;
+        DELETE FROM dhcp6_pd_pool WHERE subnet_id = OLD.subnet_id;
+        DELETE FROM dhcp6_options WHERE dhcp6_subnet_id = OLD.subnet_id;
     END $$
 DELIMITER ;
 
@@ -2433,23 +2476,6 @@ END
 $$
 DELIMITER ;
 
-# Drop existing trigger on the dhcp6_subnet table.
-DROP TRIGGER dhcp6_subnet_ADEL;
-
-# Create new trigger which will delete pools associated with the subnet and
-# the options associated with the subnet.
-DELIMITER $$
-CREATE TRIGGER dhcp6_subnet_BDEL BEFORE DELETE ON dhcp6_subnet
-    FOR EACH ROW
-    BEGIN
-        CALL createAuditEntryDHCP6('dhcp6_subnet', OLD.subnet_id, "delete");
-        DELETE FROM dhcp6_pool WHERE subnet_id = OLD.subnet_id;
-        DELETE FROM dhcp6_pd_pool WHERE subnet_id = OLD.subnet_id;
-        DELETE FROM dhcp6_options WHERE dhcp6_subnet_id = OLD.subnet_id;
-    END $$
-DELIMITER ;
-
-
 # Update the schema version number
 UPDATE schema_version
 SET version = '8', minor = '2';