2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-02 15:05:16 +00:00

[#2430] PostgreSQL CB now supports class user-context

src/bin/admin/tests/pgsql_tests.sh.in
   Updated  pgsql_upgrade_11_0_to_12_0()

src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp4.cc
src/hooks/dhcp/pgsql_cb/pgsql_cb_dhcp6.cc
src/hooks/dhcp/pgsql_cb/pgsql_query_macros_dhcp.h
    added user_context to necessary statements, bindings

src/share/database/scripts/pgsql/dhcpdb_create.pgsql
src/share/database/scripts/pgsql/upgrade_011_to_012.sh.in
    added user_context column to class tables
This commit is contained in:
Thomas Markwalder
2022-06-08 09:34:10 -04:00
parent 088b23a3e3
commit fd89a7983a
6 changed files with 99 additions and 49 deletions

View File

@@ -481,6 +481,18 @@ pgsql_upgrade_11_0_to_12_0() {
count=$(echo "${OUTPUT}" | grep -Eci 'UPDATE dhcp6_subnet SET shared_network_name = NULL') || true count=$(echo "${OUTPUT}" | grep -Eci 'UPDATE dhcp6_subnet SET shared_network_name = NULL') || true
assert_eq 1 "${count}" "function func_dhcp6_shared_network_BDEL() is missing changed line. (expected count %d, returned %d)" assert_eq 1 "${count}" "function func_dhcp6_shared_network_BDEL() is missing changed line. (expected count %d, returned %d)"
# user_context should have been added to dhcp4_client_class
qry="select user_context from dhcp4_client_class limit 1;"
run_command \
pgsql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
# user_context should have been added to dhcp6_client_class
qry="select user_context from dhcp6_client_class limit 1;"
run_command \
pgsql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
} }
pgsql_upgrade_test() { pgsql_upgrade_test() {

View File

@@ -2258,12 +2258,20 @@ public:
// modification_ts // modification_ts
last_client_class->setModificationTime(worker.getTimestamp(12)); last_client_class->setModificationTime(worker.getTimestamp(12));
// user_context at 13.
if (!worker.isColumnNull(13)) {
ElementPtr user_context = worker.getJSON(13);
if (user_context) {
last_client_class->setContext(user_context);
}
}
class_list.push_back(last_client_class); class_list.push_back(last_client_class);
} }
// Check for new server tags at 35. // Check for new server tags at 36.
if (!worker.isColumnNull(35)) { if (!worker.isColumnNull(36)) {
std::string new_tag = worker.getString(35); std::string new_tag = worker.getString(36);
if (last_tag != new_tag) { if (last_tag != new_tag) {
if (!new_tag.empty() && !last_client_class->hasServerTag(ServerTag(new_tag))) { if (!new_tag.empty() && !last_client_class->hasServerTag(ServerTag(new_tag))) {
last_client_class->setServerTag(new_tag); last_client_class->setServerTag(new_tag);
@@ -2273,23 +2281,23 @@ public:
} }
} }
// Parse client class specific option definition from 13 to 22. // Parse client class specific option definition from 14 to 23.
if (!worker.isColumnNull(13) && if (!worker.isColumnNull(14) &&
(last_option_def_id < worker.getBigInt(13))) { (last_option_def_id < worker.getBigInt(14))) {
last_option_def_id = worker.getBigInt(13); last_option_def_id = worker.getBigInt(14);
auto def = processOptionDefRow(worker, 13); auto def = processOptionDefRow(worker, 14);
if (def) { if (def) {
last_client_class->getCfgOptionDef()->add(def); last_client_class->getCfgOptionDef()->add(def);
} }
} }
// Parse client class specific option from 23 to 34. // Parse client class specific option from 24 to 35.
if (!worker.isColumnNull(23) && if (!worker.isColumnNull(24) &&
(last_option_id < worker.getBigInt(23))) { (last_option_id < worker.getBigInt(24))) {
last_option_id = worker.getBigInt(23); last_option_id = worker.getBigInt(24);
OptionDescriptorPtr desc = processOptionRow(Option::V4, worker, 23); OptionDescriptorPtr desc = processOptionRow(Option::V4, worker, 24);
if (desc) { if (desc) {
last_client_class->getCfgOption()->add(*desc, desc->space_name_); last_client_class->getCfgOption()->add(*desc, desc->space_name_);
} }
@@ -2418,6 +2426,7 @@ public:
} }
in_bindings.addTimestamp(client_class->getModificationTime()); in_bindings.addTimestamp(client_class->getModificationTime());
in_bindings.add(client_class->getContext());
PgSqlTransaction transaction(conn_); PgSqlTransaction transaction(conn_);
@@ -3559,7 +3568,7 @@ TaggedStatementArray tagged_statements = { {
// Insert client class. // Insert client class.
{ {
// PgSqlConfigBackendDHCPv4Impl::INSERT_CLIENT_CLASS4, // PgSqlConfigBackendDHCPv4Impl::INSERT_CLIENT_CLASS4,
12, 13,
{ {
OID_VARCHAR, // 1 name OID_VARCHAR, // 1 name
OID_TEXT, // 2 test OID_TEXT, // 2 test
@@ -3572,7 +3581,8 @@ TaggedStatementArray tagged_statements = { {
OID_INT8, // 9 max_valid_lifetime OID_INT8, // 9 max_valid_lifetime
OID_BOOL, // 10 depend_on_known_directly OID_BOOL, // 10 depend_on_known_directly
OID_VARCHAR, // 11 follow_class_name OID_VARCHAR, // 11 follow_class_name
OID_TIMESTAMP // 12 modification_ts OID_TIMESTAMP, // 12 modification_ts
OID_TEXT // 13 user_context cast as JSON
}, },
"INSERT_CLIENT_CLASS4", "INSERT_CLIENT_CLASS4",
"INSERT INTO dhcp4_client_class(" "INSERT INTO dhcp4_client_class("
@@ -3587,9 +3597,10 @@ TaggedStatementArray tagged_statements = { {
" max_valid_lifetime," " max_valid_lifetime,"
" depend_on_known_directly," " depend_on_known_directly,"
" follow_class_name," " follow_class_name,"
" modification_ts" " modification_ts, "
" user_context "
") VALUES (" ") VALUES ("
"$1, $2, cast($3 as inet), $4, $5, $6, $7, $8, $9, $10, $11, $12" "$1, $2, cast($3 as inet), $4, $5, $6, $7, $8, $9, $10, $11, $12, cast($13 as JSON)"
")" ")"
}, },
@@ -3980,7 +3991,7 @@ TaggedStatementArray tagged_statements = { {
// Update existing client class with specifying its position. // Update existing client class with specifying its position.
{ {
// PgSqlConfigBackendDHCPv4Impl::UPDATE_CLIENT_CLASS4, // PgSqlConfigBackendDHCPv4Impl::UPDATE_CLIENT_CLASS4,
13, 14,
{ {
OID_VARCHAR, // 1 name OID_VARCHAR, // 1 name
OID_TEXT, // 2 test OID_TEXT, // 2 test
@@ -3994,7 +4005,8 @@ TaggedStatementArray tagged_statements = { {
OID_BOOL, // 10 depend_on_known_directly OID_BOOL, // 10 depend_on_known_directly
OID_VARCHAR, // 11 follow_class_name OID_VARCHAR, // 11 follow_class_name
OID_TIMESTAMP, // 12 modification_ts OID_TIMESTAMP, // 12 modification_ts
OID_VARCHAR // 13 name (of class to update) OID_TEXT, // 13 user_context cast as JSON
OID_VARCHAR // 14 name (of class to update)
}, },
"UPDATE_CLIENT_CLASS4", "UPDATE_CLIENT_CLASS4",
PGSQL_UPDATE_CLIENT_CLASS4("follow_class_name = $11,") PGSQL_UPDATE_CLIENT_CLASS4("follow_class_name = $11,")
@@ -4003,7 +4015,7 @@ TaggedStatementArray tagged_statements = { {
// Update existing client class without specifying its position. // Update existing client class without specifying its position.
{ {
// PgSqlConfigBackendDHCPv4Impl::UPDATE_CLIENT_CLASS4_SAME_POSITION, // PgSqlConfigBackendDHCPv4Impl::UPDATE_CLIENT_CLASS4_SAME_POSITION,
13, 14,
{ {
OID_VARCHAR, // 1 name OID_VARCHAR, // 1 name
OID_TEXT, // 2 test OID_TEXT, // 2 test
@@ -4017,7 +4029,8 @@ TaggedStatementArray tagged_statements = { {
OID_BOOL, // 10 depend_on_known_directly OID_BOOL, // 10 depend_on_known_directly
OID_VARCHAR, // 11 follow_class_name OID_VARCHAR, // 11 follow_class_name
OID_TIMESTAMP, // 12 modification_ts OID_TIMESTAMP, // 12 modification_ts
OID_VARCHAR // 13 name (of class to update) OID_TEXT, // 13 user_context cast as JSON
OID_VARCHAR // 14 name (of class to update)
}, },
"UPDATE_CLIENT_CLASS4_SAME_POSITION", "UPDATE_CLIENT_CLASS4_SAME_POSITION",
PGSQL_UPDATE_CLIENT_CLASS4("") PGSQL_UPDATE_CLIENT_CLASS4("")

View File

@@ -2579,18 +2579,26 @@ public:
// modification_ts // modification_ts
last_client_class->setModificationTime(worker.getTimestamp(9)); last_client_class->setModificationTime(worker.getTimestamp(9));
// class specific option definition from 10 to 19. // user_context at 10.
// class specific option from 20 to 31. if (!worker.isColumnNull(10)) {
ElementPtr user_context = worker.getJSON(10);
if (user_context) {
last_client_class->setContext(user_context);
}
}
// class specific option definition from 11 to 20.
// class specific option from 21 to 32.
// preferred lifetime: default, min, max // preferred lifetime: default, min, max
last_client_class->setPreferred(worker.getTriplet(33, 34, 35)); last_client_class->setPreferred(worker.getTriplet(34, 35, 36));
class_list.push_back(last_client_class); class_list.push_back(last_client_class);
} }
// Check for new server tags at 32. // Check for new server tags at 33.
if (!worker.isColumnNull(32)) { if (!worker.isColumnNull(33)) {
std::string new_tag = worker.getString(32); std::string new_tag = worker.getString(33);
if (last_tag != new_tag) { if (last_tag != new_tag) {
if (!new_tag.empty() && !last_client_class->hasServerTag(ServerTag(new_tag))) { if (!new_tag.empty() && !last_client_class->hasServerTag(ServerTag(new_tag))) {
last_client_class->setServerTag(new_tag); last_client_class->setServerTag(new_tag);
@@ -2600,23 +2608,23 @@ public:
} }
} }
// Parse client class specific option definition from 10 to 19. // Parse client class specific option definition from 11 to 20.
if (!worker.isColumnNull(10) && if (!worker.isColumnNull(11) &&
(last_option_def_id < worker.getBigInt(10))) { (last_option_def_id < worker.getBigInt(11))) {
last_option_def_id = worker.getBigInt(10); last_option_def_id = worker.getBigInt(11);
auto def = processOptionDefRow(worker, 10); auto def = processOptionDefRow(worker, 11);
if (def) { if (def) {
last_client_class->getCfgOptionDef()->add(def); last_client_class->getCfgOptionDef()->add(def);
} }
} }
// Parse client class specific option from 20 to 31. // Parse client class specific option from 21 to 32.
if (!worker.isColumnNull(20) && if (!worker.isColumnNull(21) &&
(last_option_id < worker.getBigInt(20))) { (last_option_id < worker.getBigInt(21))) {
last_option_id = worker.getBigInt(20); last_option_id = worker.getBigInt(21);
OptionDescriptorPtr desc = processOptionRow(Option::V6, worker, 20); OptionDescriptorPtr desc = processOptionRow(Option::V6, worker, 21);
if (desc) { if (desc) {
last_client_class->getCfgOption()->add(*desc, desc->space_name_); last_client_class->getCfgOption()->add(*desc, desc->space_name_);
} }
@@ -2745,6 +2753,7 @@ public:
in_bindings.add(client_class->getPreferred().getMin()); in_bindings.add(client_class->getPreferred().getMin());
in_bindings.add(client_class->getPreferred().getMax()); in_bindings.add(client_class->getPreferred().getMax());
in_bindings.addTimestamp(client_class->getModificationTime()); in_bindings.addTimestamp(client_class->getModificationTime());
in_bindings.add(client_class->getContext());
PgSqlTransaction transaction(conn_); PgSqlTransaction transaction(conn_);
@@ -3980,7 +3989,7 @@ TaggedStatementArray tagged_statements = { {
// Insert client class. // Insert client class.
{ {
// PgSqlConfigBackendDHCPv6Impl::INSERT_CLIENT_CLASS6, // PgSqlConfigBackendDHCPv6Impl::INSERT_CLIENT_CLASS6,
12, 13,
{ {
OID_VARCHAR, // 1 name OID_VARCHAR, // 1 name
OID_TEXT, // 2 test OID_TEXT, // 2 test
@@ -3993,7 +4002,8 @@ TaggedStatementArray tagged_statements = { {
OID_INT8, // 9 preferred_lifetime OID_INT8, // 9 preferred_lifetime
OID_INT8, // 10 min_preferred_lifetime OID_INT8, // 10 min_preferred_lifetime
OID_INT8, // 11 max_preferred_lifetime OID_INT8, // 11 max_preferred_lifetime
OID_TIMESTAMP // 12 modification_ts OID_TIMESTAMP, // 12 modification_ts
OID_TEXT // 13 user_context cast as JSON
}, },
"INSERT_CLIENT_CLASS6", "INSERT_CLIENT_CLASS6",
"INSERT INTO dhcp6_client_class(" "INSERT INTO dhcp6_client_class("
@@ -4008,9 +4018,10 @@ TaggedStatementArray tagged_statements = { {
" preferred_lifetime," " preferred_lifetime,"
" min_preferred_lifetime," " min_preferred_lifetime,"
" max_preferred_lifetime," " max_preferred_lifetime,"
" modification_ts" " modification_ts,"
" user_context "
") VALUES (" ") VALUES ("
" $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12" " $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, cast($13 as JSON)"
")" ")"
}, },
@@ -4423,7 +4434,7 @@ TaggedStatementArray tagged_statements = { {
// Update existing client class with specifying its position. // Update existing client class with specifying its position.
{ {
// PgSqlConfigBackendDHCPv6Impl::UPDATE_CLIENT_CLASS6, // PgSqlConfigBackendDHCPv6Impl::UPDATE_CLIENT_CLASS6,
13, 14,
{ {
OID_VARCHAR, // 1 name OID_VARCHAR, // 1 name
OID_TEXT, // 2 test OID_TEXT, // 2 test
@@ -4437,7 +4448,8 @@ TaggedStatementArray tagged_statements = { {
OID_INT8, // 10 min_preferred_lifetime OID_INT8, // 10 min_preferred_lifetime
OID_INT8, // 11 max_preferred_lifetime OID_INT8, // 11 max_preferred_lifetime
OID_TIMESTAMP, // 12 modification_ts OID_TIMESTAMP, // 12 modification_ts
OID_VARCHAR // 13 name (of class to update) OID_TEXT, // 13 user_conetx
OID_VARCHAR // 14 name (of class to update)
}, },
"UPDATE_CLIENT_CLASS6", "UPDATE_CLIENT_CLASS6",
PGSQL_UPDATE_CLIENT_CLASS6("follow_class_name = $8,") PGSQL_UPDATE_CLIENT_CLASS6("follow_class_name = $8,")
@@ -4446,7 +4458,7 @@ TaggedStatementArray tagged_statements = { {
// Update existing client class without specifying its position. // Update existing client class without specifying its position.
{ {
// PgSqlConfigBackendDHCPv6Impl::UPDATE_CLIENT_CLASS6_SAME_POSITION, // PgSqlConfigBackendDHCPv6Impl::UPDATE_CLIENT_CLASS6_SAME_POSITION,
13, 14,
{ {
OID_VARCHAR, // 1 name OID_VARCHAR, // 1 name
OID_TEXT, // 2 test OID_TEXT, // 2 test
@@ -4460,7 +4472,8 @@ TaggedStatementArray tagged_statements = { {
OID_INT8, // 10 min_preferred_lifetime OID_INT8, // 10 min_preferred_lifetime
OID_INT8, // 11 max_preferred_lifetime OID_INT8, // 11 max_preferred_lifetime
OID_TIMESTAMP, // 12 modification_ts OID_TIMESTAMP, // 12 modification_ts
OID_VARCHAR // 13 name (of class to update) OID_TEXT, // 13 user_conetx
OID_VARCHAR // 14 name (of class to update)
}, },
"UPDATE_CLIENT_CLASS6_SAME_POSITION", "UPDATE_CLIENT_CLASS6_SAME_POSITION",
PGSQL_UPDATE_CLIENT_CLASS6("") PGSQL_UPDATE_CLIENT_CLASS6("")

View File

@@ -671,6 +671,7 @@ namespace {
" c.depend_on_known_directly," \ " c.depend_on_known_directly," \
" o.depend_on_known_indirectly, " \ " o.depend_on_known_indirectly, " \
" gmt_epoch(c.modification_ts) as modification_ts, " \ " gmt_epoch(c.modification_ts) as modification_ts, " \
" c.user_context," \
" d.id," \ " d.id," \
" d.code," \ " d.code," \
" d.name," \ " d.name," \
@@ -733,6 +734,7 @@ namespace {
" c.depend_on_known_directly," \ " c.depend_on_known_directly," \
" o.depend_on_known_indirectly, " \ " o.depend_on_known_indirectly, " \
" gmt_epoch(c.modification_ts) as modification_ts, " \ " gmt_epoch(c.modification_ts) as modification_ts, " \
" c.user_context, " \
" d.id," \ " d.id," \
" d.code," \ " d.code," \
" d.name," \ " d.name," \
@@ -1086,8 +1088,9 @@ namespace {
" max_valid_lifetime = $9," \ " max_valid_lifetime = $9," \
" depend_on_known_directly = $10," \ " depend_on_known_directly = $10," \
follow_class_name_set \ follow_class_name_set \
" modification_ts = $12 " \ " modification_ts = $12, " \
"WHERE name = $13" " user_context = cast($13 as json)" \
"WHERE name = $14"
#endif #endif
#ifndef PGSQL_UPDATE_CLIENT_CLASS6 #ifndef PGSQL_UPDATE_CLIENT_CLASS6
@@ -1104,8 +1107,9 @@ namespace {
" preferred_lifetime = $9, " \ " preferred_lifetime = $9, " \
" min_preferred_lifetime = $10, " \ " min_preferred_lifetime = $10, " \
" max_preferred_lifetime = $11, " \ " max_preferred_lifetime = $11, " \
" modification_ts = $12 " \ " modification_ts = $12, " \
"WHERE name = $13" " user_context = cast($13 as json) " \
"WHERE name = $14"
#endif #endif
#ifndef PGSQL_UPDATE_SERVER #ifndef PGSQL_UPDATE_SERVER

View File

@@ -4969,6 +4969,10 @@ END;
$dhcp6_shared_network_BDEL$ $dhcp6_shared_network_BDEL$
LANGUAGE plpgsql; LANGUAGE plpgsql;
-- Add user_context column to Client class tables.
ALTER TABLE dhcp4_client_class ADD COLUMN user_context JSON DEFAULT NULL;
ALTER TABLE dhcp6_client_class ADD COLUMN user_context JSON DEFAULT NULL;
-- Update the schema version number. -- Update the schema version number.
UPDATE schema_version UPDATE schema_version
SET version = '12', minor = '0'; SET version = '12', minor = '0';

View File

@@ -90,6 +90,10 @@ END;
\$dhcp6_shared_network_BDEL\$ \$dhcp6_shared_network_BDEL\$
LANGUAGE plpgsql; LANGUAGE plpgsql;
-- Add user_context column to Client class tables.
ALTER TABLE dhcp4_client_class ADD COLUMN user_context JSON DEFAULT NULL;
ALTER TABLE dhcp6_client_class ADD COLUMN user_context JSON DEFAULT NULL;
-- Update the schema version number. -- Update the schema version number.
UPDATE schema_version UPDATE schema_version
SET version = '12', minor = '0'; SET version = '12', minor = '0';