From 9c2e733b990b2677cda46fec3af7f2c5d5cf9b39 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Wed, 23 Sep 2026 10:07:16 -0300 Subject: [PATCH] fix(xcatdsklspost): the diskful cleanup deleted a diskless node's postscripts site.cleanupdiskfullxcatpost names the node type it applies to, and site.5.rst says "on the diskfull nodes". xcatdsklspost serves every type: updatenode calls it for a diskless or statelite node as well, and the site value is one row that reaches all of them. With cleanupdiskfullxcatpost=yes and cleanupxcatpost=no, append_xcatpost_cleanup still appended the delete for those nodes. The diskful branch now reads NODESETSTATE from the generated mypostscript and appends nothing for netboot or statelite. That is the signal remoteshell, hardeths, configeth, otherpkgs and servicenode already use for this question, and mypostscript.tmpl exports it. cleanupxcatpost is unchanged. It names no node type and keeps applying to every one, which xcatdsklspost_xcatpost_cleanup.bats now asserts so a guard added to the wrong branch shows up. Four cases cover it: a netboot node and a statelite node keep their postscripts, a diskful node is still cleaned, and cleanupxcatpost still empties a netboot node. The first two fail against the parent commit. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../bats/xcatdsklspost_xcatpost_cleanup.bats | 49 +++++++++++++++++++ xCAT/postscripts/xcatdsklspost | 11 ++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/xCAT-test/bats/xcatdsklspost_xcatpost_cleanup.bats b/xCAT-test/bats/xcatdsklspost_xcatpost_cleanup.bats index b6658dcd4..60c95ed51 100644 --- a/xCAT-test/bats/xcatdsklspost_xcatpost_cleanup.bats +++ b/xCAT-test/bats/xcatdsklspost_xcatpost_cleanup.bats @@ -98,6 +98,55 @@ append_cleanup() [ ! -e "$XCATPOST/setroute" ] } +# cleanupdiskfullxcatpost names the node type it applies to. updatenode calls this script for a +# diskless or statelite node as well, and the site value is one row that reaches all of them, so +# without a guard a diskless node loses its postscripts to a setting that does not name it. +@test "a netboot node keeps its postscripts when site.cleanupdiskfullxcatpost is set" { + make_xcatpost + make_mypostscript 0 "NODESETSTATE='netboot'" "CLEANUPDISKFULLXCATPOST='yes'" + append_cleanup + + run bash "$MYPS" + [ "$status" -eq 0 ] + [ -f "$XCATPOST/setroute" ] + [ -f "$XCATPOST/_xcat/postscript.cfg" ] + # Nothing was appended, so the run cannot report a cleanup it did not do. + refute_grep -q 'cleanup of .* completed' "$MSGLOG" +} + +@test "a statelite node keeps its postscripts when site.cleanupdiskfullxcatpost is set" { + make_xcatpost + make_mypostscript 0 "NODESETSTATE='statelite'" "CLEANUPDISKFULLXCATPOST='yes'" + append_cleanup + + run bash "$MYPS" + [ "$status" -eq 0 ] + [ -f "$XCATPOST/setroute" ] +} + +@test "a diskful node is still cleaned when site.cleanupdiskfullxcatpost is set" { + make_xcatpost + make_mypostscript 0 "NODESETSTATE='install'" "CLEANUPDISKFULLXCATPOST='yes'" + append_cleanup + + run bash "$MYPS" + [ "$status" -eq 0 ] + [ ! -e "$XCATPOST/setroute" ] + [ -f "$XCATPOST/updateflag.awk" ] +} + +# site.cleanupxcatpost names no node type, so it keeps applying to every one. A guard added to the +# wrong branch would show up here. +@test "site.cleanupxcatpost still applies to a netboot node" { + make_xcatpost + make_mypostscript 0 "NODESETSTATE='netboot'" "CLEANUPXCATPOST='yes'" + append_cleanup + + run bash "$MYPS" + [ "$status" -eq 0 ] + [ -z "$(ls -A "$XCATPOST")" ] +} + @test "site.cleanupxcatpost removes every file including updateflag.awk" { make_xcatpost make_mypostscript 0 "CLEANUPXCATPOST='yes'" "CLEANUPDISKFULLXCATPOST='no'" diff --git a/xCAT/postscripts/xcatdsklspost b/xCAT/postscripts/xcatdsklspost index c725a80b0..ffd209849 100755 --- a/xCAT/postscripts/xcatdsklspost +++ b/xCAT/postscripts/xcatdsklspost @@ -236,6 +236,12 @@ parsehttpserver () # after a failed run, so the postscripts stay on the node for diagnosis. # xcatinstallpost applies the same rule at install time. # +# cleanupdiskfullxcatpost names the node type it applies to, and this script serves +# every type: updatenode calls it for a diskless or statelite node as well. The site +# value is one row and reaches all of them, so the diskful branch reads NODESETSTATE +# and does nothing for netboot or statelite. cleanupxcatpost carries no such word and +# keeps applying everywhere. +# # $1 - path of the generated mypostscript # $2 - the xcatpost directory to remove the postscripts from ##################################################### @@ -253,8 +259,11 @@ append_xcatpost_cleanup() echo "rm -rf $postdir/*" >> "$mypostscript" fi + local nodesetstate + nodesetstate=`grep '^NODESETSTATE=' "$mypostscript" |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z` cleanupdiskfullxcatpost=`grep CLEANUPDISKFULLXCATPOST= "$mypostscript" |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z` - if [[ "$cleanupdiskfullxcatpost" =~ ^(1|yes|y)$ ]]; then + if [[ "$cleanupdiskfullxcatpost" =~ ^(1|yes|y)$ ]] \ + && [ "$nodesetstate" != "netboot" ] && [ "$nodesetstate" != "statelite" ]; then # post.xcat and the other install scripts embed this whole file in a here-document # that ends at a line "EOF". A line "EOF" here ends that here-document early and # leaves the rest of this file as shell code in the generated install script.