From bff1e7ea93d4b87be6c2b423efcd0fc22b060cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Sat, 24 Oct 2026 01:15:01 -0300 Subject: [PATCH] test(genesis): cover the UUID that discovery reports dodiscovery runs in a private namespace with a fixed product_uuid and stubbed hardware and transport commands. The test reads the UUID from the discovery request that the script sends and expects product_uuid unchanged. Before the fix the request held the UUID with its first three fields swapped. (cherry picked from commit 21762f21526e0ba71fb3b9a6d3ec314e59feb101) --- xCAT-test/bats/README.md | 12 ++-- xCAT-test/bats/genesis_discovery_uuid.bats | 69 ++++++++++++++++++++++ 2 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 xCAT-test/bats/genesis_discovery_uuid.bats diff --git a/xCAT-test/bats/README.md b/xCAT-test/bats/README.md index de452fe90e..bb7df37734 100644 --- a/xCAT-test/bats/README.md +++ b/xCAT-test/bats/README.md @@ -69,14 +69,16 @@ reap children created by deliberate-fault tests. ## Genesis sandbox prerequisites -`genesis_bmcsetup_users.bats` and `genesis_getadapter.bats` run the complete -checkout scripts with private filesystem, process, and network namespaces. -They replace hardware and transport commands, not the scripts under test. -The fixtures do not contact a BMC or transmit an adapter request. +`genesis_bmcsetup_users.bats`, `genesis_getadapter.bats` and +`genesis_discovery_uuid.bats` run the complete checkout scripts with private +filesystem, process, and network namespaces. They replace hardware and +transport commands, not the scripts under test. The fixtures do not contact a +BMC or transmit an adapter or discovery request. These tests require Linux, bats-core 1.4 or newer, Bubblewrap, Bash, GNU core utilities, awk, grep, sed, and user namespace support. The adapter tests also -require `cmp` from diffutils. The CI environment provides these dependencies. +require `cmp` from diffutils, and the discovery test requires gzip. The CI +environment provides these dependencies. Missing prerequisites fail on Linux; non-Linux hosts report a skip. The temporary filesystem must allow executable files. diff --git a/xCAT-test/bats/genesis_discovery_uuid.bats b/xCAT-test/bats/genesis_discovery_uuid.bats new file mode 100644 index 0000000000..28eae58f5b --- /dev/null +++ b/xCAT-test/bats/genesis_discovery_uuid.bats @@ -0,0 +1,69 @@ +#!/usr/bin/env bats + +load 'helpers/genesis_sandbox' + +setup() +{ + setup_genesis_sandbox dodiscovery + local fips library + fips=$(repo_path xCAT-genesis-scripts/usr/lib/xcat/fips.sh) + [ -r "$fips" ] + type -P gzip >/dev/null || { + echo 'Install gzip to read the discovery request' >&2 + return 1 + } + dmi="$fixture/sys/devices/virtual/dmi/id" + mkdir -p "$dmi" "$fixture/real" + printf 'Example Server\n' >"$dmi/product_name" + printf 'Example Inc.\n' >"$dmi/sys_vendor" + printf 'EX0001\n' >"$dmi/product_serial" + printf 'xcatd=192.0.2.1:3001\n' >"$fixture/cmdline" + cp -L "$(PATH=/usr/bin:/bin type -P sleep)" "$fixture/real/sleep" + printf '#!/bin/sh\nexit 0\n' >"$fixture/bin/minixcatd.awk" + printf '#!/bin/sh\nexit 0\n' >"$fixture/bin/logger" + printf '#!/bin/sh\nexit 0\n' >"$fixture/bin/ip" + printf '#!/bin/sh\nexit 1\n' >"$fixture/bin/ipmitool" + cat >"$fixture/bin/openssl" <<'SH' +#!/bin/sh +case "$1" in + dgst) printf 'signature\n' >"$4" ;; + enc) printf 'c2lnbmF0dXJl\n' ;; + *) printf 'fixture-public-key\n' ;; +esac +SH + cat >"$fixture/bin/udpcat.awk" <<'SH' +#!/bin/sh +cat >/run/fixture/sent.tmp +mv /run/fixture/sent.tmp /run/fixture/sent.gz +SH + # The discovery loop sends again until /restart exists, so the pause after the first send ends it. + cat >"$fixture/bin/sleep" <<'SH' +#!/bin/sh +tries=0 +while [ ! -s /run/fixture/sent.gz ] && [ "$tries" -lt 1000 ]; do + /run/fixture/real/sleep 0.01 + tries=$((tries + 1)) +done +kill -TERM "$PPID" +SH + chmod +x "$fixture/bin/"* + sandbox+=(--tmpfs /usr/lib) + for library in /usr/lib/*; do + [ "${library##*/}" = xcat ] && continue + sandbox+=(--ro-bind "$library" "$library") + done + sandbox+=(--ro-bind "$fips" /usr/lib/xcat/fips.sh) +} + +reported_uuids() +{ + gzip -dc "$fixture/sent.gz" | sed -n 's|^\(.*\)$|\1|p' +} + +@test 'discovery reports the system UUID that the kernel prints' { + printf '12345678-1234-4bcd-9876-1234567890ab\n' >"$dmi/product_uuid" + run_genesis 143 + run reported_uuids + [ "$status" -eq 0 ] + [ "$output" = '12345678-1234-4bcd-9876-1234567890ab' ] +}