From: Marcin Siodelski Date: Fri, 25 Jan 2019 12:48:54 +0000 (+0100) Subject: [#396,!205] Added MySQL upgrade script from 7.0 to 8.0. X-Git-Tag: 429-Updated-StampedValue-to-support-reals_base~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39c84ebcceb3593c85c06a4697d4a658f9cc0de3;p=thirdparty%2Fkea.git [#396,!205] Added MySQL upgrade script from 7.0 to 8.0. --- diff --git a/configure.ac b/configure.ac index 15724c481e..ee429e73b2 100644 --- a/configure.ac +++ b/configure.ac @@ -1663,6 +1663,7 @@ AC_CONFIG_FILES([Makefile src/share/database/scripts/mysql/upgrade_5.1_to_5.2.sh src/share/database/scripts/mysql/upgrade_5.2_to_6.0.sh src/share/database/scripts/mysql/upgrade_6.0_to_7.0.sh + src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh src/share/database/scripts/pgsql/Makefile src/share/database/scripts/pgsql/upgrade_1.0_to_2.0.sh src/share/database/scripts/pgsql/upgrade_2.0_to_3.0.sh diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in index c8afd20939..549b5cdcc4 100644 --- a/src/bin/admin/tests/mysql_tests.sh.in +++ b/src/bin/admin/tests/mysql_tests.sh.in @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC") +# Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC") # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this @@ -487,7 +487,7 @@ EOF run_statement "dhcp4_server" "$qry" 1 # table: dhcp4_audit - qry="select id, object_type, object_id, modification_type, modification_ts, log_message from dhcp4_audit" + qry="select id, object_type, object_id, modification_type from dhcp4_audit" run_statement "dhcp4_audit" "$qry" # table: dhcp4_global_parameter @@ -543,7 +543,7 @@ EOF run_statement "dhcp6_server" "$qry" 1 # table: dhcp6_audit - qry="select id, object_type, object_id, modification_type, modification_ts, log_message from dhcp6_audit" + qry="select id, object_type, object_id, modification_type from dhcp6_audit" run_statement "dhcp6_audit" "$qry" # table: dhcp6_global_parameter @@ -594,9 +594,57 @@ EOF qry="select option_id, server_id, modification_ts from dhcp6_options_server" run_statement "dhcp6_options_server" "$qry" - # Verify upgraded schema reports version 7.0 + # Schema upgrade from 7.0 to 8.0 + + # Test that createAuditRevisionDHCP4 exists and creates entry in + # the dhcp4_audit_revision table. + qry="CALL createAuditRevisionDHCP4('all', 'some log message', 0)" + run_statement "createAuditRevisionDHCP4" "$qry" + + qry="SELECT COUNT(*) from dhcp4_audit_revision" + run_statement "dhcp4_audit_revision count" "$qry" 1 + + qry="SELECT id, modification_ts, server_id, log_message FROM dhcp4_audit_revision" + run_statement "dhcp4_audit_revision" "$qry" + + # Test that createAuditEntryDHCP4 exists and creates entry in + # the dhcp4_audit table. + qry="SET @audit_revision_id = (SELECT id FROM dhcp4_audit_revision LIMIT 1); CALL createAuditEntryDHCP4('dhcp4_subnet', 1, 'create')" + run_statement "createAuditRevisionDHCP4" "$qry" + + qry="SELECT COUNT(*) FROM dhcp4_audit" + run_statement "dhcp4_audit count" "$qry" 1 + + qry="SELECT id, object_type, object_id, modification_type, revision_id FROM dhcp4_audit" + run_statement "dhcp4_audit" "$qry" + + # Test that createOptionAuditDHCP4 exists can create an audit + # entry. + + # First set the cascade_transaction session variable to check that + # the procedure won't create the audit entry for the option when + # this flag is set. + qry="SET @audit_revision_id = (SELECT id FROM dhcp4_audit_revision LIMIT 1); SET @cascade_transaction = 1; CALL createOptionAuditDHCP4('create', 0, 1024, NULL, NULL, NULL, NULL)" + run_statement "createOptionAuditDHCP4 cascade update" "$qry" + + # The number of rows matching the audit entry should be 0. + qry="SELECT COUNT(*) FROM dhcp4_audit WHERE object_type = 'dhcp4_options' AND object_id = 1024"; + run_statement "createOptionAuditDHCP4 cascade update, entry not inserted" "$qry" 0; + + # This time set the cascade_update to 0 and expect that the + # audit entry will be created for the option. + qry="SET @audit_revision_id = (SELECT id FROM dhcp4_audit_revision LIMIT 1); SET @cascade_transaction = 0; CALL createOptionAuditDHCP4('create', 0, 1024, NULL, NULL, NULL, NULL)" + run_statement "createOptionAuditDHCP4 cascade update" "$qry" + + qry="SELECT COUNT(*) FROM dhcp4_audit WHERE object_type = 'dhcp4_options' AND object_id = 1024"; + run_statement "createOptionAuditDHCP4 cascade update, entry not inserted" "$qry" 1; + + # New triggers aren't tested here because the extensive tests are + # provided with the backend implementations. + + # 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) - assert_str_eq "7.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" # Let's wipe the whole database mysql_wipe diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index 79f2c0ddf6..903206d132 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -1819,14 +1819,12 @@ public: option_def->getCode(), option_def->getOptionSpaceName()); - // Create scoped audit revision. It initiates session variables in the - // database to be used for creating new audit revision. As long as this - // instance exists no new audit revisions are created as a result of - // any subsequent calls. - ScopedAuditRevision audit_revision(this, - MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, - "option definition set", - true); + // Create scoped audit revision. As long as this instance exists + // no new audit revisions are created in any subsequent calls. + ScopedAuditRevision + audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION, + "option definition set", + true); if (existing_definition) { // Need to add three more bindings for WHERE clause. diff --git a/src/share/database/scripts/mysql/.gitignore b/src/share/database/scripts/mysql/.gitignore index 9e4b36e5f4..0ce2c5d735 100644 --- a/src/share/database/scripts/mysql/.gitignore +++ b/src/share/database/scripts/mysql/.gitignore @@ -7,3 +7,4 @@ /upgrade_5.1_to_5.2.sh /upgrade_5.2_to_6.0.sh /upgrade_6.0_to_7.0.sh +/upgrade_7.0_to_8.0.sh diff --git a/src/share/database/scripts/mysql/Makefile.am b/src/share/database/scripts/mysql/Makefile.am index a3fdf1f2d0..fdf0f41e63 100644 --- a/src/share/database/scripts/mysql/Makefile.am +++ b/src/share/database/scripts/mysql/Makefile.am @@ -12,6 +12,7 @@ sqlscripts_DATA += upgrade_5.0_to_5.1.sh sqlscripts_DATA += upgrade_5.1_to_5.2.sh sqlscripts_DATA += upgrade_5.2_to_6.0.sh sqlscripts_DATA += upgrade_6.0_to_7.0.sh +sqlscripts_DATA += upgrade_7.0_to_8.0.sh DISTCLEANFILES = upgrade_1.0_to_2.0.sh DISTCLEANFILES += upgrade_2.0_to_3.0.sh @@ -22,5 +23,6 @@ DISTCLEANFILES += upgrade_5.0_to_5.1.sh DISTCLEANFILES += upgrade_5.1_to_5.2.sh DISTCLEANFILES += upgrade_5.2_to_6.0.sh DISTCLEANFILES += upgrade_6.0_to_7.0.sh +DISTCLEANFILES += upgrade_7.0_to_8.0.sh EXTRA_DIST = ${sqlscripts_DATA} diff --git a/src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in b/src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in new file mode 100644 index 0000000000..05dde9b6dc --- /dev/null +++ b/src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in @@ -0,0 +1,362 @@ +#!/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" != "7.0" ]; then + printf "This script upgrades 7.0 to 8.0. Reported version is $VERSION. Skipping upgrade.\n" + exit 0 +fi + +mysql "$@" <