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

[642-update-mysql-cb-with-calls-to-set-delete-and-retrieve-servers] Changed new schema to 8.1 (vs 9.0) and addressed trivial comments

This commit is contained in:
Francis Dupont
2019-06-25 16:20:54 +02:00
committed by Marcin Siodelski
parent a621db7001
commit 9346fb8859
9 changed files with 100 additions and 130 deletions

View File

@@ -267,7 +267,7 @@ MySqlConfigBackendImpl::getGlobalParameters(const int index,
std::string name = out_bindings[1]->getString(); std::string name = out_bindings[1]->getString();
if (!name.empty()) { if (!name.empty()) {
last_param = StampedValue::create(out_bindings[1]->getString(), last_param = StampedValue::create(name,
out_bindings[2]->getString(), out_bindings[2]->getString(),
static_cast<Element::types> static_cast<Element::types>
(out_bindings[3]->getInteger<uint8_t>())); (out_bindings[3]->getInteger<uint8_t>()));
@@ -287,7 +287,7 @@ MySqlConfigBackendImpl::getGlobalParameters(const int index,
// parameter already exists and belongs to 'all'. // parameter already exists and belongs to 'all'.
auto& index = local_parameters.get<StampedValueNameIndexTag>(); auto& index = local_parameters.get<StampedValueNameIndexTag>();
auto existing = index.find(name); auto existing = index.find(name);
if (existing != local_parameters.end()) { if (existing != index.end()) {
// This parameter was already fetched. Let's check if we should // This parameter was already fetched. Let's check if we should
// replace it or not. // replace it or not.
if (!last_param_server_tag.amAll() && (*existing)->hasAllServerTag()) { if (!last_param_server_tag.amAll() && (*existing)->hasAllServerTag()) {
@@ -302,7 +302,7 @@ MySqlConfigBackendImpl::getGlobalParameters(const int index,
// If there is no such parameter yet or the existing parameter // If there is no such parameter yet or the existing parameter
// belongs to a different server and the inserted parameter is // belongs to a different server and the inserted parameter is
// not for all servers. // not for all servers.
if ((existing == local_parameters.end()) || if ((existing == index.end()) ||
(!(*existing)->hasServerTag(last_param_server_tag) && (!(*existing)->hasServerTag(last_param_server_tag) &&
!last_param_server_tag.amAll())) { !last_param_server_tag.amAll())) {
local_parameters.insert(last_param); local_parameters.insert(last_param);
@@ -930,14 +930,14 @@ MySqlConfigBackendImpl::getServers(const int index,
} }
void void
MySqlConfigBackendImpl::createUpdateServer(const int create_audit_revision_index, MySqlConfigBackendImpl::createUpdateServer(const int& create_audit_revision,
const int create_index, const int& create_index,
const int update_index, const int& update_index,
const ServerPtr& server) { const ServerPtr& server) {
// Create scoped audit revision. As long as this instance exists // Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls. // no new audit revisions are created in any subsequent calls.
ScopedAuditRevision audit_revision(this, ScopedAuditRevision audit_revision(this,
create_audit_revision_index, create_audit_revision,
ServerSelector::ALL(), ServerSelector::ALL(),
"server set", "server set",
true); true);
@@ -962,8 +962,8 @@ MySqlConfigBackendImpl::createUpdateServer(const int create_audit_revision_index
} }
uint64_t uint64_t
MySqlConfigBackendImpl::deleteServer(const int create_audit_revision_index, MySqlConfigBackendImpl::deleteServer(const int& create_audit_revision,
const int delete_index, const int& delete_index,
const std::string& server_tag) { const std::string& server_tag) {
MySqlTransaction transaction(conn_); MySqlTransaction transaction(conn_);
@@ -971,7 +971,7 @@ MySqlConfigBackendImpl::deleteServer(const int create_audit_revision_index,
// Create scoped audit revision. As long as this instance exists // Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls. // no new audit revisions are created in any subsequent calls.
ScopedAuditRevision ScopedAuditRevision
audit_revision(this, create_audit_revision_index, audit_revision(this, create_audit_revision,
ServerSelector::ALL(), "deleting a server", false); ServerSelector::ALL(), "deleting a server", false);
// Specify which server should be deleted. // Specify which server should be deleted.
@@ -987,16 +987,16 @@ MySqlConfigBackendImpl::deleteServer(const int create_audit_revision_index,
} }
uint64_t uint64_t
MySqlConfigBackendImpl::deleteAllServers(const int create_audit_revision_index, MySqlConfigBackendImpl::deleteAllServers(const int& create_audit_revision,
const int delete_index) { const int& delete_index) {
MySqlTransaction transaction(conn_); MySqlTransaction transaction(conn_);
// Create scoped audit revision. As long as this instance exists // Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls. // no new audit revisions are created in any subsequent calls.
ScopedAuditRevision ScopedAuditRevision
audit_revision(this, create_audit_revision_index, audit_revision(this, create_audit_revision,
ServerSelector::ALL(), "deleting a server", false); ServerSelector::ALL(), "deleting all servers", false);
MySqlBindingCollection in_bindings; MySqlBindingCollection in_bindings;

View File

@@ -643,9 +643,9 @@ public:
/// @param create_index Index of the INSERT query to be used. /// @param create_index Index of the INSERT query to be used.
/// @param update_index Index of the UPDATE query to be used. /// @param update_index Index of the UPDATE query to be used.
/// @param server Pointer to the server to be inserted or updated. /// @param server Pointer to the server to be inserted or updated.
void createUpdateServer(const int create_audit_revision_index, void createUpdateServer(const int& create_audit_revision,
const int create_index, const int& create_index,
const int update_index, const int& update_index,
const db::ServerPtr& server); const db::ServerPtr& server);
/// @brief Attempts to delete a server having a given tag. /// @brief Attempts to delete a server having a given tag.
@@ -655,7 +655,7 @@ public:
/// @param create_index Index of the DELETE query to be executed. /// @param create_index Index of the DELETE query to be executed.
/// @param server_tag Tag of the server to be deleted. /// @param server_tag Tag of the server to be deleted.
/// @return Number of deleted servers. /// @return Number of deleted servers.
uint64_t deleteServer(const int create_audit_revision_index, const int index, uint64_t deleteServer(const int& create_audit_revision, const int& index,
const std::string& server_tag); const std::string& server_tag);
/// @brief Attempts to delete all servers. /// @brief Attempts to delete all servers.
@@ -667,8 +667,8 @@ public:
/// revision. /// revision.
/// @param server_tag Tag of the server to be deleted. /// @param server_tag Tag of the server to be deleted.
/// @return Number of deleted servers. /// @return Number of deleted servers.
uint64_t deleteAllServers(const int create_audit_revision_index, uint64_t deleteAllServers(const int& create_audit_revision,
const int index); const int& index);
/// @brief Returns backend type in the textual format. /// @brief Returns backend type in the textual format.
/// ///

View File

@@ -1,4 +1,4 @@
// File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on Mon Jun 17 2019 14:28 // File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on Tue Jun 25 2019 16:12
#include <cstddef> #include <cstddef>
#include <log/message_types.h> #include <log/message_types.h>
@@ -196,7 +196,7 @@ const char* values[] = {
"MYSQL_CB_CREATE_UPDATE_SHARED_NETWORK_OPTION6", "create or update shared network: %1 option", "MYSQL_CB_CREATE_UPDATE_SHARED_NETWORK_OPTION6", "create or update shared network: %1 option",
"MYSQL_CB_CREATE_UPDATE_SUBNET4", "create or update subnet: %1", "MYSQL_CB_CREATE_UPDATE_SUBNET4", "create or update subnet: %1",
"MYSQL_CB_CREATE_UPDATE_SUBNET6", "create or update subnet: %1", "MYSQL_CB_CREATE_UPDATE_SUBNET6", "create or update subnet: %1",
"MYSQL_CB_DEINIT_OK", "unloading MYSQAL CB hooks library successful", "MYSQL_CB_DEINIT_OK", "unloading MYSQL CB hooks library successful",
"MYSQL_CB_DELETE_ALL_GLOBAL_PARAMETERS4", "delete all global parameters", "MYSQL_CB_DELETE_ALL_GLOBAL_PARAMETERS4", "delete all global parameters",
"MYSQL_CB_DELETE_ALL_GLOBAL_PARAMETERS4_RESULT", "deleted: %1 entries", "MYSQL_CB_DELETE_ALL_GLOBAL_PARAMETERS4_RESULT", "deleted: %1 entries",
"MYSQL_CB_DELETE_ALL_GLOBAL_PARAMETERS6", "delete all global parameters", "MYSQL_CB_DELETE_ALL_GLOBAL_PARAMETERS6", "delete all global parameters",

View File

@@ -1,4 +1,4 @@
// File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on Mon Jun 17 2019 14:28 // File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on Tue Jun 25 2019 16:12
#ifndef MYSQL_CB_MESSAGES_H #ifndef MYSQL_CB_MESSAGES_H
#define MYSQL_CB_MESSAGES_H #define MYSQL_CB_MESSAGES_H

View File

@@ -35,6 +35,14 @@ Debug message issued when triggered an action to create or update option definit
% MYSQL_CB_CREATE_UPDATE_OPTION_DEF6 create or update option definition: %1 code: %2 % MYSQL_CB_CREATE_UPDATE_OPTION_DEF6 create or update option definition: %1 code: %2
Debug message issued when triggered an action to create or update option definition Debug message issued when triggered an action to create or update option definition
% MYSQL_CB_CREATE_UPDATE_SERVER4 create or update server: %1
Debug message issued when triggered an action to create or update a DHCPv4
server information.
% MYSQL_CB_CREATE_UPDATE_SERVER6 create or update server: %1
Debug message issued when triggered an action to create or update a DHCPv6
server information.
% MYSQL_CB_CREATE_UPDATE_SHARED_NETWORK4 create or update shared network: %1 % MYSQL_CB_CREATE_UPDATE_SHARED_NETWORK4 create or update shared network: %1
Debug message issued when triggered an action to create or update shared network Debug message issued when triggered an action to create or update shared network
@@ -53,15 +61,7 @@ Debug message issued when triggered an action to create or update subnet
% MYSQL_CB_CREATE_UPDATE_SUBNET6 create or update subnet: %1 % MYSQL_CB_CREATE_UPDATE_SUBNET6 create or update subnet: %1
Debug message issued when triggered an action to create or update subnet Debug message issued when triggered an action to create or update subnet
% MYSQL_CB_CREATE_UPDATE_SERVER4 create or update server: %1 % MYSQL_CB_DEINIT_OK unloading MYSQL CB hooks library successful
Debug message issued when triggered an action to create or update a DHCPv4
server information.
% MYSQL_CB_CREATE_UPDATE_SERVER6 create or update server: %1
Debug message issued when triggered an action to create or update a DHCPv6
server information.
% MYSQL_CB_DEINIT_OK unloading MYSQAL CB hooks library successful
This informational message indicates that the MySQL Configuration Backend hooks This informational message indicates that the MySQL Configuration Backend hooks
library has been unloaded successfully. library has been unloaded successfully.
@@ -89,18 +89,6 @@ Debug message issued when triggered an action to delete all option definitions
% MYSQL_CB_DELETE_ALL_OPTION_DEFS6_RESULT deleted: %1 entries % MYSQL_CB_DELETE_ALL_OPTION_DEFS6_RESULT deleted: %1 entries
Debug message indicating the result of an action to delete all option definitions Debug message indicating the result of an action to delete all option definitions
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS4 delete all shared networks
Debug message issued when triggered an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS4_RESULT deleted: %1 entries
Debug message indicating the result of an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS6 delete all shared networks
Debug message issued when triggered an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS6_RESULT deleted: %1 entries
Debug message indicating the result of an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SERVERS4 delete all DHCPv4 servers % MYSQL_CB_DELETE_ALL_SERVERS4 delete all DHCPv4 servers
Debug message issued when triggered an action to delete all servers. Debug message issued when triggered an action to delete all servers.
@@ -113,6 +101,18 @@ Debug message issued when triggered an action to delete all servers.
% MYSQL_CB_DELETE_ALL_SERVERS6_RESULT deleted: %1 entries % MYSQL_CB_DELETE_ALL_SERVERS6_RESULT deleted: %1 entries
Debug message indicating the result of an action to delete all servers. Debug message indicating the result of an action to delete all servers.
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS4 delete all shared networks
Debug message issued when triggered an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS4_RESULT deleted: %1 entries
Debug message indicating the result of an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS6 delete all shared networks
Debug message issued when triggered an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS6_RESULT deleted: %1 entries
Debug message indicating the result of an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SUBNETS4 delete all subnets % MYSQL_CB_DELETE_ALL_SUBNETS4 delete all subnets
Debug message issued when triggered an action to delete all subnets Debug message issued when triggered an action to delete all subnets

View File

@@ -492,7 +492,7 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteServer) {
"server set"); "server set");
} }
// Verify that the server has been updated. // Verify that the server has been updated.
EXPECT_NO_THROW(returned_server = cbptr_->getServer4(ServerTag("server1"))); EXPECT_NO_THROW(returned_server = cbptr_->getServer4(ServerTag("server1")));
ASSERT_TRUE(returned_server); ASSERT_TRUE(returned_server);
EXPECT_EQ("server1", returned_server->getServerTag().get()); EXPECT_EQ("server1", returned_server->getServerTag().get());

View File

@@ -533,7 +533,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeleteServer) {
"server set"); "server set");
} }
// Verify that the server has been updated. // Verify that the server has been updated.
EXPECT_NO_THROW(returned_server = cbptr_->getServer6(ServerTag("server1"))); EXPECT_NO_THROW(returned_server = cbptr_->getServer6(ServerTag("server1")));
ASSERT_TRUE(returned_server); ASSERT_TRUE(returned_server);
EXPECT_EQ("server1", returned_server->getServerTag().get()); EXPECT_EQ("server1", returned_server->getServerTag().get());

View File

@@ -38,6 +38,60 @@ ALTER TABLE dhcp6_subnet
ADD COLUMN min_valid_lifetime INT(10) DEFAULT NULL, ADD COLUMN min_valid_lifetime INT(10) DEFAULT NULL,
ADD COLUMN max_valid_lifetime INT(10) DEFAULT NULL; ADD COLUMN max_valid_lifetime INT(10) DEFAULT NULL;
# Create dhcp4_server insert trigger
DELIMITER $$
CREATE TRIGGER dhcp4_server_AINS AFTER INSERT ON dhcp4_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP4('dhcp4_server', NEW.id, "create");
END $$
DELIMITER ;
# Create dhcp4_server update trigger
DELIMITER $$
CREATE TRIGGER dhcp4_server_AUPD AFTER UPDATE ON dhcp4_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP4('dhcp4_server', NEW.id, "update");
END $$
DELIMITER ;
# Create dhcp4_server delete trigger
DELIMITER $$
CREATE TRIGGER dhcp4_server_ADEL AFTER DELETE ON dhcp4_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP4('dhcp4_server', OLD.id, "delete");
END $$
DELIMITER ;
# Create dhcp6_server insert trigger
DELIMITER $$
CREATE TRIGGER dhcp6_server_AINS AFTER INSERT ON dhcp6_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP6('dhcp6_server', NEW.id, "create");
END $$
DELIMITER ;
# Create dhcp6_server update trigger
DELIMITER $$
CREATE TRIGGER dhcp6_server_AUPD AFTER UPDATE ON dhcp6_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP6('dhcp6_server', NEW.id, "update");
END $$
DELIMITER ;
# Create dhcp6_server delete trigger
DELIMITER $$
CREATE TRIGGER dhcp6_server_ADEL AFTER DELETE ON dhcp6_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP6('dhcp6_server', OLD.id, "delete");
END $$
DELIMITER ;
# Update the schema version number # Update the schema version number
UPDATE schema_version UPDATE schema_version
SET version = '8', minor = '1'; SET version = '8', minor = '1';

View File

@@ -1,84 +0,0 @@
#!/bin/sh
# Include utilities. Use installed version if available and
# use build version if it isn't.
if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
. @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
else
. @abs_top_builddir@/src/bin/admin/admin-utils.sh
fi
VERSION=`mysql_version "$@"`
if [ "$VERSION" != "8.0" ]; then
printf "This script upgrades 8.0 to 9.0. Reported version is $VERSION. Skipping upgrade.\n"
exit 0
fi
mysql "$@" <<EOF
# Create dhcp4_server insert trigger
DELIMITER $$
CREATE TRIGGER dhcp4_server_AINS AFTER INSERT ON dhcp4_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP4('dhcp4_server', NEW.id, "create");
END $$
DELIMITER ;
# Create dhcp4_server update trigger
DELIMITER $$
CREATE TRIGGER dhcp4_server_AUPD AFTER UPDATE ON dhcp4_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP4('dhcp4_server', NEW.id, "update");
END $$
DELIMITER ;
# Create dhcp4_server delete trigger
DELIMITER $$
CREATE TRIGGER dhcp4_server_ADEL AFTER DELETE ON dhcp4_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP4('dhcp4_server', OLD.id, "delete");
END $$
DELIMITER ;
# Create dhcp6_server insert trigger
DELIMITER $$
CREATE TRIGGER dhcp6_server_AINS AFTER INSERT ON dhcp6_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP6('dhcp6_server', NEW.id, "create");
END $$
DELIMITER ;
# Create dhcp6_server update trigger
DELIMITER $$
CREATE TRIGGER dhcp6_server_AUPD AFTER UPDATE ON dhcp6_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP6('dhcp6_server', NEW.id, "update");
END $$
DELIMITER ;
# Create dhcp6_server delete trigger
DELIMITER $$
CREATE TRIGGER dhcp6_server_ADEL AFTER DELETE ON dhcp6_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP6('dhcp6_server', OLD.id, "delete");
END $$
DELIMITER ;
# Update the schema version number
UPDATE schema_version
SET version = '9', minor = '0';
# This line concludes database upgrade to version 9.0.
EOF
RESULT=$?
exit $?