Commit 63e0cbda authored by Marcin Siodelski's avatar Marcin Siodelski

[#429,!217] Extended dhcpX_global_parameter: added parameter_type.

parent a88c177e
...@@ -258,7 +258,7 @@ mysql_upgrade_test() { ...@@ -258,7 +258,7 @@ mysql_upgrade_test() {
assert_str_eq "1.0" ${version} "Expected kea-admin to return %s, returned value was %s" assert_str_eq "1.0" ${version} "Expected kea-admin to return %s, returned value was %s"
# Ok, we have a 1.0 database. Let's upgrade it to 7.0 # Ok, we have a 1.0 database. Let's upgrade it to 8.0
${keaadmin} lease-upgrade mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir ${keaadmin} lease-upgrade mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
ERRCODE=$? ERRCODE=$?
...@@ -491,7 +491,7 @@ EOF ...@@ -491,7 +491,7 @@ EOF
run_statement "dhcp4_audit" "$qry" run_statement "dhcp4_audit" "$qry"
# table: dhcp4_global_parameter # table: dhcp4_global_parameter
qry="select id, name, value, modification_ts from dhcp4_global_parameter" qry="select id, name, value, parameter_type, modification_ts from dhcp4_global_parameter"
run_statement "dhcp4_global_parameter" "$qry" run_statement "dhcp4_global_parameter" "$qry"
# table: dhcp4_global_parameter_server # table: dhcp4_global_parameter_server
...@@ -547,7 +547,7 @@ EOF ...@@ -547,7 +547,7 @@ EOF
run_statement "dhcp6_audit" "$qry" run_statement "dhcp6_audit" "$qry"
# table: dhcp6_global_parameter # table: dhcp6_global_parameter
qry="select id, name, value, modification_ts from dhcp6_global_parameter" qry="select id, name, value, parameter_type, modification_ts from dhcp6_global_parameter"
run_statement "dhcp6_global_parameter" "$qry" run_statement "dhcp6_global_parameter" "$qry"
# table: dhcp6_global_parameter_server # table: dhcp6_global_parameter_server
...@@ -642,6 +642,10 @@ EOF ...@@ -642,6 +642,10 @@ EOF
# New triggers aren't tested here because the extensive tests are # New triggers aren't tested here because the extensive tests are
# provided with the backend implementations. # provided with the backend implementations.
# parameter_data_type must exist and must have 4 rows.
qry="SELECT COUNT(*) FROM parameter_data_type";
run_statement "parameter_data_type count" "$qry" 4;
# Verify upgraded schema reports version 8.0 # Verify upgraded schema reports version 8.0
version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir) version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
assert_str_eq "8.0" ${version} "Expected kea-admin to return %s, returned value was %s" assert_str_eq "8.0" ${version} "Expected kea-admin to return %s, returned value was %s"
......
...@@ -152,6 +152,7 @@ public: ...@@ -152,6 +152,7 @@ public:
MySqlBinding::createInteger<uint64_t>(), // id MySqlBinding::createInteger<uint64_t>(), // id
MySqlBinding::createString(GLOBAL_PARAMETER_NAME_BUF_LENGTH), // name MySqlBinding::createString(GLOBAL_PARAMETER_NAME_BUF_LENGTH), // name
MySqlBinding::createString(GLOBAL_PARAMETER_VALUE_BUF_LENGTH), // value MySqlBinding::createString(GLOBAL_PARAMETER_VALUE_BUF_LENGTH), // value
MySqlBinding::createInteger<uint8_t>(), // parameter_type
MySqlBinding::createTimestamp() // modification_ts MySqlBinding::createTimestamp() // modification_ts
}; };
...@@ -159,9 +160,44 @@ public: ...@@ -159,9 +160,44 @@ public:
[&parameters] [&parameters]
(MySqlBindingCollection& out_bindings) { (MySqlBindingCollection& out_bindings) {
if (!out_bindings[1]->getString().empty()) { if (!out_bindings[1]->getString().empty()) {
StampedValuePtr stamped_value(new StampedValue(out_bindings[1]->getString(), std::string name = out_bindings[1]->getString();
out_bindings[2]->getString())); std::string value = out_bindings[2]->getString();
stamped_value->setModificationTime(out_bindings[3]->getTimestamp()); uint8_t parameter_type = out_bindings[3]->getInteger<uint8_t>();
StampedValuePtr stamped_value;
try {
switch (static_cast<Element::types>(parameter_type)) {
case Element::string:
stamped_value = StampedValue::create(name, value);
break;
case Element::integer:
stamped_value = StampedValue::create(name,
Element::create(boost::lexical_cast<int64_t>(value)));
break;
case Element::boolean:
stamped_value = StampedValue::create(name,
Element::create((value == "1") ? true : false));
break;
case Element::real:
stamped_value = StampedValue::create(name,
Element::create(boost::lexical_cast<double>(value)));
break;
default:
isc_throw(TypeError, "invalid type of the parameter '"
<< name << "' fetched from the database");
}
} catch (const boost::bad_lexical_cast& ex) {
isc_throw(BadValue, "actual type of the value '" << name
<< "' is different than marked in the database");
}
stamped_value->setModificationTime(out_bindings[4]->getTimestamp());
parameters.insert(stamped_value); parameters.insert(stamped_value);
} }
}); });
...@@ -209,6 +245,7 @@ public: ...@@ -209,6 +245,7 @@ public:
MySqlBindingCollection in_bindings = { MySqlBindingCollection in_bindings = {
MySqlBinding::createString(value->getName()), MySqlBinding::createString(value->getName()),
MySqlBinding::createString(value->getValue()), MySqlBinding::createString(value->getValue()),
MySqlBinding::createInteger<uint8_t>(value->getType()),
MySqlBinding::createTimestamp(value->getModificationTime()), MySqlBinding::createTimestamp(value->getModificationTime()),
MySqlBinding::createString(tag), MySqlBinding::createString(tag),
MySqlBinding::createString(value->getName()) MySqlBinding::createString(value->getName())
......
...@@ -35,6 +35,7 @@ namespace { ...@@ -35,6 +35,7 @@ namespace {
" g.id," \ " g.id," \
" g.name," \ " g.name," \
" g.value," \ " g.value," \
" g.parameter_type," \
" g.modification_ts " \ " g.modification_ts " \
"FROM " #table_prefix "_global_parameter AS g " \ "FROM " #table_prefix "_global_parameter AS g " \
"INNER JOIN " #table_prefix "_global_parameter_server AS a " \ "INNER JOIN " #table_prefix "_global_parameter_server AS a " \
...@@ -217,8 +218,9 @@ namespace { ...@@ -217,8 +218,9 @@ namespace {
"INSERT INTO " #table_prefix "_global_parameter(" \ "INSERT INTO " #table_prefix "_global_parameter(" \
" name," \ " name," \
" value," \ " value," \
" parameter_type," \
" modification_ts" \ " modification_ts" \
") VALUES (?, ?, ?)" ") VALUES (?, ?, ?, ?)"
#endif #endif
#ifndef MYSQL_INSERT_GLOBAL_PARAMETER_SERVER #ifndef MYSQL_INSERT_GLOBAL_PARAMETER_SERVER
...@@ -322,6 +324,7 @@ namespace { ...@@ -322,6 +324,7 @@ namespace {
"SET" \ "SET" \
" g.name = ?," \ " g.name = ?," \
" g.value = ?," \ " g.value = ?," \
" g.parameter_type = ?," \
" g.modification_ts = ? " \ " g.modification_ts = ? " \
"WHERE s.tag = ? AND g.name = ?" "WHERE s.tag = ? AND g.name = ?"
#endif #endif
......
...@@ -1849,6 +1849,38 @@ CREATE TRIGGER dhcp4_options_ADEL AFTER DELETE ON dhcp4_options ...@@ -1849,6 +1849,38 @@ CREATE TRIGGER dhcp4_options_ADEL AFTER DELETE ON dhcp4_options
END $$ END $$
DELIMITER ; DELIMITER ;
-- -----------------------------------------------------
-- Table `parameter_data_type`
-- Reflects an enum used by Kea to define supported
-- data types for the simple configuration parameters,
-- e.g. global parameters used by DHCP servers.
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS parameter_data_type (
id TINYINT UNSIGNED NOT NULL PRIMARY KEY,
name VARCHAR(32) NOT NULL
) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO parameter_data_type VALUES (0, 'integer');
INSERT INTO parameter_data_type VALUES (1, 'real');
INSERT INTO parameter_data_type VALUES (2, 'boolean');
INSERT INTO parameter_data_type VALUES (4, 'string');
COMMIT;
ALTER TABLE dhcp4_global_parameter
ADD COLUMN parameter_type TINYINT UNSIGNED NOT NULL;
ALTER TABLE dhcp4_global_parameter
ADD CONSTRAINT fk_dhcp4_global_parameter_type FOREIGN KEY (parameter_type)
REFERENCES parameter_data_type (id);
ALTER TABLE dhcp6_global_parameter
ADD COLUMN parameter_type TINYINT UNSIGNED NOT NULL;
ALTER TABLE dhcp6_global_parameter
ADD CONSTRAINT fk_dhcp6_global_parameter_type FOREIGN KEY (parameter_type)
REFERENCES parameter_data_type (id);
# Update the schema version number # Update the schema version number
UPDATE schema_version UPDATE schema_version
......
...@@ -59,6 +59,7 @@ DROP TABLE IF EXISTS dhcp6_shared_network_server; ...@@ -59,6 +59,7 @@ DROP TABLE IF EXISTS dhcp6_shared_network_server;
DROP TABLE IF EXISTS dhcp6_subnet; DROP TABLE IF EXISTS dhcp6_subnet;
DROP TABLE IF EXISTS dhcp6_subnet_server; DROP TABLE IF EXISTS dhcp6_subnet_server;
DROP TABLE IF EXISTS modification; DROP TABLE IF EXISTS modification;
DROP TABLE IF EXISTS parameter_data_type;
DROP PROCEDURE IF EXISTS createAuditRevisionDHCP4; DROP PROCEDURE IF EXISTS createAuditRevisionDHCP4;
DROP PROCEDURE IF EXISTS createAuditEntryDHCP4; DROP PROCEDURE IF EXISTS createAuditEntryDHCP4;
DROP TRIGGER IF EXISTS dhcp4_global_parameter_AINS; DROP TRIGGER IF EXISTS dhcp4_global_parameter_AINS;
......
...@@ -532,6 +532,38 @@ CREATE TRIGGER dhcp4_options_ADEL AFTER DELETE ON dhcp4_options ...@@ -532,6 +532,38 @@ CREATE TRIGGER dhcp4_options_ADEL AFTER DELETE ON dhcp4_options
END $$ END $$
DELIMITER ; DELIMITER ;
-- -----------------------------------------------------
-- Table parameter_data_type
-- Reflects an enum used by Kea to define supported
-- data types for the simple configuration parameters,
-- e.g. global parameters used by DHCP servers.
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS parameter_data_type (
id TINYINT UNSIGNED NOT NULL PRIMARY KEY,
name VARCHAR(32) NOT NULL
) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO parameter_data_type VALUES (0, 'integer');
INSERT INTO parameter_data_type VALUES (1, 'real');
INSERT INTO parameter_data_type VALUES (2, 'boolean');
INSERT INTO parameter_data_type VALUES (4, 'string');
COMMIT;
ALTER TABLE dhcp4_global_parameter
ADD COLUMN parameter_type TINYINT UNSIGNED NOT NULL;
ALTER TABLE dhcp4_global_parameter
ADD CONSTRAINT fk_dhcp4_global_parameter_type FOREIGN KEY (parameter_type)
REFERENCES parameter_data_type (id);
ALTER TABLE dhcp6_global_parameter
ADD COLUMN parameter_type TINYINT UNSIGNED NOT NULL;
ALTER TABLE dhcp6_global_parameter
ADD CONSTRAINT fk_dhcp6_global_parameter_type FOREIGN KEY (parameter_type)
REFERENCES parameter_data_type (id);
# Update the schema version number # Update the schema version number
UPDATE schema_version UPDATE schema_version
......
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