Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ds-identify: Improve ds-identify testing flexibility #5047

Merged
merged 4 commits into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion tools/ds-identify
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ PATH_SYS_CLASS_BLOCK=${PATH_SYS_CLASS_BLOCK:-${PATH_ROOT}/sys/class/block}
PATH_DEV_DISK="${PATH_DEV_DISK:-${PATH_ROOT}/dev/disk}"
PATH_VAR_LIB_CLOUD="${PATH_VAR_LIB_CLOUD:-${PATH_ROOT}/var/lib/cloud}"
PATH_DI_CONFIG="${PATH_DI_CONFIG:-${PATH_ROOT}/etc/cloud/ds-identify.cfg}"
PATH_DI_ENV="${PATH_DI_ENV:-${PATH_ROOT}/usr/libexec/ds-identify-env}"
PATH_PROC_CMDLINE="${PATH_PROC_CMDLINE:-${PATH_ROOT}/proc/cmdline}"
PATH_PROC_1_CMDLINE="${PATH_PROC_1_CMDLINE:-${PATH_ROOT}/proc/1/cmdline}"
PATH_PROC_1_ENVIRON="${PATH_PROC_1_ENVIRON:-${PATH_ROOT}/proc/1/environ}"
Expand Down Expand Up @@ -1894,6 +1895,16 @@ set_run_path() {
DI_LOG="${DI_LOG:-${PATH_RUN_CI}/ds-identify.log}"
}

# set ds-identify internal variables by providing an env file
# testing only - NOT use for production code, it is NOT supported
get_environment() {
if [ -f "$PATH_DI_ENV" ]; then
debug 0 "WARN: loading environment file [${PATH_DI_ENV}]";
# shellcheck source=/dev/null
. "$PATH_DI_ENV"
fi
}

_main() {
local dscheck_fn="" ret_dis=1 ret_en=0

Expand Down Expand Up @@ -2020,6 +2031,7 @@ _main() {

main() {
local ret=""
get_environment
ensure_sane_path
read_uname_info
set_run_path
Expand Down Expand Up @@ -2049,7 +2061,14 @@ noop() {
:
}

get_environment
case "${DI_MAIN}" in
# builtin DI_MAIN implementations
main|print_info|noop) "${DI_MAIN}" "$@";;
*) error "unexpected value for DI_MAIN"; exit 1;;

# side-load an alternate implementation
# testing only - NOT use for production code, it is NOT supported
*)
debug 0 "WARN: side-loading alternate implementation: [${DI_MAIN}]";
exec "${DI_MAIN}" "$@";;
esac
Loading