Commit 87162653 authored by Marcin Siodelski's avatar Marcin Siodelski

[#93,!51] Pool specific options are now managed in MySQL database.

parent bfe0c99c
This diff is collapsed.
...@@ -127,6 +127,14 @@ public: ...@@ -127,6 +127,14 @@ public:
pool1.reset(new Pool4(IOAddress("10.0.0.10"), IOAddress("10.0.0.20"))); pool1.reset(new Pool4(IOAddress("10.0.0.10"), IOAddress("10.0.0.20")));
subnet->addPool(pool1); subnet->addPool(pool1);
pool1->getCfgOption()->add(test_options_[3]->option_,
test_options_[3]->persistent_,
test_options_[3]->space_name_);
pool1->getCfgOption()->add(test_options_[4]->option_,
test_options_[4]->persistent_,
test_options_[4]->space_name_);
pool2.reset(new Pool4(IOAddress("10.0.0.50"), IOAddress("10.0.0.60"))); pool2.reset(new Pool4(IOAddress("10.0.0.50"), IOAddress("10.0.0.60")));
subnet->addPool(pool2); subnet->addPool(pool2);
...@@ -803,6 +811,80 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteSubnetOption4) { ...@@ -803,6 +811,80 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteSubnetOption4) {
EXPECT_FALSE(returned_subnet->getCfgOption()->get(DHCP4_OPTION_SPACE, DHO_BOOT_FILE_NAME).option_); EXPECT_FALSE(returned_subnet->getCfgOption()->get(DHCP4_OPTION_SPACE, DHO_BOOT_FILE_NAME).option_);
} }
// This test verifies that option can be inserted, updated and deleted
// from the pool.
TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeletePoolOption4) {
// Insert new subnet.
Subnet4Ptr subnet = test_subnets_[1];
cbptr_->createUpdateSubnet4(ServerSelector::UNASSIGNED(), subnet);
// Add an option into the pool.
const PoolPtr pool = subnet->getPool(Lease::TYPE_V4, IOAddress("192.0.2.10"));
ASSERT_TRUE(pool);
OptionDescriptorPtr opt_boot_file_name = test_options_[0];
cbptr_->createUpdateOption4(ServerSelector::UNASSIGNED(),
pool->getFirstAddress(),
pool->getLastAddress(),
opt_boot_file_name);
// Query for a subnet.
Subnet4Ptr returned_subnet = cbptr_->getSubnet4(ServerSelector::UNASSIGNED(),
subnet->getID());
ASSERT_TRUE(returned_subnet);
// The returned subnet should include our pool.
const PoolPtr returned_pool = returned_subnet->getPool(Lease::TYPE_V4,
IOAddress("192.0.2.10"));
ASSERT_TRUE(returned_pool);
// The pool should contain option we added earlier.
OptionDescriptor returned_opt_boot_file_name =
returned_pool->getCfgOption()->get(DHCP4_OPTION_SPACE, DHO_BOOT_FILE_NAME);
ASSERT_TRUE(returned_opt_boot_file_name.option_);
EXPECT_TRUE(returned_opt_boot_file_name.equals(*opt_boot_file_name));
// Modify the option and update it in the database.
opt_boot_file_name->persistent_ = !opt_boot_file_name->persistent_;
cbptr_->createUpdateOption4(ServerSelector::UNASSIGNED(),
pool->getFirstAddress(),
pool->getLastAddress(),
opt_boot_file_name);
// Fetch the subnet and the corresponding pool.
returned_subnet = cbptr_->getSubnet4(ServerSelector::UNASSIGNED(),
subnet->getID());
ASSERT_TRUE(returned_subnet);
const PoolPtr returned_pool1 = returned_subnet->getPool(Lease::TYPE_V4,
IOAddress("192.0.2.10"));
ASSERT_TRUE(returned_pool1);
// Test that the option has been correctly updated in the database.
returned_opt_boot_file_name =
returned_pool1->getCfgOption()->get(DHCP4_OPTION_SPACE, DHO_BOOT_FILE_NAME);
ASSERT_TRUE(returned_opt_boot_file_name.option_);
EXPECT_TRUE(returned_opt_boot_file_name.equals(*opt_boot_file_name));
// Delete option from the pool.
cbptr_->deleteOption4(ServerSelector::UNASSIGNED(),
pool->getFirstAddress(),
pool->getLastAddress(),
opt_boot_file_name->option_->getType(),
opt_boot_file_name->space_name_);
// Fetch the subnet and the pool from the database again to make sure
// that the option is really gone.
returned_subnet = cbptr_->getSubnet4(ServerSelector::UNASSIGNED(),
subnet->getID());
ASSERT_TRUE(returned_subnet);
const PoolPtr returned_pool2 = returned_subnet->getPool(Lease::TYPE_V4,
IOAddress("192.0.2.10"));
ASSERT_TRUE(returned_pool2);
// Option should be gone.
EXPECT_FALSE(returned_pool2->getCfgOption()->get(DHCP4_OPTION_SPACE,
DHO_BOOT_FILE_NAME).option_);
}
// This test verifies that shared network level option can be added, // This test verifies that shared network level option can be added,
// updated and deleted. // updated and deleted.
TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteSharedNetworkOption4) { TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteSharedNetworkOption4) {
......
...@@ -773,6 +773,14 @@ ALTER TABLE hosts ...@@ -773,6 +773,14 @@ ALTER TABLE hosts
INSERT INTO dhcp_option_scope (scope_id, scope_name) INSERT INTO dhcp_option_scope (scope_id, scope_name)
VALUES(4, "shared-network"); VALUES(4, "shared-network");
# Add scope for pool specific options.
INSERT INTO dhcp_option_scope (scope_id, scope_name)
VALUES(5, "pool");
# Add scope for PD pool specific options.
INSERT INTO dhcp_option_scope (scope_id, scope_name)
VALUES(6, "pd-pool");
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `modification` -- Table `modification`
-- ----------------------------------------------------- -- -----------------------------------------------------
...@@ -1033,6 +1041,17 @@ CREATE TABLE IF NOT EXISTS dhcp4_options_server ( ...@@ -1033,6 +1041,17 @@ CREATE TABLE IF NOT EXISTS dhcp4_options_server (
ON DELETE NO ACTION ON UPDATE NO ACTION ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB; ) ENGINE=InnoDB;
# Create trigger which removes pool specific options upon removal of
# the pool.
DELIMITER $$
CREATE TRIGGER dhcp4_pool_BDEL BEFORE DELETE ON dhcp4_pool FOR EACH ROW
-- Edit trigger body code below this line. Do not edit lines above this one
BEGIN
DELETE FROM dhcp4_options WHERE scope_id = 5 AND pool_id = OLD.id;
END
$$
DELIMITER ;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `dhcp6_server` -- Table `dhcp6_server`
-- ----------------------------------------------------- -- -----------------------------------------------------
...@@ -1288,6 +1307,17 @@ CREATE TABLE IF NOT EXISTS dhcp6_options_server ( ...@@ -1288,6 +1307,17 @@ CREATE TABLE IF NOT EXISTS dhcp6_options_server (
ON DELETE NO ACTION ON UPDATE NO ACTION ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB; ) ENGINE=InnoDB;
# Create trigger which removes pool specific options upon removal of
# the pool.
DELIMITER $$
CREATE TRIGGER dhcp6_pool_BDEL BEFORE DELETE ON dhcp6_pool FOR EACH ROW
-- Edit trigger body code below this line. Do not edit lines above this one
BEGIN
DELETE FROM dhcp6_options WHERE scope_id = 5 AND pool_id = OLD.id;
END
$$
DELIMITER ;
# Update the schema version number # Update the schema version number
UPDATE schema_version UPDATE schema_version
SET version = '7', minor = '0'; SET version = '7', minor = '0';
......
...@@ -116,6 +116,14 @@ UPDATE dhcp6_options SET dhcp6_subnet_id = NULL WHERE dhcp6_subnet_id = 0; ...@@ -116,6 +116,14 @@ UPDATE dhcp6_options SET dhcp6_subnet_id = NULL WHERE dhcp6_subnet_id = 0;
INSERT INTO dhcp_option_scope (scope_id, scope_name) INSERT INTO dhcp_option_scope (scope_id, scope_name)
VALUES(4, "shared-network"); VALUES(4, "shared-network");
# Add scope for pool specific options.
INSERT INTO dhcp_option_scope (scope_id, scope_name)
VALUES(5, "pool");
# Add scope for PD pool specific options.
INSERT INTO dhcp_option_scope (scope_id, scope_name)
VALUES(6, "pd-pool");
# Create table modification # Create table modification
CREATE TABLE IF NOT EXISTS modification ( CREATE TABLE IF NOT EXISTS modification (
id TINYINT(3) NOT NULL, id TINYINT(3) NOT NULL,
...@@ -359,6 +367,17 @@ CREATE TABLE IF NOT EXISTS dhcp4_options_server ( ...@@ -359,6 +367,17 @@ CREATE TABLE IF NOT EXISTS dhcp4_options_server (
ON DELETE NO ACTION ON UPDATE NO ACTION ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB; ) ENGINE=InnoDB;
# Create trigger which removes pool specific options upon removal of
# the pool.
DELIMITER $$
CREATE TRIGGER dhcp4_pool_BDEL BEFORE DELETE ON dhcp4_pool FOR EACH ROW
-- Edit trigger body code below this line. Do not edit lines above this one
BEGIN
DELETE FROM dhcp4_options WHERE scope_id = 5 AND pool_id = OLD.id;
END
$$
DELIMITER ;
# Create table dhcp6_server # Create table dhcp6_server
# #
CREATE TABLE IF NOT EXISTS dhcp6_server ( CREATE TABLE IF NOT EXISTS dhcp6_server (
...@@ -597,6 +616,17 @@ CREATE TABLE IF NOT EXISTS dhcp6_options_server ( ...@@ -597,6 +616,17 @@ CREATE TABLE IF NOT EXISTS dhcp6_options_server (
ON DELETE NO ACTION ON UPDATE NO ACTION ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB; ) ENGINE=InnoDB;
# Create trigger which removes pool specific options upon removal of
# the pool.
DELIMITER $$
CREATE TRIGGER dhcp6_pool_BDEL BEFORE DELETE ON dhcp6_pool FOR EACH ROW
-- Edit trigger body code below this line. Do not edit lines above this one
BEGIN
DELETE FROM dhcp6_options WHERE scope_id = 5 AND pool_id = OLD.id;
END
$$
DELIMITER ;
# Update the schema version number # Update the schema version number
UPDATE schema_version UPDATE schema_version
SET version = '7', minor = '0'; SET version = '7', minor = '0';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment