2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-09-30 14:55:16 +00:00

Merge pull request #7890 from VersatusHPC/fix/nodepurge-leaves-autoinst-directory

fix(xcat-core): nodepurge leaves the autoinstall directory of an Ubuntu node
This commit is contained in:
Daniel Hilst
2026-09-30 06:24:57 -03:00
committed by GitHub
3 changed files with 75 additions and 14 deletions
+34 -1
View File
@@ -4,7 +4,7 @@ package xCAT::ProfiledNodeUtils;
use strict;
use warnings;
use Socket;
use File::Path qw/mkpath/;
use File::Path qw/mkpath rmtree/;
use File::Temp qw/tempfile/;
use Fcntl qw(:flock);
require xCAT::Table;
@@ -1585,3 +1585,36 @@ sub cal_netboot {
return 0;
}
}
#-------------------------------------------------------------------------------
=head3 remove_node_config_files
Description : Remove the autoinstall configuration of each node in a list.
Arguments : $config_dir - the autoinstall directory, normally /install/autoinst
$nodes - reference to the list of node names
Returns : N/A
Example :
xCAT::ProfiledNodeUtils->remove_node_config_files("/install/autoinst", \@nodes);
=cut
#-------------------------------------------------------------------------------
sub remove_node_config_files {
my $class = shift;
my $config_dir = shift;
my $nodes = shift;
foreach my $one_node (@$nodes) {
foreach my $suffix ("", ".pre", ".post") {
my $path = "$config_dir/$one_node$suffix";
next unless (-e $path);
# mkinstall writes a directory here for a Subiquity node, with meta-data,
# user-data and vendor-data in it. unlink cannot remove a directory.
if (-d $path) {
rmtree($path);
} else {
unlink $path;
}
}
}
}
+1 -13
View File
@@ -735,20 +735,8 @@ Usage:
$warnstr .= "Details: $retstrref->[1]";
}
}
# For each node in the noderange remove its configureation files in $config_dir, if file exists
setrsp_progress("Removing configuration files...");
my $config_dir = "/install/autoinst/";
foreach my $one_node (@$nodes) {
if ( -e "$config_dir/$one_node") {
unlink "$config_dir/$one_node";
}
if ( -e "$config_dir/$one_node.post") {
unlink "$config_dir/$one_node.post";
}
if ( -e "$config_dir/$one_node.pre") {
unlink "$config_dir/$one_node.pre";
}
}
xCAT::ProfiledNodeUtils->remove_node_config_files("/install/autoinst", $nodes);
setrsp_progress("Removed all nodes.");
setrsp_success($nodes, $warnstr);
}
@@ -0,0 +1,40 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Path qw(mkpath);
use File::Slurper qw(write_text);
use File::Temp qw(tempdir);
use FindBin;
use Test::More;
use lib "$FindBin::Bin/../../perl-xCAT";
use xCAT::ProfiledNodeUtils;
# nodepurge deletes the autoinstall configuration of each node it removes. mkinstall writes that
# configuration as a directory for a Subiquity node and as a plain file for preseed and kickstart,
# so the cleanup must remove both shapes.
my $dir = tempdir(CLEANUP => 1);
# A Subiquity node: cloud-init files in a directory named after the node.
mkpath("$dir/subiquitynode");
write_text("$dir/subiquitynode/$_", "x\n") for qw(meta-data user-data vendor-data);
# A preseed node: a plain file, with its .pre and .post scripts.
write_text("$dir/$_", "x\n") for qw(preseednode preseednode.pre preseednode.post);
# othernode is not in the node list, so the routine must leave it alone.
write_text("$dir/othernode", "x\n");
# neverinstalled has no configuration at all, so the routine must not die on it.
xCAT::ProfiledNodeUtils->remove_node_config_files(
$dir, ['subiquitynode', 'preseednode', 'neverinstalled']);
ok(!-e "$dir/subiquitynode", 'the autoinstall directory of a Subiquity node is removed');
ok(!-e "$dir/preseednode", 'the autoinstall file of a preseed node is removed');
ok(!-e "$dir/preseednode.pre", 'the .pre script of a preseed node is removed');
ok(!-e "$dir/preseednode.post", 'the .post script of a preseed node is removed');
ok(-e "$dir/othernode", 'a node outside the node list keeps its configuration');
done_testing();