From: Andrei Pavel Date: Thu, 4 May 2023 12:41:58 +0000 (+0300) Subject: [#2786] changes to are-scripts-in-sync.py CI script X-Git-Tag: Kea-2.3.8~163 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=50eee8ebac12baa1cbcbe7a78d2d87e68d265831;p=thirdparty%2Fkea.git [#2786] changes to are-scripts-in-sync.py CI script --- diff --git a/configure.ac b/configure.ac index 8accf2c796..641b54dd26 100644 --- a/configure.ac +++ b/configure.ac @@ -1698,6 +1698,8 @@ AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_015_to_016.sh], [chmod +x src/share/database/scripts/mysql/upgrade_015_to_016.sh]) AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_016_to_017.sh], [chmod +x src/share/database/scripts/mysql/upgrade_016_to_017.sh]) +AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_017_to_018.sh], + [chmod +x src/share/database/scripts/mysql/upgrade_017_to_018.sh]) AC_CONFIG_FILES([src/share/database/scripts/mysql/wipe_data.sh], [chmod +x src/share/database/scripts/mysql/wipe_data.sh]) AC_CONFIG_FILES([src/share/database/scripts/pgsql/Makefile]) @@ -1743,6 +1745,8 @@ AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_014_to_015.sh], [chmod +x src/share/database/scripts/pgsql/upgrade_014_to_015.sh]) AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_015_to_016.sh], [chmod +x src/share/database/scripts/pgsql/upgrade_015_to_016.sh]) +AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_016_to_017.sh], + [chmod +x src/share/database/scripts/pgsql/upgrade_016_to_017.sh]) AC_CONFIG_FILES([src/share/database/scripts/pgsql/wipe_data.sh], [chmod +x src/share/database/scripts/pgsql/wipe_data.sh]) AC_CONFIG_FILES([src/share/yang/Makefile]) diff --git a/src/share/database/scripts/mysql/.gitignore b/src/share/database/scripts/mysql/.gitignore index c3c5062886..d6056d5a66 100644 --- a/src/share/database/scripts/mysql/.gitignore +++ b/src/share/database/scripts/mysql/.gitignore @@ -25,4 +25,5 @@ /upgrade_014_to_015.sh /upgrade_015_to_016.sh /upgrade_016_to_017.sh +/upgrade_017_to_018.sh /wipe_data.sh diff --git a/src/share/database/scripts/mysql/upgrade_016_to_017.sh.in b/src/share/database/scripts/mysql/upgrade_016_to_017.sh.in index 8a44660301..f3951c4907 100644 --- a/src/share/database/scripts/mysql/upgrade_016_to_017.sh.in +++ b/src/share/database/scripts/mysql/upgrade_016_to_017.sh.in @@ -66,140 +66,6 @@ ALTER TABLE dhcp6_subnet ADD COLUMN pd_allocator TEXT NULL; ALTER TABLE dhcp6_shared_network ADD COLUMN allocator TEXT NULL; ALTER TABLE dhcp6_shared_network ADD COLUMN pd_allocator TEXT NULL; --- Extend lease4 client_id to 255 bytes. -ALTER TABLE lease4 - MODIFY COLUMN client_id VARBINARY(255); - --- Extend hosts dhcp_identifier to 255 bytes. -ALTER TABLE hosts - MODIFY COLUMN dhcp_identifier VARBINARY(255) NOT NULL; - --- Extend hosts relay_id to 255 bytes. -ALTER TABLE lease4 - MODIFY COLUMN relay_id VARBINARY(255) DEFAULT NULL; - --- Extend hosts remote_id to 255 bytes. -ALTER TABLE lease4 - MODIFY COLUMN remote_id VARBINARY(255) DEFAULT NULL; - --- Extend lease6 duid to 130 bytes. -ALTER TABLE lease6 - MODIFY COLUMN duid VARBINARY(130); - -UPDATE lease6 SET duid = UNHEX('000000') WHERE duid = UNHEX('00'); - --- Drop and create lease4Upload stored procedure with 255 bytes long client_id. -DROP PROCEDURE IF EXISTS lease4Upload; - --- Create a procedure that inserts a v4 lease from memfile data. -DELIMITER $$ -CREATE PROCEDURE lease4Upload( - IN address VARCHAR(15), - IN hwaddr VARCHAR(20), - IN client_id VARCHAR(255), - IN valid_lifetime INT UNSIGNED, - IN expire BIGINT UNSIGNED, - IN subnet_id INT UNSIGNED, - IN fqdn_fwd TINYINT, - IN fqdn_rev TINYINT, - IN hostname VARCHAR(255), - IN state INT UNSIGNED, - IN user_context TEXT -) -BEGIN - INSERT INTO lease4 ( - address, - hwaddr, - client_id, - valid_lifetime, - expire, - subnet_id, - fqdn_fwd, - fqdn_rev, - hostname, - state, - user_context - ) VALUES ( - INET_ATON(address), - UNHEX(REPLACE(hwaddr, ':', '')), - UNHEX(REPLACE(client_id, ':', '')), - valid_lifetime, - FROM_UNIXTIME(expire), - subnet_id, - fqdn_fwd, - fqdn_rev, - REPLACE(hostname, ',', ','), - state, - REPLACE(user_context, ',', ',') - ); -END $$ -DELIMITER ; - --- Drop and create lease6Upload stored procedure with 130 bytes long duid. -DROP PROCEDURE IF EXISTS lease6Upload; - --- Create a procedure that inserts a v6 lease from memfile data. -DELIMITER $$ -CREATE PROCEDURE lease6Upload( - IN address VARCHAR(39), - IN duid VARCHAR(130), - IN valid_lifetime INT UNSIGNED, - IN expire BIGINT UNSIGNED, - IN subnet_id INT UNSIGNED, - IN pref_lifetime INT UNSIGNED, - IN lease_type TINYINT, - IN iaid INT UNSIGNED, - IN prefix_len TINYINT UNSIGNED, - IN fqdn_fwd TINYINT, - IN fqdn_rev TINYINT, - IN hostname VARCHAR(255), - IN hwaddr VARCHAR(64), - IN state INT UNSIGNED, - IN user_context TEXT, - IN hwtype SMALLINT, - IN hwaddr_source INT UNSIGNED -) -BEGIN - INSERT INTO lease6 ( - address, - duid, - valid_lifetime, - expire, - subnet_id, - pref_lifetime, - lease_type, - iaid, - prefix_len, - fqdn_fwd, - fqdn_rev, - hostname, - hwaddr, - state, - user_context, - hwtype, - hwaddr_source - ) VALUES ( - address, - UNHEX(REPLACE(duid, ':', '')), - valid_lifetime, - FROM_UNIXTIME(expire), - subnet_id, - pref_lifetime, - lease_type, - iaid, - prefix_len, - fqdn_fwd, - fqdn_rev, - REPLACE(hostname, ',', ','), - UNHEX(REPLACE(hwaddr, ':', '')), - state, - REPLACE(user_context, ',', ','), - hwtype, - hwaddr_source - ); -END $$ -DELIMITER ; - -- Update the schema version number. UPDATE schema_version SET version = '17', minor = '0'; diff --git a/src/share/database/scripts/mysql/upgrade_017_to_018.sh.in b/src/share/database/scripts/mysql/upgrade_017_to_018.sh.in new file mode 100644 index 0000000000..eb2d59af63 --- /dev/null +++ b/src/share/database/scripts/mysql/upgrade_017_to_018.sh.in @@ -0,0 +1,197 @@ +#!/bin/sh + +# Copyright (C) 2023 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 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# shellcheck disable=SC1091 +# SC1091: Not following: ... was not specified as input (see shellcheck -x). + +# Exit with error if commands exit with non-zero and if undefined variables are +# used. +set -eu + +# shellcheck disable=SC2034 +# SC2034: ... appears unused. Verify use (or export if used externally). +prefix="@prefix@" + +# Include utilities. Use installed version if available and +# use build version if it isn't. +if test -f "@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 + +# Check version. +version=$(mysql_version "${@}") +if test "${version}" != "17.0"; then + printf 'This script upgrades 17.0 to 18.0. ' + printf 'Reported version is %s. Skipping upgrade.\n' "${version}" + exit 0 +fi + +# Get the schema name from database argument. We need this to +# query information_schema for the right database. +for arg in "${@}" +do + if ! printf '%s' "${arg}" | grep -Eq '^\-\-' + then + schema="$arg" + break + fi +done + +# Make sure we have the schema. +if [ -z "$schema" ] +then + printf "Could not find database schema name in cmd line args: %s\n" "${*}" + exit 255 +fi + +mysql "$@" </dev/null < 0: - print(output) - - # Only report errors on the latest upgrade script. For all other upgrade - # scripts, there is a chance of false errors caused by incorrect matching of - # lines. Assume no diff so that CI doesn't complain. - return len(output) > 0 and upgrade_script == latest_upgrade_script + return output, upgrade_script == latest_upgrade_script def execute(command): @@ -194,7 +190,7 @@ def execute(command): output, error = p.communicate() if error: print('ERROR:', error, file=sys.stderr) - sys.exit(1) + sys.exit(2) return output.strip() @@ -278,26 +274,40 @@ def main(parameters): # Get the latest upgrade script. latest_upgrade_script = find_last_file_in_same_directory_starting_with(i, 'upgrade_') if latest_upgrade_script is None: - print('Warning: could not find latest upgrade script.', file=sys.stderr) + print('WARNING: could not find latest upgrade script.', file=sys.stderr) continue pairs.add((i, latest_upgrade_script)) elif basename.startswith('upgrade_'): # Get the dhcpdb_create script. dhcpdb_create = find_last_file_in_same_directory_starting_with(i, 'dhcpdb_create') if dhcpdb_create is None: - print('Warning: could not find dhcpdb_create script.', file=sys.stderr) + print('WARNING: could not find dhcpdb_create script.', file=sys.stderr) continue pairs.add((dhcpdb_create, i)) pairs = sorted(pairs) # Do the diff. - diff_found = False + output_for_latest = '' + output_for_other_than_latest = '' for create, update in pairs: - diff_found |= diff(create, update) + output, is_latest = diff(create, update) + if is_latest: + output_for_latest += output + else: + output_for_other_than_latest += output + + # Only print if we have something to print to avoid a newline. + # Also don't clutter output with lines that doesn't cause CI failure if + # there are lines that cause CI failure. + if len(output_for_latest): + print(output_for_latest) + elif len(output_for_other_than_latest): + print(output_for_other_than_latest) - # For any diff, return 1 so that CI complains. - # For no diff, return 0 to appease CI. - return int(diff_found) + # Only report errors on the latest upgrade script. For all other upgrade + # scripts, there is a chance of false errors caused by incorrect matching of + # lines. Assume no diff in that case so that CI doesn't complain. + return len(output_for_latest) != 0 if __name__ == '__main__':