mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-10-02 00:41:42 +00:00
test(xcat-core): nodepurge leaves the autoinstall directory of an Ubuntu node
nodepurge removes the autoinstall configuration of each node it deletes. The cleanup loop was inline in the nodepurge sub of profilednodes.pm, which no test can load, so the loop moves to xCAT::ProfiledNodeUtils->remove_node_config_files with its behaviour unchanged. nodepurge_autoinst_cleanup.t drives that routine against a scratch directory. It fails here: the Subiquity node keeps its directory, and the preseed file and the .pre and .post scripts are removed. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
@@ -1585,3 +1585,29 @@ 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);
|
||||
unlink $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
Reference in New Issue
Block a user