-2022. [func] andrei
+2022. [func] andrei, djt
kea-admin lease-upload will now call the lease file cleanup (LFC)
process to clean up entries with duplicate addresses in the input
- CSV file.
+ CSV file to avoid a conflict error when inserting the leases in
+ the database. kea-admin has also gained a new -y|--yes flag that
+ enables automatic overwriting of any file that it writes to, when
+ dumping or uploading leases.
(Gitlab #2293)
2021. [build] razvan
test_start 'kea_admin_error_reporting_test.db_init.mysql.i'
run_command \
- "${kea_admin}" lease-dump mysql -y -i
+ "${kea_admin}" lease-dump mysql -i
assert_eq 1 "${EXIT_CODE}"
assert_str_eq 'ERROR/kea-admin: -i or --input requires a parameter' "$(printf '%s\n' "${OUTPUT}" | head -n 1)"
test_finish ${?}
test_start 'kea_admin_error_reporting_test.db_init.mysql.input'
run_command \
- "${kea_admin}" lease-dump mysql -y --input
+ "${kea_admin}" lease-dump mysql --input
assert_eq 1 "${EXIT_CODE}"
assert_str_eq 'ERROR/kea-admin: -i or --input requires a parameter' "$(printf '%s\n' "${OUTPUT}" | head -n 1)"
test_finish ${?}
test_start 'kea_admin_error_reporting_test.db_init.mysql.o'
run_command \
- "${kea_admin}" lease-dump mysql -y -o
+ "${kea_admin}" lease-dump mysql -o
assert_eq 1 "${EXIT_CODE}"
assert_str_eq 'ERROR/kea-admin: -o or --output requires a parameter' "$(printf '%s\n' "${OUTPUT}" | head -n 1)"
test_finish ${?}
test_start 'kea_admin_error_reporting_test.db_init.mysql.output'
run_command \
- "${kea_admin}" lease-dump mysql -y --output
+ "${kea_admin}" lease-dump mysql --output
assert_eq 1 "${EXIT_CODE}"
assert_str_eq 'ERROR/kea-admin: -o or --output requires a parameter' "$(printf '%s\n' "${OUTPUT}" | head -n 1)"
test_finish ${?}
test_finish 0
}
+# May accept additional parameters to be passed to lease-dump.
mysql_lease4_dump_test() {
- test_start "mysql.lease4_dump_test"
+ test_start "mysql.lease4_dump_test${1-}"
test_dir="@abs_top_srcdir@/src/bin/admin/tests"
output_dir="@abs_top_builddir@/src/bin/admin/tests"
output_file="$output_dir/data/mysql.lease4_dump_test.output.csv"
ref_file="$test_dir/data/lease4_dump_test.reference.csv"
- # Clean up any test files left from prior failed runs.
- rm -f "${output_file}"
+ # Clean up any test files left from prior failed runs unless -y was provided in which case
+ # explicitly create the file to check that it will be automatically deleted.
+ # files should be removed by kea-admin itself.
+ if printf '%s' "${@}" | grep 'y' > /dev/null; then
+ touch "${output_file}"
+ touch "${output_file}.tmp"
+ else
+ rm -f "${output_file}"
+ rm -f "${output_file}.tmp"
+ fi
# Let's wipe the whole database
mysql_wipe
# Ok, now let's initialize the database
run_command \
- "${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
+ "${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 the reference record
# Dump lease4 to output_file
run_command \
- "${kea_admin}" lease-dump mysql -y -4 -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" -o $output_file
+ "${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
test_finish 0
}
+# May accept additional parameters to be passed to lease-dump.
mysql_lease6_dump_test() {
- test_start "mysql.lease6_dump_test"
+ test_start "mysql.lease6_dump_test${1-}"
test_dir="@abs_top_srcdir@/src/bin/admin/tests"
output_dir="@abs_top_builddir@/src/bin/admin/tests"
output_file="$output_dir/data/mysql.lease6_dump_test.output.csv"
ref_file="$test_dir/data/lease6_dump_test.reference.csv"
- # Clean up any test files left from prior failed runs.
- rm -f "${output_file}"
+ # Clean up any test files left from prior failed runs unless -y was provided in which case
+ # explicitly create the file to check that it will be automatically deleted.
+ # files should be removed by kea-admin itself.
+ if printf '%s' "${@}" | grep 'y' > /dev/null; then
+ touch "${output_file}"
+ touch "${output_file}.tmp"
+ else
+ rm -f "${output_file}"
+ rm -f "${output_file}.tmp"
+ fi
# Let's wipe the whole database
mysql_wipe
# Dump lease4 to output_file
run_command \
- "${kea_admin}" lease-dump mysql -y -6 -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" -o $output_file
+ "${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, expected exit code %d, actual %d"
# Compare the dump output to reference file, they should be identical
test_finish 0
}
+# May accept additional parameters to be passed to lease-dump or to lease-upload.
mysql_lease4_upload_test() {
- test_start "mysql.lease4_upload_test"
+ test_start "mysql.lease4_upload_test${1-}"
input_file="@abs_top_srcdir@/src/bin/admin/tests/data/lease4_dump_test.reference.csv"
output_file="@abs_top_srcdir@/src/bin/admin/tests/data/lease4_dump_test.output.csv"
# Wipe the whole database.
mysql_wipe
- # Make sure there's no output file left from previous failures, otherwise
- # kea-admin is going to ask you if you want to overwrite which blocks tests.
- rm -f "${output_file}"
+ # Clean up any test files left from prior failed runs unless -y was provided in which case
+ # explicitly create the file to check that it will be automatically deleted.
+ # files should be removed by kea-admin itself.
+ if printf '%s' "${@}" | grep 'y' > /dev/null; then
+ touch "${input_file}.tmp"
+ touch "${output_file}"
+ touch "${output_file}.tmp"
+ else
+ rm -f "${input_file}.tmp"
+ rm -f "${output_file}"
+ rm -f "${output_file}.tmp"
+ fi
# Initialize the database.
run_command \
# Upload leases.
run_command \
- "${kea_admin}" lease-upload mysql -y -4 -u "${db_user}" \
+ "${kea_admin}" lease-upload mysql -4 -u "${db_user}" \
-p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" \
- -i "${input_file}"
+ -i "${input_file}" "${@}"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-upload -4 failed, expected exit code %d, actual %d"
# Dump leases.
run_command \
- "${kea_admin}" lease-dump mysql -y -4 -u "${db_user}" \
+ "${kea_admin}" lease-dump mysql -4 -u "${db_user}" \
-p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" \
- -o "${output_file}"
+ -o "${output_file}" "${@}"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -4 failed, expected exit code %d, actual %d"
# Compare the initial file used for upload to the file retrieved from dump, they should be identical.
test_finish 0
}
+# May accept additional parameters to be passed to lease-dump or to lease-upload.
mysql_lease6_upload_test() {
- test_start "mysql.lease6_upload_test"
+ test_start "mysql.lease6_upload_test${1-}"
input_file="@abs_top_srcdir@/src/bin/admin/tests/data/lease6_dump_test.reference.csv"
output_file="@abs_top_srcdir@/src/bin/admin/tests/data/lease6_dump_test.output.csv"
# Wipe the whole database.
mysql_wipe
- # Make sure there's no output file left from previous failures, otherwise
- # kea-admin is going to ask you if you want to overwrite which blocks tests.
- rm -f "${output_file}"
+ # Clean up any test files left from prior failed runs unless -y was provided in which case
+ # explicitly create the file to check that it will be automatically deleted.
+ # files should be removed by kea-admin itself.
+ if printf '%s' "${@}" | grep 'y' > /dev/null; then
+ touch "${input_file}.tmp"
+ touch "${output_file}"
+ touch "${output_file}.tmp"
+ else
+ rm -f "${input_file}.tmp"
+ rm -f "${output_file}"
+ rm -f "${output_file}.tmp"
+ fi
# Initialize the database.
run_command \
# Upload leases.
run_command \
- "${kea_admin}" lease-upload mysql -y -6 -u "${db_user}" \
+ "${kea_admin}" lease-upload mysql -6 -u "${db_user}" \
-p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" \
- -i "${input_file}"
+ -i "${input_file}" "${@}"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-upload -6 failed, expected exit code %d, actual %d"
# Dump leases.
run_command \
- "${kea_admin}" lease-dump mysql -y -6 -u "${db_user}" \
+ "${kea_admin}" lease-dump mysql -6 -u "${db_user}" \
-p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" \
- -o "${output_file}"
+ -o "${output_file}" "${@}"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -6 failed, expected exit code %d, actual %d"
# Compare the initial file used for upload to the file retrieved from dump, they should be identical.
mysql_db_version_with_extra_test
mysql_upgrade_test
mysql_lease4_dump_test
+mysql_lease4_dump_test -y
mysql_lease6_dump_test
+mysql_lease6_dump_test -y
mysql_lease4_upload_test
+mysql_lease4_upload_test -y
mysql_lease6_upload_test
-mysql_lease4_stat_test
+mysql_lease6_upload_test -y
mysql_lease6_stat_test
+mysql_lease4_stat_test
mysql_lease_stat_upgrade_test
mysql_lease_stat_recount_test
mysql_unused_subnet_id_test
# determined by querying the PostgreSQL server. This
# updated reference data is captured in a temporary file
# which is used for the actual comparison.
+# May accept additional parameters to be passed to lease-dump.
pgsql_lease4_dump_test() {
test_start "pgsql.lease4_dump_test"
output_file="$output_dir/data/pgsql.lease4_dump_test.output.csv"
ref_file="$test_dir/data/lease4_dump_test.reference.csv"
- # Clean up any test files left from prior failed runs.
- rm -f "${output_file}"
+ # Clean up any test files left from prior failed runs unless -y was provided in which case
+ # explicitly create the file to check that it will be automatically deleted.
+ # files should be removed by kea-admin itself.
+ if printf '%s' "${@}" | grep 'y' > /dev/null; then
+ touch "${output_file}"
+ touch "${output_file}.tmp"
+ else
+ rm -f "${output_file}"
+ rm -f "${output_file}.tmp"
+ fi
# Let's wipe the whole database
pgsql_wipe
# Dump lease4 to output_file
run_command \
- "${kea_admin}" lease-dump pgsql -y -4 -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" -o $output_file
+ "${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, expected exit code %d, actual %d"
# Compare the dump output to reference file, they should be identical
output_file="$output_dir/data/pgsql.lease6_dump_test.output.csv"
ref_file="$test_dir/data/lease6_dump_test.reference.csv"
- # Clean up any test files left from prior failed runs.
- rm -f "${output_file}"
+ # Clean up any test files left from prior failed runs unless -y was provided in which case
+ # explicitly create the file to check that it will be automatically deleted.
+ # files should be removed by kea-admin itself.
+ if printf '%s' "${@}" | grep 'y' > /dev/null; then
+ touch "${output_file}"
+ touch "${output_file}.tmp"
+ else
+ rm -f "${output_file}"
+ rm -f "${output_file}.tmp"
+ fi
# Let's wipe the whole database
pgsql_wipe
# Dump lease6 to output_file
run_command \
- "${kea_admin}" lease-dump pgsql -y -6 -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" -o $output_file
+ "${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, expected exit code %d, actual %d"
# Compare the dump output to reference file, they should be identical
test_finish 0
}
+# May accept additional parameters to be passed to lease-dump or to lease-upload.
pgsql_lease4_upload_test() {
test_start "pgsql.lease4_upload_test"
# Wipe the whole database.
pgsql_wipe
- # Make sure there's no output file left from previous failures, otherwise
- # kea-admin is going to ask you if you want to overwrite which blocks tests.
- rm -f "${output_file}"
+ # Clean up any test files left from prior failed runs unless -y was provided in which case
+ # explicitly create the file to check that it will be automatically deleted.
+ # files should be removed by kea-admin itself.
+ if printf '%s' "${@}" | grep 'y' > /dev/null; then
+ touch "${input_file}.tmp"
+ touch "${output_file}"
+ touch "${output_file}.tmp"
+ else
+ rm -f "${input_file}.tmp"
+ rm -f "${output_file}"
+ rm -f "${output_file}.tmp"
+ fi
# Initialize the database.
run_command \
# Upload leases.
run_command \
- "${kea_admin}" lease-upload pgsql -y -4 -u "${db_user}" \
+ "${kea_admin}" lease-upload pgsql -4 -u "${db_user}" \
-p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" \
- -i "${input_file}"
+ -i "${input_file}" "${@}"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-upload -4 failed, expected exit code %d, actual %d"
# Dump leases.
run_command \
- "${kea_admin}" lease-dump pgsql -y -4 -u "${db_user}" \
+ "${kea_admin}" lease-dump pgsql -4 -u "${db_user}" \
-p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" \
- -o "${output_file}"
+ -o "${output_file}" "${@}"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -4 failed, expected exit code %d, actual %d"
# Compare the initial file used for upload to the file retrieved from dump, they should be identical.
# Wipe the whole database.
pgsql_wipe
- # Make sure there's no output file left from previous failures, otherwise
- # kea-admin is going to ask you if you want to overwrite which blocks tests.
- rm -f "${output_file}"
+ # Clean up any test files left from prior failed runs unless -y was provided in which case
+ # explicitly create the file to check that it will be automatically deleted.
+ # files should be removed by kea-admin itself.
+ if printf '%s' "${@}" | grep 'y' > /dev/null; then
+ touch "${input_file}.tmp"
+ touch "${output_file}"
+ touch "${output_file}.tmp"
+ else
+ rm -f "${input_file}.tmp"
+ rm -f "${output_file}"
+ rm -f "${output_file}.tmp"
+ fi
# Initialize the database.
run_command \
# Upload leases.
run_command \
- "${kea_admin}" lease-upload pgsql -y -6 -u "${db_user}" \
+ "${kea_admin}" lease-upload pgsql -6 -u "${db_user}" \
-p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" \
- -i "${input_file}"
+ -i "${input_file}" "${@}"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-upload -6 failed, expected exit code %d, actual %d"
# Dump leases.
run_command \
- "${kea_admin}" lease-dump pgsql -y -6 -u "${db_user}" \
+ "${kea_admin}" lease-dump pgsql -6 -u "${db_user}" \
-p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}" \
- -o "${output_file}"
+ -o "${output_file}" "${@}"
assert_eq 0 "${EXIT_CODE}" "kea-admin lease-dump -6 failed, expected exit code %d, actual %d"
# Compare the initial file used for upload to the file retrieved from dump, they should be identical.
pgsql_db_version_test
pgsql_upgrade_test
pgsql_lease4_dump_test
+pgsql_lease4_dump_test -y
pgsql_lease6_dump_test
+pgsql_lease6_dump_test -y
pgsql_lease4_upload_test
+pgsql_lease4_upload_test -y
pgsql_lease6_upload_test
+pgsql_lease6_upload_test -y
pgsql_lease4_stat_test
pgsql_lease6_stat_test
pgsql_lease_stat_upgrade_test