# 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
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
# 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
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
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
# 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
# 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}?"
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}?"
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
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
fi
# get the correct dump query
- run_and_return_output_and_exit_code \
+ run_command \
mysql_version
version="${OUTPUT}"
if [ "${EXIT_CODE}" -ne 0 ]
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}"
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
exit 1
fi
- run_and_return_output_and_exit_code \
+ run_command \
mysql_execute "$_RECOUNT6_QUERY"
if [ "${EXIT_CODE}" -ne 0 ]
then
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
exit 1
fi
- run_and_return_output_and_exit_code \
+ run_command \
pgsql_execute "$_RECOUNT6_QUERY"
if [ "${EXIT_CODE}" -ne 0 ]
then
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"
}
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"
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"
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"
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"
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"
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"
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"
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"
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"
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
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"
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"
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
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"
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"
exp_value="${1-}"
# Execute the statment
- run_and_return_output_and_exit_code \
+ run_command \
mysql_execute "${qry}"
value="${OUTPUT}"
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"
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)"
# 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,
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"
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)"
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)"
# 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
# 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
#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)"
# 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)"
#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)"
#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)"
#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)"
#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
# 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
#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)"
#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)"
#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)"
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"
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
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
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
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
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"
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"
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"
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"
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"
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"
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}"
#
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"
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"
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}"
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"
}
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"
# 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"
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)"
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)"
}
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"
}
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"
# 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}"
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"
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"
s/<timestamp2>/${local_timestamp2}/g; \
s/<timestamp3>/${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"
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"
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"
s/<timestamp2>/${local_timestamp2}/g; \
s/<timestamp3>/${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"
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"
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"
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}"
#
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"
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"
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
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}"
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}"
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}"
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}"
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}"
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"
# 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."
# 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}" \
# 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."
# 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}" \
# 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."
# 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"
# 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"
# 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."
# 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"
# 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"
# 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."
# 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."
# 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."
# 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."
# 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."
# 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."
# 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}" \
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}" \
# 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}"
# 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}"
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}"
# 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
long_version='--version'
fi
- for v in -v ${long_version}; do
+ for v in -v "${long_version}"; do
run_command \
"${bin_path}/${bin}" "${v}"