From: Andrei Pavel Date: Fri, 11 Dec 2020 13:56:11 +0000 (+0200) Subject: [#1574] rename function to run_command X-Git-Tag: Kea-1.9.3~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d11a991016d1994c76d763c990f1dc2011e25c4;p=thirdparty%2Fkea.git [#1574] rename function to run_command --- diff --git a/src/bin/admin/kea-admin.in b/src/bin/admin/kea-admin.in index 1f97801934..57a0dba66f 100644 --- a/src/bin/admin/kea-admin.in +++ b/src/bin/admin/kea-admin.in @@ -142,7 +142,7 @@ mysql_can_create() { # Let's grab the version for possible debugging issues. It also # determines basic functional access to db. - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "select @@global.version;" if [ "${EXIT_CODE}" -ne 0 ] then @@ -165,7 +165,7 @@ BEGIN\n \ END;" # Let's clean up just in case. - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "$cleanup_sql" if [ "${EXIT_CODE}" -ne 0 ] then @@ -175,7 +175,7 @@ END;" # Now make the dummy table. perms_ok=1 - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "$table_sql" if [ "${EXIT_CODE}" -ne 0 ] then @@ -183,7 +183,7 @@ END;" perms_ok=0; else # Now attempt to make trigger - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "$trigger_sql" if [ "${EXIT_CODE}" -ne 0 ] then @@ -193,7 +193,7 @@ END;" fi # Try to cleanup no matter what happened above - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "$cleanup_sql" if [ "${EXIT_CODE}" -ne 0 ] then @@ -220,7 +220,7 @@ mysql_init() { # mysql may spit out connection or access errors to stderr, we ignore those. # We should not hide them as they may give hints to user what is wrong with # his setup. - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "SHOW TABLES;" if [ "${EXIT_CODE}" -ne 0 ] then @@ -262,7 +262,7 @@ pgsql_init() { # Let's try to count the number of tables. Anything above 0 means that there # is some database in place. If there is anything, we abort. - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "\d" if [ "${EXIT_CODE}" -ne 0 ]; then log_error "pgsql_init: table query failed, status code: ${EXIT_CODE}?" @@ -280,7 +280,7 @@ pgsql_init() { init_script="$scripts_dir/pgsql/dhcpdb_create.pgsql" printf "Initializing database using script %s\n" $init_script - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute_script $init_script if [ "${EXIT_CODE}" -ne 0 ]; then log_error "Database initialization failed, status code: ${EXIT_CODE}?" @@ -295,7 +295,7 @@ pgsql_init() { cql_init() { printf 'Checking if there is a database initialized already...\n' - run_and_return_output_and_exit_code \ + run_command \ cql_execute "DESCRIBE tables;" # Shellcheck complaints about missing quotes and word splitting here. There @@ -421,7 +421,7 @@ cql_upgrade() { fi # Check if there are upgrade scripts. - run_and_return_output_and_exit_code \ + run_command \ find "${scripts_dir}/cql" -name 'upgrade*.sh' -type f if [ "${EXIT_CODE}" -eq 0 ]; then # Upgrade scripts are present. for script in "${scripts_dir}"/cql/upgrade*.sh @@ -496,7 +496,7 @@ mysql_dump() { fi # get the correct dump query - run_and_return_output_and_exit_code \ + run_command \ mysql_version version="${OUTPUT}" if [ "${EXIT_CODE}" -ne 0 ] @@ -611,7 +611,7 @@ cql_dump() { check_file_overwrite "$dump_file" # Run query, check for failure. - run_and_return_output_and_exit_code \ + run_command \ cql_execute "${dump_query}" if [ "${EXIT_CODE}" -ne 0 ]; then log_error "lease-dump: cql_execute failed, exit code ${EXIT_CODE}" @@ -633,7 +633,7 @@ cql_dump() { mysql_recount() { printf "Recount lease statistics from database\n" - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "$_RECOUNT4_QUERY" if [ "${EXIT_CODE}" -ne 0 ] then @@ -641,7 +641,7 @@ mysql_recount() { exit 1 fi - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "$_RECOUNT6_QUERY" if [ "${EXIT_CODE}" -ne 0 ] then @@ -653,7 +653,7 @@ mysql_recount() { pgsql_recount() { printf "Recount lease statistics from database\n" - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "$_RECOUNT4_QUERY" if [ "${EXIT_CODE}" -ne 0 ] then @@ -661,7 +661,7 @@ pgsql_recount() { exit 1 fi - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "$_RECOUNT6_QUERY" if [ "${EXIT_CODE}" -ne 0 ] then diff --git a/src/bin/admin/tests/cql_tests.sh.in b/src/bin/admin/tests/cql_tests.sh.in index 1ba2a3863e..0ede814595 100644 --- a/src/bin/admin/tests/cql_tests.sh.in +++ b/src/bin/admin/tests/cql_tests.sh.in @@ -31,7 +31,7 @@ kea_admin="@abs_top_builddir@/src/bin/admin/kea-admin" cql_wipe() { # Wipe the database. - run_and_return_output_and_exit_code \ + run_command \ cql_execute_script $db_scripts_dir/cql/dhcpdb_drop.cql assert_eq 0 "${EXIT_CODE}" "drop table query failed, exit code %d, expected %d" } @@ -43,41 +43,41 @@ cql_db_init_test() { cql_wipe # Create the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init cql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "kea-admin db-init cql failed, expected exit code: %d, actual: %d" # Verify that all the expected tables exist # Check schema_version table - run_and_return_output_and_exit_code \ + run_command \ cql_execute "SELECT version, minor FROM schema_version;" assert_eq 0 "${EXIT_CODE}" "schema_version table check failed, expected exit code: %d, actual: %d" # Check lease4 table - run_and_return_output_and_exit_code \ + run_command \ cql_execute "SELECT address, hwaddr, client_id, valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, state, user_context FROM lease4;" assert_eq 0 "${EXIT_CODE}" "lease4 table check failed, expected exit code: %d, actual: %d" # Check lease6 table - run_and_return_output_and_exit_code \ + run_command \ cql_execute "SELECT address, duid, valid_lifetime, expire, subnet_id, pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, state, user_context FROM lease6;" assert_eq 0 "${EXIT_CODE}" "lease6 table check failed, expected exit code: %d, actual: %d" # Check lease6_types table - run_and_return_output_and_exit_code \ + run_command \ cql_execute "SELECT lease_type, name FROM lease6_types;" assert_eq 0 "${EXIT_CODE}" "lease6_types table check failed, expected exit code: %d, actual: %d" # Check lease_state table - run_and_return_output_and_exit_code \ + run_command \ cql_execute "SELECT state, name FROM lease_state;" assert_eq 0 "${EXIT_CODE}" "lease_state table check failed, expected exit code: %d, actual: %d" # Trying to create it again should fail. This verifies the db present # check echo "Making sure keyspace creation fails the second time..." - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init cql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 2 "${EXIT_CODE}" "kea-admin failed to deny db-init, expected exit code: %d, actual: %d" @@ -94,7 +94,7 @@ cql_db_version_test() { cql_wipe # Create the database. - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init cql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "kea-admin db-init cql failed, expected exit code: %d, actual: %d" @@ -115,11 +115,11 @@ cql_upgrade_test() { cql_wipe # Initialize database to schema 1.0. - run_and_return_output_and_exit_code \ + run_command \ cql_execute_script "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.cql" assert_eq 0 "${EXIT_CODE}" "cannot initialize the database, expected exit code: %d, actual: %d" - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-upgrade cql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "db-upgrade failed, expected exit code: %d, actual: %d" @@ -154,7 +154,7 @@ cql_lease4_dump_test() { cql_wipe # Create the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init cql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "kea-admin db-init cql failed, expected exit code: %d, actual: %d" @@ -176,12 +176,12 @@ cql_lease4_dump_test() { fqdn_fwd, fqdn_rev, hostname, state, user_context) \ VALUES (-1073741300,textAsBlob('22'),NULL,40,1436173267,50,true,true,'three.example.com', 2, '');" - run_and_return_output_and_exit_code \ + run_command \ cql_execute "$insert_cql" assert_eq 0 "${EXIT_CODE}" "insert into lease4 failed, expected exit code %d, actual %d" # Dump lease4 to output_file. - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" lease-dump cql -4 -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" -o $output_file assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -4 failed, expected exit code %d, actual %d" @@ -189,7 +189,7 @@ cql_lease4_dump_test() { sort -g "${output_file}" > "${sorted_file}" # Compare the dump output to reference file, they should be identical. - run_and_return_output_and_exit_code \ + run_command \ cmp -s $sorted_file $ref_file assert_eq 0 "${EXIT_CODE}" "dump file does not match reference file, expected exit code %d, actual %d" @@ -230,7 +230,7 @@ cql_lease6_dump_test() { cql_wipe # Create the database. - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init cql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "could not create database, expected exit code %d, actual %d" @@ -255,12 +255,12 @@ cql_lease6_dump_test() { VALUES ('2001:db8::12',textAsBlob('21'),30,1436173267,40,50,1,60,70,true,true, \ 'three.example.com',textAsBlob('80'),90,4,2,'');" - run_and_return_output_and_exit_code \ + run_command \ cql_execute "$insert_cql" assert_eq 0 "${EXIT_CODE}" "insert into lease6 failed, expected exit code %d, actual %d" # Dump lease4 to output_file. - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" lease-dump cql -6 -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" -o $output_file assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -6 failed, status code %d" @@ -268,7 +268,7 @@ cql_lease6_dump_test() { sort -g "${output_file}" > "${sorted_file}" # Compare the dump output to reference file, they should be identical. - run_and_return_output_and_exit_code \ + run_command \ cmp -s $sorted_file $ref_file assert_eq 0 "${EXIT_CODE}" "dump file does not match reference file, expected exit code %d, actual %d" @@ -349,12 +349,12 @@ cql_unused_subnet_id_test() { INSERT INTO host_reservations (id, host_identifier_type, host_identifier, host_ipv4_subnet_id, host_ipv6_subnet_id, hostname, option_subnet_id) \ VALUES (5, 0, textAsBlob('3123456'), -1, 6, 'host3', 6);" - run_and_return_output_and_exit_code \ + run_command \ cql_execute "$qry" assert_eq 0 "${EXIT_CODE}" "insert hosts failed, expected exit code: %d, actual: %d" # Ok, we have a 2.0 database with hosts and options. Let's upgrade it. - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-upgrade cql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" # Upgrade should succeed @@ -374,7 +374,7 @@ cql_unused_subnet_id_test() { SELECT id, host_ipv4_subnet_id, host_ipv6_subnet_id, hostname, lower_case_hostname, option_subnet_id\ FROM hosts WHERE id IN (1,2,3,4,5) ALLOW FILTERING;" - run_and_return_output_and_exit_code \ + run_command \ cql_execute "$qry" printf '%s\n' "${OUTPUT}" > "${export_file}" assert_eq 0 "${EXIT_CODE}" "insert hosts failed, expected exit code: %d, actual: %d" @@ -383,7 +383,7 @@ cql_unused_subnet_id_test() { grep -F '|' "${export_file}" | sort -V | tr -d " " | sed 's/|/,/g' > $sorted_file # Compare the dump output to reference file, they should be identical. - run_and_return_output_and_exit_code \ + run_command \ cmp -s $sorted_file $ref_file assert_eq 0 "${EXIT_CODE}" "export file does not match reference file, expected exit code %d, actual %d" @@ -445,12 +445,12 @@ cql_upgrade_hosts_test() { option_scope_id) \ FROM '$data_file'" - run_and_return_output_and_exit_code \ + run_command \ cql_execute "$qry" assert_eq 0 "${EXIT_CODE}" "insert hosts failed, expected exit code: %d, actual: %d" # Ok, we have a 3.0 database with hosts and options. Let's upgrade it. - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-upgrade cql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" # Upgrade should succeed @@ -471,7 +471,7 @@ cql_upgrade_hosts_test() { option_scope_id) \ TO '$export_file'" - run_and_return_output_and_exit_code \ + run_command \ cql_execute "$qry" assert_eq 0 "${EXIT_CODE}" "insert hosts failed, expected exit code: %d, actual: %d" @@ -479,7 +479,7 @@ cql_upgrade_hosts_test() { sort -V "${export_file}" > "${sorted_file}" # Compare the dump output to reference file, they should be identical. - run_and_return_output_and_exit_code \ + run_command \ cmp -s $sorted_file $ref_file assert_eq 0 "${EXIT_CODE}" "export file does not match reference file, expected exit code %d, actual %d" diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in index d28bb37918..f3e26029f5 100644 --- a/src/bin/admin/tests/mysql_tests.sh.in +++ b/src/bin/admin/tests/mysql_tests.sh.in @@ -47,7 +47,7 @@ run_statement() { exp_value="${1-}" # Execute the statment - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" value="${OUTPUT}" @@ -66,7 +66,7 @@ run_statement() { mysql_wipe() { printf "Wiping whole database %s...\n" "${db_name}" - run_and_return_output_and_exit_code \ + run_command \ mysql_execute_script "${db_scripts_dir}/mysql/dhcpdb_drop.mysql" assert_eq 0 "${EXIT_CODE}" "mysql-wipe: drop table sql failed, exit code %d, expected %d" @@ -79,38 +79,38 @@ mysql_db_init_test() { mysql_wipe # Ok, now let's initialize the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "kea-admin db-init mysql returned non-zero status code %d, expected %d" # Ok, now let's check if the tables are indeed there. # First table: schema_version. Should have 2 columns: version and minor. - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT version, minor FROM schema_version;' assert_eq 0 "${EXIT_CODE}" "schema_version table is missing or broken. (expected status code %d, returned %d)" # Second table: lease4 - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT address, hwaddr, client_id, valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname FROM lease4;' assert_eq 0 "${EXIT_CODE}" "lease4 table is missing or broken. (expected status code %d, returned %d)" # Third table: lease6 - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT address, duid, valid_lifetime, expire, subnet_id, pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, hwaddr_source FROM lease6;' assert_eq 0 "${EXIT_CODE}" "lease6 table is missing or broken. (expected status code %d, returned %d)" # Fourth table: lease6_types - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT lease_type, name FROM lease6_types;' assert_eq 0 "${EXIT_CODE}" "lease6_types table is missing or broken. (expected status code %d, returned %d)" # Fifth table: lease_hwaddr_source - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT hwaddr_source, name FROM lease_hwaddr_source;' assert_eq 0 "${EXIT_CODE}" "lease_hwaddr_source table is missing or broken. (expected status code %d, returned %d)" @@ -129,12 +129,12 @@ mysql_db_version_test() { # Do not create any table so db-version will raise an error printf 'Checking db-version error case...\n' - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" assert_eq 1 "${EXIT_CODE}" "schema_version table still exists. (expected %d, exit code %d)" # Ok, now let's create a version 1.7 - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'CREATE TABLE schema_version ( version INT PRIMARY KEY NOT NULL, @@ -143,7 +143,7 @@ mysql_db_version_test() { INSERT INTO schema_version VALUES (1, 7);' assert_eq 0 "${EXIT_CODE}" "schema_version table cannot be created. (expected %d, exit code %d)" - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" version="${OUTPUT}" assert_str_eq "1.7" "${version}" "Expected kea-admin to return %s, returned value was %s" @@ -161,49 +161,49 @@ mysql_host_reservation_init_test() { mysql_wipe # Ok, now let's initialize the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "kea-admin db-init mysql returned non-zero status code %d, expected %d" # Ok, now let's check if the tables are indeed there. # First table: schema_version. Should have 2 columns: version and minor. - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT version, minor FROM schema_version;' assert_eq 0 "${EXIT_CODE}" "schema_version table is missing or broken. (expected status code %d, returned %d)" # Second table: hosts - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT host_id, dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, dhcp4_client_classes, dhcp6_client_classes, dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name, auth_key FROM hosts;' assert_eq 0 "${EXIT_CODE}" "hosts table is missing or broken. (expected status code %d, returned %d)" # Third table: ipv6_reservations - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT reservation_id, address, prefix_len, type, dhcp6_iaid, host_id FROM ipv6_reservations;' assert_eq 0 "${EXIT_CODE}" "ipv6_reservations table is missing or broken. (expected status code %d, returned %d)" # Fourth table: dhcp4_options - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp4_subnet_id, host_id, scope_id FROM dhcp4_options;' assert_eq 0 "${EXIT_CODE}" "dhcp4_options table is missing or broken. (expected status code %d, returned %d)" # Fifth table: dhcp6_options - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp6_subnet_id, host_id, scope_id FROM dhcp6_options;' assert_eq 0 "${EXIT_CODE}" "dhcp6_options table is missing or broken. (expected status code %d, returned %d)" # Sixth table: host_identifier_type - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT type, name FROM host_identifier_type;' assert_eq 0 "${EXIT_CODE}" "host_identifier_type table is missing or broken. (expected status code %d, returned %d)" # Seventh table: dhcp_option_scope - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT scope_id, scope_name FROM dhcp_option_scope;' assert_eq 0 "${EXIT_CODE}" "dhcp_option_scope table is missing or broken. (expected status code %d, returned %d)" @@ -262,75 +262,75 @@ mysql_upgrade_test() { 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 9.5 - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-upgrade mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "kea-admin db-upgrade mysql returned non-zero status code %d, expected %d\n" # Let's check that the new tables are indeed there. #table: lease6 (upgrade 1.0 -> 2.0) - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT hwaddr, hwtype, hwaddr_source FROM lease6;' assert_eq 0 "${EXIT_CODE}" "lease6 table not upgraded to 2.0 (expected status code %d, returned %d)" #table: lease_hwaddr_source (upgrade 1.0 -> 2.0) - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT hwaddr_source, name FROM lease_hwaddr_source;' assert_eq 0 "${EXIT_CODE}" "lease_hwaddr_source table is missing or broken. (expected status code %d, returned %d)" #table: hosts (upgrade 2.0 -> 3.0) - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT host_id, dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, dhcp4_client_classes, dhcp6_client_classes FROM hosts;' assert_eq 0 "${EXIT_CODE}" "hosts table is missing or broken. (expected status code %d, returned %d)" #table: ipv6_reservations (upgrade 2.0 -> 3.0) - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT reservation_id, address, prefix_len, type, dhcp6_iaid, host_id FROM ipv6_reservations;' assert_eq 0 "${EXIT_CODE}" "ipv6_reservations table is missing or broken. (expected status code %d, returned %d)" #table: dhcp4_options (upgrade 2.0 -> 3.0) - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp4_subnet_id, host_id FROM dhcp4_options;' assert_eq 0 "${EXIT_CODE}" "dhcp4_options table is missing or broken. (expected status code %d, returned %d)" #table: dhcp6_options (upgrade 2.0 -> 3.0) - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp6_subnet_id, host_id FROM dhcp6_options;' assert_eq 0 "${EXIT_CODE}" "dhcp6_options table is missing or broken. (expected status code %d, returned %d)" #table: lease_state table added (upgrade 3.0 -> 4.0) - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT state,name from lease_state;' assert_eq 0 "${EXIT_CODE}" "dhcp6_options table is missing or broken. (expected status code %d, returned %d)" #table: state column added to lease4 (upgrade 3.0 -> 4.0) - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT state from lease4;' assert_eq 0 "${EXIT_CODE}" "lease4 is missing state column. (expected status code %d, returned %d)" #table: state column added to lease6 (upgrade 3.0 -> 4.0) - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT state from lease6;' assert_eq 0 "${EXIT_CODE}" "lease6 is missing state column. (expected status code %d, returned %d)" #table: stored procedures for lease dumps added (upgrade 3.0 -> 4.0) - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'call lease4DumpHeader(); call lease4DumpData(); call lease6DumpHeader(); call lease6DumpHeader();' assert_eq 0 "${EXIT_CODE}" "lease dump stored procedures are missing or broken. (expected status code %d, returned %d)" #lease_hardware_source should have row for source = 0 (upgrade 4.0 -> 4.1) qry="select count(hwaddr_source) from lease_hwaddr_source where hwaddr_source = 0 and name='HWADDR_SOURCE_UNKNOWN';" - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" count="${OUTPUT}" assert_eq 0 "${EXIT_CODE}" "select from lease_hwaddr_source failed. (expected status code %d, returned %d)" @@ -339,7 +339,7 @@ mysql_upgrade_test() { # table: stored procedures for lease data dumps were modified (upgrade 4.0 -> 4.1) # verify lease4DumpData has order by lease address qry="show create procedure lease4DumpData" - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" assert_eq 0 "${EXIT_CODE}" "procedure text fetch for lease4DumpData failed. (returned status code %d, expected %d)" count=$(echo "${OUTPUT}" | grep -Fci 'order by l.address') || true @@ -347,7 +347,7 @@ mysql_upgrade_test() { # verify lease6DumpData has order by lease address qry="show create procedure lease6DumpData" - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" assert_eq 0 "${EXIT_CODE}" "procedure text fetch for lease6DumpData failed. (returned status code %d, expected %d)" count=$(echo "${OUTPUT}" | grep -Fci 'order by l.address') || true @@ -356,7 +356,7 @@ mysql_upgrade_test() { #table: host_identifier_type (upgrade 4.1 -> 5.0) # verify that host_identifier_type table exists. qry="select count(*) from host_identifier_type"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" count="${OUTPUT}" assert_eq 0 "${EXIT_CODE}" "select from host_identifier_type failed. (expected status code %d, returned %d)" @@ -364,7 +364,7 @@ mysql_upgrade_test() { # verify that foreign key fk_host_identifier_type exists qry="show create table hosts"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" count=$(echo "${OUTPUT}" | grep -Fci -m 1 'fk_host_identifier_type') || true assert_eq 0 "${EXIT_CODE}" "show create table hosts failed. (expected status code %d, returned %d)" @@ -373,7 +373,7 @@ mysql_upgrade_test() { #table: dhcp_option_scope (upgrade 4.1 -> 5.0) # verify that dhcp_option_scope table exists. qry="select count(*) from dhcp_option_scope"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" count="${OUTPUT}" assert_eq 0 "${EXIT_CODE}" "select from dhcp_option_scope failed. (expected status code %d, returned %d)" @@ -383,7 +383,7 @@ mysql_upgrade_test() { #table: scope_id columns to dhcp4_options (upgrade 4.1 -> 5.0) # verify that dhcp4_options table includes scope_id qry="select scope_id from dhcp4_options"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" count="${OUTPUT}" assert_eq 0 "${EXIT_CODE}" "select scope_id from dhcp4_options failed. (expected status code %d, returned %d)" @@ -391,7 +391,7 @@ mysql_upgrade_test() { #table: scope_id columns to dhcp6_options (upgrade 4.1 -> 5.0) # verify that dhcp6_options table includes scope_id qry="select scope_id from dhcp6_options"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" count="${OUTPUT}" assert_eq 0 "${EXIT_CODE}" "select scope_id from dhcp6_options failed. (expected status code %d, returned %d)" @@ -399,14 +399,14 @@ mysql_upgrade_test() { #table: DHCPv4 fixed field colums (upgrade 4.1 -> 5.0) # verify that hosts table has columns holding values for DHCPv4 fixed fields qry="select dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name, auth_key from hosts"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" count="${OUTPUT}" assert_eq 0 "${EXIT_CODE}" "select dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name, auth_key failed. (expected status code %d, returned %d)" # verify that dhcp4_subnet_id is unsigned qry="show columns from hosts like 'dhcp4_subnet_id'" - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" assert_eq 0 "${EXIT_CODE}" "show columns from hosts like 'dhcp4_subnet_id' failed. (expected status code %d, returned %d)" count=$(echo "${OUTPUT}" | grep -Fci unsigned) || true @@ -414,7 +414,7 @@ mysql_upgrade_test() { # verify that dhcp6_subnet_id is unsigned qry="show columns from hosts like 'dhcp6_subnet_id'" - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" assert_eq 0 "${EXIT_CODE}" "show columns from hosts like 'dhcp6_subnet_id' failed. (expected status code %d, returned %d)" count=$(echo "${OUTPUT}" | grep -Fci unsigned) || true @@ -422,7 +422,7 @@ mysql_upgrade_test() { #host_identifier_type should have rows for types 3 and 4 (upgrade 5.0 -> 5.1) qry="select count(*) from host_identifier_type"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" count="${OUTPUT}" assert_eq 0 "${EXIT_CODE}" "select from host_identifier_type failed. (expected status code %d, returned %d)" @@ -431,21 +431,21 @@ mysql_upgrade_test() { #table: user_context columns to hosts, dhcp4_options and dhcp6_options (upgrade 5.2 -> 6.0) # verify that hosts table includes user_context qry="select user_context from hosts"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" count="${OUTPUT}" assert_eq 0 "${EXIT_CODE}" "select user_context from hosts failed. (expected status code %d, returned %d)" # verify that dhcp4_options table includes user_context qry="select user_context from dhcp4_options"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" count="${OUTPUT}" assert_eq 0 "${EXIT_CODE}" "select user_context from dhcp4_options failed. (expected status code %d, returned %d)" # verify that dhcp6_options table includes user_context qry="select user_context from dhcp6_options"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" count="${OUTPUT}" assert_eq 0 "${EXIT_CODE}" "select user_context from dhcp6_options failed. (expected status code %d, returned %d)" @@ -455,20 +455,20 @@ mysql_upgrade_test() { #table: user_context to lease4 and lease6 (upgrade 6.0 -> 7.0) # verify that lease4 table includes user_context qry="select user_context from lease4"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" count="${OUTPUT}" assert_eq 0 "${EXIT_CODE}" "select user_context from lease4 failed. (expected status code %d, returned %d)" # verify that lease6 table includes user_context qry="select user_context from lease6"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" count="${OUTPUT}" assert_eq 0 "${EXIT_CODE}" "select user_context from lease6 failed. (expected status code %d, returned %d)" #table: logs (upgrade 6.0 -> 7.0) - run_and_return_output_and_exit_code \ + run_command \ mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \ 'SELECT timestamp, address, log FROM logs;' assert_eq 0 "${EXIT_CODE}" "logs table is missing or broken. (expected status code %d, returned %d)" @@ -759,7 +759,7 @@ mysql_upgrade_test() { insert_sql="\ insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_address) values (hex('010101010101'), 0, 1, inet_aton('192.0.2.0'));\ insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_address) values (hex('010101010102'), 0, 1, inet_aton('192.0.2.0'));" - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "$insert_sql" assert_eq 0 "${EXIT_CODE}" "insert into hosts failed, expected exit code %d, actual %d" @@ -770,7 +770,7 @@ insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_a run_statement "dhcp4_shared_network" "$qry" qry="show columns from dhcp4_shared_network like 'reservation_mode'"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" assert_eq 0 "${EXIT_CODE}" "show columns from dhcp4_shared_network like 'reservation_mode' failed. (expected status code %d, returned %d)" count=$(echo "${OUTPUT}" | grep -Fci reservation) || true @@ -781,7 +781,7 @@ insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_a run_statement "dhcp4_subnet" "$qry" qry="show columns from dhcp4_subnet like 'reservation_mode'"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" assert_eq 0 "${EXIT_CODE}" "show columns from dhcp4_subnet like 'reservation_mode' failed. (expected status code %d, returned %d)" count=$(echo "${OUTPUT}" | grep -Fci reservation) || true @@ -792,7 +792,7 @@ insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_a run_statement "dhcp6_shared_network" "$qry" qry="show columns from dhcp6_shared_network like 'reservation_mode'"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" assert_eq 0 "${EXIT_CODE}" "show columns from dhcp6_shared_network like 'reservation_mode' failed. (expected status code %d, returned %d)" count=$(echo "${OUTPUT}" | grep -Fci reservation) || true @@ -803,7 +803,7 @@ insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_a run_statement "dhcp6_subnet" "$qry" qry="show columns from dhcp6_subnet like 'reservation_mode'"; - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "${qry}" assert_eq 0 "${EXIT_CODE}" "show columns from dhcp6_subnet like 'reservation_mode' failed. (expected status code %d, returned %d)" count=$(echo "${OUTPUT}" | grep -Fci reservation) || true @@ -845,7 +845,7 @@ mysql_lease4_dump_test() { mysql_wipe # Ok, now let's initialize the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "could not create database, expected exit code %d, actual %d" @@ -855,17 +855,17 @@ insert into lease4 values(10,20,30,40,'2015-01-01 01:15:30',50,1,1,'one.example. insert into lease4 values(11,NULL,123,40,'2015-02-02 02:30:45',50,1,1,'', 1,NULL);\ insert into lease4 values(12,22,NULL,40,'2015-03-03 11:01:07',50,1,1,'three.example.com', 2,NULL);" - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "$insert_sql" assert_eq 0 "${EXIT_CODE}" "insert into lease4 failed, expected exit code %d, actual %d" # Dump lease4 to output_file - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" lease-dump mysql -4 -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" -o $output_file assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -4 failed, expected exit code %d, actual %d" # Compare the dump output to reference file, they should be identical - run_and_return_output_and_exit_code \ + run_command \ cmp -s "${output_file}" "${ref_file}" assert_eq 0 "${EXIT_CODE}" "dump file does not match reference file, expected exit code %d, actual %d" @@ -904,7 +904,7 @@ mysql_lease6_dump_test() { mysql_wipe # Ok, now let's initialize the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "could not create database, expected exit code %d, actual %d" @@ -914,17 +914,17 @@ insert into lease6 values(10,20,30,'2015-04-04 01:15:30',40,50,1,60,70,1,1,'one. insert into lease6 values(11,NULL,30,'2015-05-05 02:30:45',40,50,1,60,70,1,1,'',80,90,1,1,NULL);\ insert into lease6 values(12,21,30,'2015-06-06 11:01:07',40,50,1,60,70,1,1,'three.example.com',80,90,4,2,NULL);" - run_and_return_output_and_exit_code \ + run_command \ mysql_execute "$insert_sql" assert_eq 0 "${EXIT_CODE}" "insert into lease6 failed, expected exit code %d, actual %d" # Dump lease4 to output_file - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" lease-dump mysql -6 -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" -o $output_file assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -6 failed, status code %d" # Compare the dump output to reference file, they should be identical - run_and_return_output_and_exit_code \ + run_command \ cmp -s "${output_file}" "${ref_file}" assert_eq 0 "${EXIT_CODE}" "dump file does not match reference file, expected exit code %d, actual %d" @@ -948,7 +948,7 @@ mysql_lease4_stat_test() { mysql_wipe # Ok, now let's initialize the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "kea-admin db-init mysql returned non-zero status code %d, expected %d" @@ -1040,7 +1040,7 @@ mysql_lease6_stat_test() { mysql_wipe # Ok, now let's initialize the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "kea-admin db-init mysql returned non-zero status code %d, expected %d" @@ -1098,7 +1098,7 @@ mysql_lease_stat_upgrade_test() { run_statement "insert v6 leases" "$qry" # Ok, we have a 4.0 database with leases. Let's upgrade it to 6.0 - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-upgrade mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" # @@ -1214,7 +1214,7 @@ mysql_lease_stat_recount_test() { mysql_wipe # Ok, now let's initialize the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "kea-admin db-init mysql returned non-zero status code %d, expected %d" @@ -1250,7 +1250,7 @@ mysql_lease_stat_recount_test() { run_statement "change v6 stats" "$qry" # Recount all statistics from scratch. - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" stats-recount mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" assert_eq 0 "${EXIT_CODE}" "kea-admin stats-recount mysql returned non-zero status code %d, expected %d" diff --git a/src/bin/admin/tests/pgsql_tests.sh.in b/src/bin/admin/tests/pgsql_tests.sh.in index aeadeae875..14d15d29b1 100644 --- a/src/bin/admin/tests/pgsql_tests.sh.in +++ b/src/bin/admin/tests/pgsql_tests.sh.in @@ -47,7 +47,7 @@ run_statement() { exp_value="${1-}" # Optional value. If not given, replace with empty string. # Execute the statment - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "${qry}" value="${OUTPUT}" @@ -66,7 +66,7 @@ pgsql_wipe() { printf "Wiping whole database %s...\n" "${db_name}" export PGPASSWORD="${db_password}" - run_and_return_output_and_exit_code \ + run_command \ psql --set ON_ERROR_STOP=1 -A -t -q -U keatest -d keatest -f "${db_scripts_dir}/pgsql/dhcpdb_drop.pgsql" assert_eq 0 "${EXIT_CODE}" "pgsql_wipe drop failed, expected exit code: %d, actual: %d" } @@ -78,41 +78,41 @@ pgsql_db_init_test() { pgsql_wipe # Create the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "kea-admin db-init pgsql failed, expected exit code: %d, actual: %d" # Verify that all the expected tables exist # Check schema_version table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "SELECT version, minor FROM schema_version;" assert_eq 0 "${EXIT_CODE}" "schema_version table check failed, expected exit code: %d, actual: %d" # Check lease4 table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "SELECT address, hwaddr, client_id, valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, state, user_context FROM lease4;" assert_eq 0 "${EXIT_CODE}" "lease4 table check failed, expected exit code: %d, actual: %d" # Check lease6 table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "SELECT address, duid, valid_lifetime, expire, subnet_id, pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, state, user_context FROM lease6;" assert_eq 0 "${EXIT_CODE}" "lease6 table check failed, expected exit code: %d, actual: %d" # Check lease6_types table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "SELECT lease_type, name FROM lease6_types;" assert_eq 0 "${EXIT_CODE}" "lease6_types table check failed, expected exit code: %d, actual: %d" # Check lease_state table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "SELECT state, name FROM lease_state;" assert_eq 0 "${EXIT_CODE}" "lease_state table check failed, expected exit code: %d, actual: %d" # Trying to create it again should fail. This verifies the db present # check printf '\nDB created successfully, make sure we are not allowed to try it again:\n' - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 2 "${EXIT_CODE}" "kea-admin failed to deny db-init, expected exit code: %d, actual: %d" @@ -130,17 +130,17 @@ pgsql_db_version_test() { # Do not create any table so db-version will raise an error printf 'Checking db-version error case...\n' - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" assert_eq 3 "${EXIT_CODE}" "schema_version table still exists. (expected %d, exit code %d)" # Create the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "cannot initialize the database, expected exit code: %d, actual: %d" # Verify that kea-admin db-version returns the correct version - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" version="${OUTPUT}" assert_str_eq "6.2" "${version}" "Expected kea-admin to return %s, returned value was %s" @@ -153,110 +153,110 @@ pgsql_db_version_test() { pgsql_upgrade_1_0_to_2_0() { # Added state column to lease4 - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select state from lease4;" assert_eq 0 "${EXIT_CODE}" "lease4 is missing state column. (expected status code %d, returned %d)" # Added state column to lease6 - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select state from lease6;" assert_eq 0 "${EXIT_CODE}" "lease6 is missing state column. (expected status code %d, returned %d)" # Added stored procedures for lease dumps - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select lease4DumpHeader from lease4DumpHeader();" assert_eq 0 "${EXIT_CODE}" "function lease4DumpHeader() broken or missing. (expected status code %d, returned %d)" - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select address from lease4DumpData();" assert_eq 0 "${EXIT_CODE}" "function lease4DumpData() broken or missing. (expected status code %d, returned %d)" - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select lease6DumpHeader from lease6DumpHeader();" assert_eq 0 "${EXIT_CODE}" "function lease6DumpHeader() broken or missing. (expected status code %d, returned %d)" - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select address from lease6DumpData();" assert_eq 0 "${EXIT_CODE}" "function lease6DumpData() broken or missing. (expected status code %d, returned %d)" } pgsql_upgrade_2_0_to_3_0() { # Added hwaddr, hwtype, and hwaddr_source columns to lease6 table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select hwaddr, hwtype, hwaddr_source from lease6;" assert_eq 0 "${EXIT_CODE}" "lease6 table not upgraded to 3.0 (expected status code %d, returned %d)" # Added lease_hwaddr_source table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select hwaddr_source, name from lease_hwaddr_source;" assert_eq 0 "${EXIT_CODE}" "lease_hwaddr_source table is missing or broken. (expected status code %d, returned %d)" # Added hosts table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select host_id, dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, dhcp4_client_classes, dhcp6_client_classes, dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name, auth_key from hosts;" assert_eq 0 "${EXIT_CODE}" "hosts table is missing or broken. (expected status code %d, returned %d)" # Added ipv6_reservations table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select reservation_id, address, prefix_len, type, dhcp6_iaid, host_id from ipv6_reservations;" assert_eq 0 "${EXIT_CODE}" "ipv6_reservations table is missing or broken. (expected status code %d, returned %d)" # Added dhcp4_options table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp4_subnet_id, host_id, scope_id from dhcp4_options;" assert_eq 0 "${EXIT_CODE}" "dhcp4_options table is missing or broken. (expected status code %d, returned %d)" # Added dhcp6_options table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp6_subnet_id, host_id,scope_id from dhcp6_options;" assert_eq 0 "${EXIT_CODE}" "dhcp6_options table is missing or broken. (expected status code %d, returned %d)" # Added host_identifier_type table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select type, name from host_identifier_type;" assert_eq 0 "${EXIT_CODE}" "host_identifier_type table is missing or broken. (expected status code %d, returned %d)" # Added dhcp_option_scope table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select scope_id, scope_name from dhcp_option_scope;" assert_eq 0 "${EXIT_CODE}" "dhcp_option_scope table is missing or broken. (expected status code %d, returned %d)" # Added dhcp6_options table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp6_subnet_id, host_id,scope_id from dhcp6_options;" assert_eq 0 "${EXIT_CODE}" "dhcp6_options table is missing or broken. (expected status code %d, returned %d)" # Added order by clause to lease4DumpData - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select address from lease4DumpData();" assert_eq 0 "${EXIT_CODE}" "function lease4DumpData() broken or missing. (expected status code %d, returned %d)" - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "\sf lease4DumpData" assert_eq 0 "${EXIT_CODE}" "\sf of lease4DumpData failed. (expected status code %d, returned %d)" count=$(echo "${OUTPUT}" | grep -Fci 'order by l.address') || true assert_eq 1 "${count}" "lease4DumpData is missing order by clause" # Added hwaddr columns to lease6DumpHeader - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select lease6DumpHeader from lease6DumpHeader();" assert_eq 0 "${EXIT_CODE}" "function lease6DumpHeader() broken or missing. (expected status code %d, returned %d)" count=$(echo "${OUTPUT}" | grep -Fci 'hwaddr,hwtype,hwaddr_source') || true assert_eq 1 "${count}" "lease6DumpHeader is missing hwaddr columns" # Added hwaddr columns to lease6DumpData - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select hwaddr,hwtype,hwaddr_source from lease6DumpData();" assert_eq 0 "${EXIT_CODE}" "function lease6DumpData() broken or missing. (expected status code %d, returned %d)" # Added order by clause to lease6DumpData - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "\sf lease4DumpData" assert_eq 0 "${EXIT_CODE}" "\sf of lease4DumpData failed. (expected status code %d, returned %d)" count=$(echo "${OUTPUT}" | grep -Fci 'order by l.address') || true assert_eq 1 "${count}" "lease4DumpData is missing order by clause" # lease_hardware_source should have row for source = 0 - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select count(hwaddr_source) from lease_hwaddr_source where hwaddr_source = 0 and name='HWADDR_SOURCE_UNKNOWN';" assert_eq 0 "${EXIT_CODE}" "select from lease_hwaddr_source failed. (expected status code %d, returned %d)" assert_eq 1 "${OUTPUT}" "lease_hwaddr_source does not contain entry for HWADDR_SOURCE_UNKNOWN. (record count %d, expected %d)" @@ -264,17 +264,17 @@ pgsql_upgrade_2_0_to_3_0() { pgsql_upgrade_3_0_to_6_1() { # Added user_context to lease4 - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select user_context from lease4;" assert_eq 0 "${EXIT_CODE}" "lease4 is missing user_context column. (expected status code %d, returned %d)" # Added user_context to lease6 - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select user_context from lease6;" assert_eq 0 "${EXIT_CODE}" "lease6 is missing user_context column. (expected status code %d, returned %d)" # Added logs table - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select timestamp, address, log from logs;" assert_eq 0 "${EXIT_CODE}" "logs table is missing or broken. (expected status code %d, returned %d)" } @@ -287,7 +287,7 @@ pgsql_upgrade_6_1_to_6_2() { insert_sql="\ insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_address) values (decode('010101010101', 'hex'), 0, 1, x'FFAF0002'::int);\ insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_address) values (decode('010101010102', 'hex'), 0, 1, x'FFAF0002'::int);" - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "$insert_sql" assert_eq 0 "${EXIT_CODE}" "insert into hosts failed, expected exit code %d, actual %d" } @@ -299,11 +299,11 @@ pgsql_upgrade_test() { pgsql_wipe # Initialize database to schema 1.0. - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute_script "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.pgsql" assert_eq 0 "${EXIT_CODE}" "cannot initialize the database, expected exit code: %d, actual: %d" - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-upgrade pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "db-upgrade failed, expected exit code: %d, actual: %d" @@ -332,7 +332,7 @@ get_local_time() { # Expiration field is a "timestamp with timezone" so we need a reference # time for the machine/DB this test is running upon. - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "select timestamptz '$1';" assert_eq 0 "${EXIT_CODE}" "reference time query failed for [$timestamp], expected exit code %d, actual %d" echo "${OUTPUT}" @@ -378,7 +378,7 @@ pgsql_lease4_dump_test() { pgsql_wipe # Ok, now let's initialize the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "could not create database, expected exit code %d, actual %d" @@ -392,12 +392,12 @@ insert into lease4 values(10,E'\\x20',E'\\x30',40,'$timestamp1',50,'t','t','one. insert into lease4 values(11,'',E'\\x0123',40,'$timestamp2',50,'t','t','', 1, '');\ insert into lease4 values(12,E'\\x22','',40,'$timestamp3',50,'t','t','three.example.com', 2, '');" - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "$insert_sql" assert_eq 0 "${EXIT_CODE}" "insert into lease4 failed, expected exit code %d, actual %d" # Dump lease4 to output_file - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" lease-dump pgsql -4 -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" -o $output_file assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -4 failed, status code %d" @@ -414,13 +414,13 @@ s//${local_timestamp1}/g;\ s//${local_timestamp2}/g; \ s//${local_timestamp3}/g" - run_and_return_output_and_exit_code \ + run_command \ sed "${sed_command}" "${ref_file}" printf '%s\n' "${OUTPUT}" > "${ref_file_tmp}" assert_eq 0 "${EXIT_CODE}" "timestamp replacement failed, expected exit code %d, actual %d" # Compare the dump output to reference file, they should be identical - run_and_return_output_and_exit_code \ + run_command \ cmp -s "${output_file}" "${ref_file_tmp}" assert_eq 0 "${EXIT_CODE}" "dump file does not match reference file, expected exit code %d, actual %d" @@ -473,7 +473,7 @@ pgsql_lease6_dump_test() { pgsql_wipe # Ok, now let's initialize the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "could not create database, status code %d" @@ -487,12 +487,12 @@ insert into lease6 values(10,E'\\x20',30,'$timestamp1',40,50,1,60,70,'t','t','on insert into lease6 values(11,'',30,'$timestamp2',40,50,1,60,70,'t','t','', 1,decode('80','hex'),90,1,'');\ insert into lease6 values(12,E'\\x21',30,'$timestamp3',40,50,1,60,70,'t','t','three.example.com', 2,decode('80','hex'),90,4,'');" - run_and_return_output_and_exit_code \ + run_command \ pgsql_execute "$insert_sql" assert_eq 0 "${EXIT_CODE}" "insert into lease6 failed, status code %d" # Dump lease6 to output_file - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" lease-dump pgsql -6 -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" -o $output_file assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -6 failed, status code %d" @@ -509,13 +509,13 @@ s//${local_timestamp1}/g;\ s//${local_timestamp2}/g; \ s//${local_timestamp3}/g" - run_and_return_output_and_exit_code \ + run_command \ sed "${sed_command}" "${ref_file}" printf '%s\n' "${OUTPUT}" > "${ref_file_tmp}" assert_eq 0 "${EXIT_CODE}" "timestamp replacement failed, expected exit code %d, actual %d" # Compare the dump output to reference file, they should be identical - run_and_return_output_and_exit_code \ + run_command \ cmp -s "${output_file}" "${ref_file_tmp}" assert_eq 0 "${EXIT_CODE}" "dump file does not match reference file" @@ -578,7 +578,7 @@ pgsql_lease4_stat_test() { pgsql_wipe # Ok, now let's initialize the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "kea-admin db-init pgsql returned non-zero status code %d, expected %d" @@ -670,7 +670,7 @@ pgsql_lease6_stat_test() { pgsql_wipe # Ok, now let's initialize the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "kea-admin db-init pgsql returned non-zero status code %d, expected %d" @@ -729,7 +729,7 @@ pgsql_lease_stat_upgrade_test() { run_statement "insert v6 leases" "$qry" # Ok, we have a 2.0 database with leases. Let's upgrade it to 4.0 - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-upgrade pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" # @@ -843,7 +843,7 @@ pgsql_lease_stat_recount_test() { pgsql_wipe # Ok, now let's initialize the database - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-init pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" assert_eq 0 "${EXIT_CODE}" "kea-admin db-init pgsql returned non-zero status code %d, expected %d" @@ -880,7 +880,7 @@ pgsql_lease_stat_recount_test() { run_statement "change v6 stats" "$qry" # Recount all statistics from scratch. - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" stats-recount pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" assert_eq 0 "${EXIT_CODE}" "kea-admin stats-recount pgsql returned non-zero status code %d, expected %d" @@ -974,7 +974,7 @@ pgsql_unused_subnet_id_test() { run_statement "insert options" "$qry" # Ok, we have a 4.0 database with hosts and options. Let's upgrade it to 5.0 - run_and_return_output_and_exit_code \ + run_command \ "${kea_admin}" db-upgrade pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" # Upgrade should succeed diff --git a/src/bin/agent/tests/ca_process_tests.sh.in b/src/bin/agent/tests/ca_process_tests.sh.in index 98b5b3c6a3..2a845aaea6 100644 --- a/src/bin/agent/tests/ca_process_tests.sh.in +++ b/src/bin/agent/tests/ca_process_tests.sh.in @@ -102,7 +102,7 @@ syntax_check_test() { create_config "${config}" # Check it printf 'Running command %s.\n' "\"${bin_path}/${bin} -t ${CFG_FILE}\"" - run_and_return_output_and_exit_code \ + run_command \ "${bin_path}/${bin}" -t "${CFG_FILE}" if [ "${EXIT_CODE}" -ne "${expected_code}" ]; then printf 'ERROR: expected exit code %s, got %s\n' "${expected_code}" "${EXIT_CODE}" @@ -190,7 +190,7 @@ password_redact_test() { set_logger # Check it printf "Running command %s.\n" "\"${bin_path}/${bin} -d -t ${CFG_FILE}\"" - run_and_return_output_and_exit_code \ + run_command \ "${bin_path}/${bin}" -d -t "${CFG_FILE}" if [ "${EXIT_CODE}" -ne "${expected_code}" ]; then printf 'ERROR: expected exit code %s, got %s\n' "${expected_code}" "${EXIT_CODE}" diff --git a/src/bin/d2/tests/d2_process_tests.sh.in b/src/bin/d2/tests/d2_process_tests.sh.in index 8585f066b7..c6ca0c46ee 100644 --- a/src/bin/d2/tests/d2_process_tests.sh.in +++ b/src/bin/d2/tests/d2_process_tests.sh.in @@ -138,7 +138,7 @@ syntax_check_test() { create_config "${config}" # Check it printf "Running command %s.\n" "\"${bin_path}/${bin} -t ${CFG_FILE}\"" - run_and_return_output_and_exit_code \ + run_command \ "${bin_path}/${bin}" -t "${CFG_FILE}" if [ "${EXIT_CODE}" -ne "${expected_code}" ]; then printf 'ERROR: expected exit code %s, got %s\n' "${expected_code}" "${EXIT_CODE}" diff --git a/src/bin/dhcp4/tests/dhcp4_process_tests.sh.in b/src/bin/dhcp4/tests/dhcp4_process_tests.sh.in index d0f782cd7f..9d9ccd7f89 100644 --- a/src/bin/dhcp4/tests/dhcp4_process_tests.sh.in +++ b/src/bin/dhcp4/tests/dhcp4_process_tests.sh.in @@ -193,7 +193,7 @@ syntax_check_test() { create_config "${config}" # Check it printf "Running command %s.\n" "\"${bin_path}/${bin} -t ${CFG_FILE}\"" - run_and_return_output_and_exit_code \ + run_command \ "${bin_path}/${bin}" -t "${CFG_FILE}" if [ "${EXIT_CODE}" -ne "${expected_code}" ]; then printf 'ERROR: expected exit code %s, got %s\n' "${expected_code}" "${EXIT_CODE}" diff --git a/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in b/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in index 504cb3ad49..819bea31c8 100644 --- a/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in +++ b/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in @@ -196,7 +196,7 @@ syntax_check_test() { create_config "${config}" # Check it printf "Running command %s.\n" "\"${bin_path}/${bin} -t ${CFG_FILE}\"" - run_and_return_output_and_exit_code \ + run_command \ "${bin_path}/${bin}" -t "${CFG_FILE}" if [ "${EXIT_CODE}" -ne "${expected_code}" ]; then printf 'ERROR: expected exit code %s, got %s\n' "${expected_code}" "${EXIT_CODE}" diff --git a/src/bin/keactrl/tests/keactrl_tests.sh.in b/src/bin/keactrl/tests/keactrl_tests.sh.in index 2d55c16a30..1e1006c74d 100644 --- a/src/bin/keactrl/tests/keactrl_tests.sh.in +++ b/src/bin/keactrl/tests/keactrl_tests.sh.in @@ -14,11 +14,11 @@ set -eu # Disclaimer: `${keactrl} start` commands use `set +e` / `set -e` instead of -# run_and_return_output_and_exit_code because -# run_and_return_output_and_exit_code launches a subshell which inherently waits +# run_command because +# run_command launches a subshell which inherently waits # for the background processes started in `${keactrl} start` which don't end # until explicitly stopped. So the test would freeze if -# run_and_return_output_and_exit_code would be used. +# run_command would be used. # Include common test library. . "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh" @@ -474,7 +474,7 @@ Expected wait_for_message return %d, returned %d." # Use keactrl stop to shutdown the servers. printf 'Stopping Kea: %s stop -c %s\n' "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" stop -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d." @@ -584,7 +584,7 @@ Expected wait_for_message return %d, returned %d." # Make sure that the status command returns appropriate status. printf "Getting status of Kea modules: %s\n" "${keactrl} status \ -c ${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" status -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned %d" assert_string_contains "DHCPv4 server: active" "${OUTPUT}" \ @@ -602,7 +602,7 @@ Expected wait_for_message return %d, returned %d." # Use keactrl stop to shutdown the servers. printf 'Stopping Kea: %s stop -c %s\n' "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" stop -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d." @@ -693,7 +693,7 @@ Expected wait_for_message return %d, returned %d." # Make sure that the status command returns appropriate status. printf "Getting status of Kea modules: %s\n" "${keactrl} status -c ${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" status -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned %d" assert_string_contains "DHCPv4 server: inactive" "${OUTPUT}" \ @@ -711,7 +711,7 @@ Expected wait_for_message return %d, returned %d." # Use keactrl stop to shutdown the servers. printf 'Stopping Kea: %s stop -c %s\n' "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" stop -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d." @@ -803,7 +803,7 @@ Expected wait_for_message return %d, returned %d." # Trigger reconfiguration, make sure that the DHCPv6 server reconfigured. printf 'Reconfiguring the DHCPv6 server: %s reload -c %s\n' "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" reload -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d" @@ -872,7 +872,7 @@ Expected wait_for_message return %d, returned %d." # Trigger reconfiguration, make sure that servers are reconfigured. printf "Reconfiguring all servers: %s reload -c %s\n" \ "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" reload -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d" @@ -894,7 +894,7 @@ to reconfigure. Expected wait_for_message to return %d, returned %d." # Use keactrl stop to shutdown the servers. printf 'Stopping Kea: %s stop -c %s\n' "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" stop -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d." @@ -1003,7 +1003,7 @@ Expected wait_for_message return %d, returned %d." # Trigger reconfiguration, make sure that the DHCPv4 server is reconfigured. printf 'Reconfiguring the DHCPv4 server: %s reload -c %s\n' "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" reload -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d" @@ -1073,7 +1073,7 @@ Expected wait_for_message return %d, returned %d." # Trigger reconfiguration, make sure that servers are reconfigured. printf 'Reconfiguring DHCPv6 and DHCPv4 servers: %s reload -c %s\n' \ "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" reload -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d" @@ -1095,7 +1095,7 @@ Expected wait_for_message to return %d, returned %d." # Use keactrl stop to shutdown the servers. printf 'Stopping Kea: %s stop -c %s\n' "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" stop -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d." @@ -1223,7 +1223,7 @@ Expected wait_for_message return %d, returned %d." # Use keactrl stop to shutdown DHCPv4 server. printf "Stopping DHCPv4 server: %s stop -s dhcp4 -c %s\n" "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" stop -s dhcp4 -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d." @@ -1267,7 +1267,7 @@ Expected wait_for_message return %d, returned %d." # Use keactrl stop to shutdown DHCPv6 server. printf 'Stopping DHCPv6 server: %s stop -s dhcp6 -c %s\n' "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" stop -s dhcp6 -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d." @@ -1299,7 +1299,7 @@ Expected wait_for_message return %d, returned %d." # Use keactrl stop to shutdown D2 server. printf 'Stopping DHCP DDNS server: %s stop -s dhcp_ddns -c %s\n' "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" stop -s dhcp_ddns -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d." @@ -1333,7 +1333,7 @@ Expected wait_for_message return %d, returned %d." # Use keactrl stop to shutdown CA. printf 'Stopping Control Agent: %s stop -s ctrl_agent -c %s\n' "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" stop -s ctrl_agent -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d." @@ -1363,7 +1363,7 @@ Expected wait_for_message return %d, returned %d." # Use keactrl stop to shutdown Netconf agent. if ${have_netconf}; then printf 'Stopping Netconf agent: %s stop -s netconf -c %s\n' "${keactrl}" "${KEACTRL_CFG_FILE}" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" stop -s netconf -c ${KEACTRL_CFG_FILE} assert_eq 0 "${EXIT_CODE}" "Expected keactrl to return %d, returned value was %d." @@ -1397,7 +1397,7 @@ status_no_config_test() { # the config file. printf "Getting status without a Kea config file\n" - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" status -c ${KEACTRL_CFG_FILE} assert_eq 1 "${EXIT_CODE}" "Expected keactrl to return %d, returned %d" assert_string_contains "DHCPv4 server: inactive" "${OUTPUT}" \ @@ -1445,7 +1445,7 @@ version_command_test() { EXPECTED_RESP=$(printf "%b" "$exp") # Let's use short version: - run_and_return_output_and_exit_code \ + run_command \ "${keactrl}" version -c ${KEACTRL_CFG_FILE} assert_str_eq "${EXPECTED_RESP}" "${OUTPUT}" \ diff --git a/src/bin/netconf/tests/shtests/netconf_tests.sh.in b/src/bin/netconf/tests/shtests/netconf_tests.sh.in index d0c8e5ae45..af897a7506 100644 --- a/src/bin/netconf/tests/shtests/netconf_tests.sh.in +++ b/src/bin/netconf/tests/shtests/netconf_tests.sh.in @@ -95,7 +95,7 @@ usage_test() { # Check it printf "Running command %s.\n" "\"${bin_path}/${bin} -t ${CFG_FILE}\"" - run_and_return_output_and_exit_code \ + run_command \ "${bin_path}/${bin}" "${parameter}" if [ "${EXIT_CODE}" -ne "${expected_code}" ]; then printf 'ERROR: expected exit code %s, got %s\n' "${expected_code}" "${EXIT_CODE}" @@ -116,7 +116,7 @@ no_argument_test() { # Check it printf "Running command %s.\n" "\"${bin_path}/${bin}\"" - run_and_return_output_and_exit_code \ + run_command \ "${bin_path}/${bin}" if [ "${EXIT_CODE}" -ne "${expected_code}" ]; then printf 'ERROR: expected exit code %s, got %s\n' "${expected_code}" "${EXIT_CODE}" @@ -143,7 +143,7 @@ syntax_check_test() { create_config "${config}" # Check it printf "Running command %s.\n" "\"${bin_path}/${bin} -t ${CFG_FILE}\"" - run_and_return_output_and_exit_code \ + run_command \ "${bin_path}/${bin}" -t "${CFG_FILE}" if [ "${EXIT_CODE}" -ne "${expected_code}" ]; then printf 'ERROR: expected exit code %s, got %s\n' "${expected_code}" "${EXIT_CODE}" diff --git a/src/lib/testutils/dhcp_test_lib.sh.in b/src/lib/testutils/dhcp_test_lib.sh.in index 9d12a97cba..67b20a167d 100644 --- a/src/lib/testutils/dhcp_test_lib.sh.in +++ b/src/lib/testutils/dhcp_test_lib.sh.in @@ -138,7 +138,7 @@ does not contain pattern: # parameter assignment, but eval is not recommended. # shellcheck disable=SC2034 # SC2034: ... appears unused. Verify use (or export if used externally). -run_and_return_output_and_exit_code() { +run_command() { if test -n "${DEBUG+x}"; then printf '%s\n' "${*}" >&2 fi @@ -814,7 +814,7 @@ version_test() { long_version='--version' fi - for v in -v ${long_version}; do + for v in -v "${long_version}"; do run_command \ "${bin_path}/${bin}" "${v}"