2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-09-21 16:39:30 +00:00
Files
xcat-core/xCAT-test/bats/diskless_flat_vmothersetting_machine.bats
T
Daniel Hilst b4735e10e2 test(xcat-core): the machine-type test accepts a cleanup that removes nothing
diskless_flat_vmothersetting_machine.bats checked the restore with a substring
match and checked the cleanup only for the absence of "unary operator
expected". A cleanup that writes the machine type back, or leaves it in place,
passed both.

The test now reads the value chdef receives. The restore must write exactly
machine:<type>, and must keep a setting the node already carries. The cleanup
must write an empty value when the machine type is all there is, and must leave
the other setting behind when there is one. The chdef stub brackets its
arguments so an empty value is not the same as no call.

ppc64le is red on the cleanup: the restore ladder writes
machine:pseries-rhel7.6.0 and the cleanup ladder removes machine:pseries-7.6.0,
so the node keeps the machine type. x86_64 and riscv64 pass.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-09-17 07:35:51 -03:00

103 lines
3.8 KiB
Bash

#!/usr/bin/env bats
#
# reg_linux_diskless_installation_flat corrupts the KVM machine type of the compute node, checks
# that the node fails to boot, and then restores it. The restore reads a machine type from a
# ladder that names ppc64 and x86_64 only, so on any other architecture it writes an empty
# vmothersetting and the check after it fails.
#
# The two commands are lifted out of the case file and RUN, with lsdef and chdef shadowed, so
# the assertions read the value the case would write. The extraction fails the test when it
# stops matching, so a rewrite fails loudly instead of covering nothing.
load 'helpers/shell_source'
setup()
{
CASE="$(repo_path 'xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat')"
[ -r "$CASE" ] || skip "$CASE is required"
export CASE
}
# The command that restores the machine type, and the one that removes it again afterwards.
restore_command()
{
extract_first_matching_line "$CASE" \
'^cmd:.*str2="machine:invalid".*chdef [$][$]CN vmothersetting=[$]str5'
}
remove_command()
{
extract_first_matching_line "$CASE" \
'^cmd:.*str2=";".*~ "ppc64".*chdef [$][$]CN vmothersetting='
}
# Render one command the way xcattest does, then run it with lsdef and chdef shadowed. bash
# resolves a function ahead of PATH, so the case's own backticks read the stub.
#
# Sets OUT to everything the command printed and WRITTEN to the value it gave chdef.
run_case_command()
{
local cmd="$1" arch="$2" lsdef_value="$3"
cmd="${cmd#cmd:}"
cmd="${cmd//__GETNODEATTR(\$\$CN,arch)__/$arch}"
cmd="${cmd//__GETNODEATTR(\$\$CN,mgt)__/kvm}"
cmd="${cmd//\$\$CN/cn1}"
OUT="$(bash -c "lsdef() { echo ' vmothersetting=$lsdef_value'; }
chdef() { echo \"CHDEF:[\$*]\"; }
$cmd" 2>&1)" || true
# The brackets keep an empty value apart from no call at all: the cleanup is meant to write
# an empty vmothersetting, and a command that never reaches chdef must not read as that.
CHDEF_CALLS="$(grep -c '^CHDEF:' <<<"$OUT" || true)"
WRITTEN="$(sed -n 's/^CHDEF:\[cn1 vmothersetting=\(.*\)\]$/\1/p' <<<"$OUT")"
}
# The machine type each architecture must end up with. riscv64 guests run the qemu "virt"
# machine; kvm.pm sets it in guest_arch_profile.
#
# The restore writes the machine type; the cleanup after it takes the same machine type away
# again and leaves every other setting. Both read the same ladder, so both are checked against
# the same value.
assert_arch()
{
local arch="$1" machine="$2" restore remove
restore="$(restore_command)"
remove="$(remove_command)"
# The node carries the corrupt value only.
run_case_command "$restore" "$arch" 'machine:invalid'
[ "$CHDEF_CALLS" -eq 1 ]
[ "$WRITTEN" = "machine:$machine" ]
# The node carries a setting of its own beside the corrupt value.
run_case_command "$restore" "$arch" 'cpumode:host-passthrough;machine:invalid'
[ "$CHDEF_CALLS" -eq 1 ]
[ "$WRITTEN" = "cpumode:host-passthrough;machine:$machine" ]
# The cleanup, with nothing but the machine type to remove.
run_case_command "$remove" "$arch" "machine:$machine"
[ "$(grep -c 'unary operator expected' <<<"$OUT")" -eq 0 ]
[ "$CHDEF_CALLS" -eq 1 ]
[ "$WRITTEN" = "" ]
# The cleanup, with a setting of its own that must survive it.
run_case_command "$remove" "$arch" "cpumode:host-passthrough;machine:$machine"
[ "$(grep -c 'unary operator expected' <<<"$OUT")" -eq 0 ]
[ "$CHDEF_CALLS" -eq 1 ]
[ "$WRITTEN" = "cpumode:host-passthrough" ]
}
@test "ppc64le: the restore writes the machine type and the cleanup takes it away" {
assert_arch ppc64le pseries-rhel7.6.0
}
@test "x86_64: the restore writes the machine type and the cleanup takes it away" {
assert_arch x86_64 pc
}
@test "riscv64: the restore writes the machine type and the cleanup takes it away" {
assert_arch riscv64 virt
}