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.