mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-19 08:52:15 +00:00
test(xcat-core): the Genesis payload carries no openssl config, so no certificate is requested
A node boots Genesis, prints "Getting initial certificate --> MN:3001" and goes no
further. xcatd records no credential request, the node status stays at powering-on,
and every case that waits for the node fails.
genesis_openssl_config.bats drives each dracut module's install() with the dracut
helpers replaced by a recorder, so it reads what the module asks the payload to carry.
genesis_getcert_missing_openssl.bats gains one case: the give up message must repeat
what openssl printed, because a message naming only certkey.pem sends the reader to a
key that is intact.
Three of the six cases fail on this commit: both module cases, and the message case.
stub_dir defaulted count to the empty string, which left "{ ; exit 1; }" in the
openssl stub. That is a syntax error, so the stub failed for the wrong reason and
reported bash's message instead of openssl's. The default is now a no-op command.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
@@ -24,7 +24,9 @@ write_stub()
|
||||
# A PATH directory holding the commands getcert runs. openssl is absent unless it is asked for.
|
||||
stub_dir()
|
||||
{
|
||||
local with_openssl="${1:-0}" count=""
|
||||
# count defaults to a no-op: an empty value leaves "{ ; exit 1; }", which is a syntax
|
||||
# error, so the stub would fail for the wrong reason and report bash's message.
|
||||
local with_openssl="${1:-0}" count=":"
|
||||
local dir="${BATS_TEST_TMPDIR}/bin"
|
||||
|
||||
rm -rf "$dir"
|
||||
@@ -35,7 +37,7 @@ stub_dir()
|
||||
write_stub "$dir" sleep 'exec /bin/sleep "$@"'
|
||||
if [ "$with_openssl" = 1 ]; then
|
||||
[ -n "${COUNT_REQUESTS:-}" ] && count="echo req >> '$COUNTER'"
|
||||
write_stub "$dir" openssl "[ \"\$1\" = req ] && { $count ; exit 1; }
|
||||
write_stub "$dir" openssl "[ \"\$1\" = req ] && { $count ; echo \"\${OPENSSL_REQ_ERROR:-}\" >&2 ; exit 1; }
|
||||
exit 0"
|
||||
fi
|
||||
printf '%s\n' "$dir"
|
||||
@@ -70,3 +72,13 @@ run_getcert()
|
||||
[ -f "$COUNTER" ] && tries="$(grep -c req "$COUNTER")"
|
||||
[ "$tries" -gt 1 ]
|
||||
}
|
||||
|
||||
@test "the give up message repeats what openssl printed" {
|
||||
# OPENSSLDIR/openssl.cnf is absent more often than the key is broken, and the key is
|
||||
# usually intact. A message that names only certkey.pem sends the reader to the wrong file.
|
||||
export OPENSSL_REQ_ERROR="Can't open \"/usr/lib/ssl/openssl.cnf\" for reading, No such file or directory"
|
||||
run run_getcert "$(stub_dir 1)" 30 5
|
||||
[ "$status" -ne 124 ]
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" == *openssl.cnf* ]]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# The Genesis payload must carry the openssl config file. openssl req reads
|
||||
# OPENSSLDIR/openssl.cnf and exits 1 when it is absent, so getcert makes no certificate
|
||||
# request and the node never reports a destiny.
|
||||
|
||||
load 'helpers/shell_source'
|
||||
|
||||
setup()
|
||||
{
|
||||
HOST_CNF="$(openssl version -d 2>/dev/null | sed -e 's/^OPENSSLDIR: *"*//' -e 's/"*$//')/openssl.cnf"
|
||||
[ -e "$HOST_CNF" ] || skip "this host has no $HOST_CNF to install"
|
||||
export HOST_CNF
|
||||
}
|
||||
|
||||
# Run the module's install() with every dracut helper replaced by a recorder, so the test reads
|
||||
# what the module asks the payload to carry rather than matching the module's source.
|
||||
record_install()
|
||||
{
|
||||
local module="$1" log="$2"
|
||||
: >"$log"
|
||||
(
|
||||
for helper in dracut_install inst inst_simple inst_multiple inst_binary inst_script \
|
||||
inst_symlink inst_dir inst_hook inst_rules instmods; do
|
||||
eval "$helper() { printf '%s\n' \"\$@\" >>'$log'; return 0; }"
|
||||
done
|
||||
# Anything the module calls that this host lacks must not stop install().
|
||||
command_not_found_handle() { return 0; }
|
||||
dfatal() { printf 'dfatal %s\n' "$*" >>"$log"; }
|
||||
moddir="${BATS_TEST_TMPDIR}"; hostonly=''; dracutsysrootdir=''; srcmods=''
|
||||
. "$module" >/dev/null 2>&1 || true
|
||||
install >/dev/null 2>&1 || true
|
||||
)
|
||||
}
|
||||
|
||||
@test "the ubuntu module installs the openssl config its own openssl names" {
|
||||
module="$(repo_path 'xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh')"
|
||||
[ -r "$module" ] || skip "$module is required"
|
||||
record_install "$module" "${BATS_TEST_TMPDIR}/ubuntu.log"
|
||||
[ -s "${BATS_TEST_TMPDIR}/ubuntu.log" ]
|
||||
grep -q "$HOST_CNF" "${BATS_TEST_TMPDIR}/ubuntu.log"
|
||||
}
|
||||
|
||||
@test "the el module installs the openssl config its own openssl names" {
|
||||
module="$(repo_path 'xCAT-genesis-base/dracut_105/el/module-setup.sh')"
|
||||
[ -r "$module" ] || skip "$module is required"
|
||||
record_install "$module" "${BATS_TEST_TMPDIR}/el.log"
|
||||
[ -s "${BATS_TEST_TMPDIR}/el.log" ]
|
||||
grep -q "$HOST_CNF" "${BATS_TEST_TMPDIR}/el.log"
|
||||
}
|
||||
|
||||
@test "openssl itself is still installed, so the config is an addition" {
|
||||
module="$(repo_path 'xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh')"
|
||||
[ -r "$module" ] || skip "$module is required"
|
||||
record_install "$module" "${BATS_TEST_TMPDIR}/u2.log"
|
||||
grep -qx 'openssl' "${BATS_TEST_TMPDIR}/u2.log"
|
||||
}
|
||||
Reference in New Issue
Block a user