summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h39
-rw-r--r--src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc44
-rw-r--r--src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc53
3 files changed, 118 insertions, 18 deletions
diff --git a/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h b/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h
index 9670890ede..6ae77e3c0e 100644
--- a/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h
+++ b/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h
@@ -666,12 +666,9 @@ namespace {
#endif
#ifndef MYSQL_UPDATE_OPTION_COMMON
-#define MYSQL_UPDATE_OPTION_COMMON(table_prefix, pd_pool_id, ...) \
+#define MYSQL_UPDATE_OPTION_COMMON(table_prefix, server_join, pd_pool_id, ...) \
"UPDATE " #table_prefix "_options AS o " \
- "INNER JOIN " #table_prefix "_options_server AS a" \
- " ON o.option_id = a.option_id " \
- "INNER JOIN " #table_prefix "_server AS s" \
- " ON a.server_id = s.id " \
+ server_join \
"SET" \
" o.code = ?," \
" o.value = ?," \
@@ -689,16 +686,26 @@ namespace {
"WHERE " #__VA_ARGS__
#define MYSQL_UPDATE_OPTION4_WITH_TAG(...) \
- MYSQL_UPDATE_OPTION_COMMON(dhcp4, "", s.tag = ? __VA_ARGS__)
+ MYSQL_UPDATE_OPTION_COMMON(dhcp4, \
+ "INNER JOIN dhcp4_options_server AS a" \
+ " ON o.option_id = a.option_id " \
+ "INNER JOIN dhcp4_server AS s" \
+ " ON a.server_id = s.id ", \
+ "", s.tag = ? __VA_ARGS__)
#define MYSQL_UPDATE_OPTION4_NO_TAG(...) \
- MYSQL_UPDATE_OPTION_COMMON(dhcp4, "", __VA_ARGS__)
+ MYSQL_UPDATE_OPTION_COMMON(dhcp4, "", "", __VA_ARGS__)
#define MYSQL_UPDATE_OPTION6_WITH_TAG(...) \
- MYSQL_UPDATE_OPTION_COMMON(dhcp6, ", o.pd_pool_id = ? ", s.tag = ? __VA_ARGS__)
+ MYSQL_UPDATE_OPTION_COMMON(dhcp6, \
+ "INNER JOIN dhcp6_options_server AS a" \
+ " ON o.option_id = a.option_id " \
+ "INNER JOIN dhcp6_server AS s" \
+ " ON a.server_id = s.id ", \
+ ", o.pd_pool_id = ? ", s.tag = ? __VA_ARGS__)
#define MYSQL_UPDATE_OPTION6_NO_TAG(...) \
- MYSQL_UPDATE_OPTION_COMMON(dhcp6, ", o.pd_pool_id = ? ", __VA_ARGS__)
+ MYSQL_UPDATE_OPTION_COMMON(dhcp6, "", ", o.pd_pool_id = ? ", __VA_ARGS__)
#endif
#ifndef MYSQL_UPDATE_SERVER
@@ -824,20 +831,20 @@ namespace {
"WHERE a.option_def_id IS NULL " #__VA_ARGS__
#endif
-#ifndef MYSQL_DELETE_OPTION
-#define MYSQL_DELETE_OPTION_COMMON(table_prefix, ...) \
+#ifndef MYSQL_DELETE_OPTION_WITH_TAG
+#define MYSQL_DELETE_OPTION_WITH_TAG(table_prefix, ...) \
"DELETE o FROM " #table_prefix "_options AS o " \
"INNER JOIN " #table_prefix "_options_server AS a" \
" ON o.option_id = a.option_id " \
"INNER JOIN " #table_prefix "_server AS s" \
" ON a.server_id = s.id " \
- #__VA_ARGS__
-
-#define MYSQL_DELETE_OPTION_WITH_TAG(table_prefix, ...) \
- MYSQL_DELETE_OPTION_COMMON(table_prefix, WHERE s.tag = ? __VA_ARGS__)
+ "WHERE s.tag = ? " #__VA_ARGS__
+#endif
+#ifndef MYSQL_DELETE_OPTION_NO_TAG
#define MYSQL_DELETE_OPTION_NO_TAG(table_prefix, ...) \
- MYSQL_DELETE_OPTION_COMMON(table_prefix, __VA_ARGS__)
+ "DELETE o FROM " #table_prefix "_options AS o " \
+ #__VA_ARGS__
#endif
#ifndef MYSQL_DELETE_OPTION_UNASSIGNED
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 ff1c059fcc..1f974a363c 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
@@ -3624,8 +3624,11 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteSubnetOption4) {
"subnet set");
}
+ // The inserted subnet contains two options.
+ ASSERT_EQ(2, countRows("dhcp4_options"));
+
OptionDescriptorPtr opt_boot_file_name = test_options_[0];
- cbptr_->createUpdateOption4(ServerSelector::ALL(), subnet->getID(),
+ cbptr_->createUpdateOption4(ServerSelector::ANY(), subnet->getID(),
opt_boot_file_name);
returned_subnet = cbptr_->getSubnet4(ServerSelector::ALL(),
@@ -3653,11 +3656,15 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteSubnetOption4) {
"subnet specific option set");
}
+ // We have added one option to the existing subnet. We should now have
+ // three options.
+ ASSERT_EQ(3, countRows("dhcp4_options"));
+
opt_boot_file_name->persistent_ = !opt_boot_file_name->persistent_;
cbptr_->createUpdateOption4(ServerSelector::ALL(), subnet->getID(),
opt_boot_file_name);
- returned_subnet = cbptr_->getSubnet4(ServerSelector::ALL(),
+ returned_subnet = cbptr_->getSubnet4(ServerSelector::ANY(),
subnet->getID());
ASSERT_TRUE(returned_subnet);
returned_opt_boot_file_name =
@@ -3676,6 +3683,10 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteSubnetOption4) {
"subnet specific option set");
}
+ // Updating the option should replace the existing instance with the new
+ // instance. Therefore, we should still have three options.
+ ASSERT_EQ(3, countRows("dhcp4_options"));
+
// It should succeed for any server.
EXPECT_EQ(1, cbptr_->deleteOption4(ServerSelector::ANY(), subnet->getID(),
opt_boot_file_name->option_->getType(),
@@ -3693,6 +3704,9 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteSubnetOption4) {
AuditEntry::ModificationType::UPDATE,
"subnet specific option deleted");
}
+
+ // We should have only two options after deleting one of them.
+ ASSERT_EQ(2, countRows("dhcp4_options"));
}
// This test verifies that option can be inserted, updated and deleted
@@ -3709,6 +3723,9 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeletePoolOption4) {
"subnet set");
}
+ // Inserted subnet has two options.
+ ASSERT_EQ(2, countRows("dhcp4_options"));
+
// Add an option into the pool.
const PoolPtr pool = subnet->getPool(Lease::TYPE_V4, IOAddress("192.0.2.10"));
ASSERT_TRUE(pool);
@@ -3747,6 +3764,8 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeletePoolOption4) {
"pool specific option set");
}
+ // With the newly inserted option we should now have three options.
+ ASSERT_EQ(3, countRows("dhcp4_options"));
// Modify the option and update it in the database.
opt_boot_file_name->persistent_ = !opt_boot_file_name->persistent_;
@@ -3781,6 +3800,10 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeletePoolOption4) {
"pool specific option set");
}
+ // The new option instance should replace the existing one, so we should
+ // still have three options.
+ ASSERT_EQ(3, countRows("dhcp4_options"));
+
// Delete option for any server should succeed.
EXPECT_EQ(1, cbptr_->deleteOption4(ServerSelector::ANY(),
pool->getFirstAddress(),
@@ -3808,6 +3831,10 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeletePoolOption4) {
AuditEntry::ModificationType::UPDATE,
"pool specific option deleted");
}
+
+ // The option has been deleted so the number of options should now
+ // be down to 2.
+ EXPECT_EQ(2, countRows("dhcp4_options"));
}
// This test verifies that shared network level option can be added,
@@ -3831,6 +3858,9 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteSharedNetworkOption4) {
"shared network set");
}
+ // The inserted shared network has no options.
+ ASSERT_EQ(0, countRows("dhcp4_options"));
+
OptionDescriptorPtr opt_boot_file_name = test_options_[0];
cbptr_->createUpdateOption4(ServerSelector::ALL(),
shared_network->getName(),
@@ -3861,6 +3891,9 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteSharedNetworkOption4) {
"shared network specific option set");
}
+ // One option should now be stored in the database.
+ ASSERT_EQ(1, countRows("dhcp4_options"));
+
opt_boot_file_name->persistent_ = !opt_boot_file_name->persistent_;
cbptr_->createUpdateOption4(ServerSelector::ALL(),
shared_network->getName(),
@@ -3885,6 +3918,10 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteSharedNetworkOption4) {
"shared network specific option set");
}
+ // The new option instance should replace the existing option instance,
+ // so we should still have one option.
+ ASSERT_EQ(1, countRows("dhcp4_options"));
+
// Deleting an option for any server should succeed.
EXPECT_EQ(1, cbptr_->deleteOption4(ServerSelector::ANY(),
shared_network->getName(),
@@ -3901,6 +3938,9 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteSharedNetworkOption4) {
AuditEntry::ModificationType::UPDATE,
"shared network specific option deleted");
}
+
+ // After deleting the option we should be back to 0.
+ EXPECT_EQ(0, countRows("dhcp4_options"));
}
diff --git a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc
index b513b89ead..0e9af64516 100644
--- a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc
+++ b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc
@@ -3665,6 +3665,9 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeleteSubnetOption6) {
"subnet set");
}
+ // The inserted subnet contains four options.
+ ASSERT_EQ(4, countRows("dhcp6_options"));
+
OptionDescriptorPtr opt_posix_timezone = test_options_[0];
cbptr_->createUpdateOption6(ServerSelector::ALL(), subnet->getID(),
opt_posix_timezone);
@@ -3694,6 +3697,10 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeleteSubnetOption6) {
"subnet specific option set");
}
+ // We have added one option to the existing subnet. We should now have
+ // five options.
+ ASSERT_EQ(5, countRows("dhcp6_options"));
+
opt_posix_timezone->persistent_ = !opt_posix_timezone->persistent_;
cbptr_->createUpdateOption6(ServerSelector::ALL(), subnet->getID(),
opt_posix_timezone);
@@ -3717,6 +3724,10 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeleteSubnetOption6) {
"subnet specific option set");
}
+ // Updating the option should replace the existing instance with the new
+ // instance. Therefore, we should still have five options.
+ ASSERT_EQ(5, countRows("dhcp6_options"));
+
// It should succeed for any server.
EXPECT_EQ(1, cbptr_->deleteOption6(ServerSelector::ANY(), subnet->getID(),
opt_posix_timezone->option_->getType(),
@@ -3734,6 +3745,9 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeleteSubnetOption6) {
AuditEntry::ModificationType::UPDATE,
"subnet specific option deleted");
}
+
+ // We should have only four options after deleting one of them.
+ ASSERT_EQ(4, countRows("dhcp6_options"));
}
// This test verifies that option can be inserted, updated and deleted
@@ -3750,6 +3764,9 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeletePoolOption6) {
"subnet set");
}
+ // Inserted subnet has four options.
+ ASSERT_EQ(4, countRows("dhcp6_options"));
+
// Add an option into the pool.
const PoolPtr pool = subnet->getPool(Lease::TYPE_NA,
IOAddress("2001:db8::10"));
@@ -3789,6 +3806,8 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeletePoolOption6) {
"address pool specific option set");
}
+ // With the newly inserted option we should now have five options.
+ ASSERT_EQ(5, countRows("dhcp6_options"));
// Modify the option and update it in the database.
opt_posix_timezone->persistent_ = !opt_posix_timezone->persistent_;
@@ -3823,6 +3842,10 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeletePoolOption6) {
"address pool specific option set");
}
+ // The new option instance should replace the existing one, so we should
+ // still have five options.
+ ASSERT_EQ(5, countRows("dhcp6_options"));
+
// Delete option for any server should succeed.
EXPECT_EQ(1, cbptr_->deleteOption6(ServerSelector::ANY(),
pool->getFirstAddress(),
@@ -3850,6 +3873,10 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeletePoolOption6) {
AuditEntry::ModificationType::UPDATE,
"address pool specific option deleted");
}
+
+ // The option has been deleted so the number of options should now
+ // be down to 4.
+ EXPECT_EQ(4, countRows("dhcp6_options"));
}
// This test verifies that option can be inserted, updated and deleted
@@ -3866,6 +3893,9 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeletePdPoolOption6) {
"subnet set");
}
+ // Inserted subnet has four options.
+ ASSERT_EQ(4, countRows("dhcp6_options"));
+
// Add an option into the pd pool.
const PoolPtr pd_pool = subnet->getPool(Lease::TYPE_PD,
IOAddress("2001:db8:a:10::"));
@@ -3908,6 +3938,8 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeletePdPoolOption6) {
"prefix delegation pool specific option set");
}
+ // With the newly inserted option we should now have five options.
+ ASSERT_EQ(5, countRows("dhcp6_options"));
// Modify the option and update it in the database.
opt_posix_timezone->persistent_ = !opt_posix_timezone->persistent_;
@@ -3943,6 +3975,10 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeletePdPoolOption6) {
"prefix delegation pool specific option set");
}
+ // The new option instance should replace the existing one, so we should
+ // still have five options.
+ ASSERT_EQ(5, countRows("dhcp6_options"));
+
// Delete option for any server should succeed.
EXPECT_EQ(1, cbptr_->deleteOption6(ServerSelector::ANY(),
pd_pool->getFirstAddress(),
@@ -3970,6 +4006,10 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeletePdPoolOption6) {
AuditEntry::ModificationType::UPDATE,
"prefix delegation pool specific option deleted");
}
+
+ // The option has been deleted so the number of options should now
+ // be down to 4.
+ EXPECT_EQ(4, countRows("dhcp6_options"));
}
// This test verifies that shared network level option can be added,
@@ -3993,6 +4033,9 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeleteSharedNetworkOption6) {
"shared network set");
}
+ // The inserted shared network has no options.
+ ASSERT_EQ(0, countRows("dhcp6_options"));
+
OptionDescriptorPtr opt_posix_timezone = test_options_[0];
cbptr_->createUpdateOption6(ServerSelector::ALL(),
shared_network->getName(),
@@ -4023,6 +4066,9 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeleteSharedNetworkOption6) {
"shared network specific option set");
}
+ // One option should now be stored in the database.
+ ASSERT_EQ(1, countRows("dhcp6_options"));
+
opt_posix_timezone->persistent_ = !opt_posix_timezone->persistent_;
cbptr_->createUpdateOption6(ServerSelector::ALL(),
shared_network->getName(),
@@ -4047,6 +4093,10 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeleteSharedNetworkOption6) {
"shared network specific option set");
}
+ // The new option instance should replace the existing option instance,
+ // so we should still have one option.
+ ASSERT_EQ(1, countRows("dhcp6_options"));
+
// Deleting an option for any server should succeed.
EXPECT_EQ(1, cbptr_->deleteOption6(ServerSelector::ANY(),
shared_network->getName(),
@@ -4063,6 +4113,9 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeleteSharedNetworkOption6) {
AuditEntry::ModificationType::UPDATE,
"shared network specific option deleted");
}
+
+ // After deleting the option we should be back to 0.
+ EXPECT_EQ(0, countRows("dhcp6_options"));
}
}