From 0beb6ece16dc5a7140b49883df06f74e2c28f072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 13 Oct 2026 15:29:27 -0300 Subject: [PATCH] test(packimage): cover an image directory with a space The removal of abandoned stages, a publication that removes the other archive formats, and rmimage must work in an image directory with a space. A directory or file that the first word of its path names must stay. --- xCAT-test/unit/rmimage_image_files.t | 20 ++++++++++++++++++++ xCAT-test/unit/svrutils_publish_rootimg.t | 23 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/xCAT-test/unit/rmimage_image_files.t b/xCAT-test/unit/rmimage_image_files.t index db5b953fb..646f479a2 100644 --- a/xCAT-test/unit/rmimage_image_files.t +++ b/xCAT-test/unit/rmimage_image_files.t @@ -65,4 +65,24 @@ ok(!-e "$dir/.packimage-$host+KEEPPREV", 'a temporary directory that keeps the p ok(!-e "$dir/.rootimg-previous-KEPTARCH", 'a previous archive that a failed publication kept is removed with the image'); ok(-e "$dir/notes.txt", 'a file that is not part of the image stays'); +{ + # The image directory has a space, and the first word of its path names another directory, which stays. + my $spaced = "$fixture/install/netboot/custom images/lite"; + make_path("$spaced/rootimg/etc", "$spaced/.rootimg-previous-KEPTARCH", "$fixture/install/netboot/custom/keep"); + write_text("$spaced/$_", "$_\n") for qw(rootimg.cpio.gz rootimg-statelite.gz.sha256); + xCAT::Table->new('osimage')->setAttribs({ imagename => 'spaced' }, + { osvers => 'rhels9.6', osarch => 'x86_64', profile => 'compute', provmethod => 'statelite' }); + xCAT::Table->new('linuximage')->setAttribs({ imagename => 'spaced' }, { rootimgdir => $spaced }); + my @spaced_responses; + { + no warnings 'once'; + local %::XCATSITEVALS = (installdir => "$fixture/install", tftpdir => "$fixture/tftpboot"); + xCAT_plugin::rmimage::process_request({ arg => ['spaced'] }, sub { push @spaced_responses, @_ }, sub { }); + } + is(join("\n", map { @{ $_->{error} || [] } } @spaced_responses), '', 'rmimage of an image directory with a space reports no error'); + ok(!-e "$spaced/rootimg.cpio.gz" && !-e "$spaced/rootimg-statelite.gz.sha256", 'the archives of the image directory with a space are removed'); + ok(!-e "$spaced/.rootimg-previous-KEPTARCH", 'a kept previous archive of the image directory with a space is removed'); + ok(-d "$fixture/install/netboot/custom/keep", 'the directory that the first word of the image directory names stays'); +} + done_testing(); diff --git a/xCAT-test/unit/svrutils_publish_rootimg.t b/xCAT-test/unit/svrutils_publish_rootimg.t index b8237d597..c609e1244 100644 --- a/xCAT-test/unit/svrutils_publish_rootimg.t +++ b/xCAT-test/unit/svrutils_publish_rootimg.t @@ -283,4 +283,27 @@ for my $failed ('rootimg.cpio.gz', 'rootimg.cpio.gz.metainfo') { is(read_binary("$dir/rootimg.cpio.gz.sha256"), "checksum of v1\n", 'the previous checksum content goes back instead'); } +{ + # glob splits a pattern at a space, so the first word of an image directory with a space named another path. + my $dir = "$fixture/custom images/node"; + make_path("$fixture/custom/keep", $dir); + my ($stage) = xCAT::SvrUtils->rootimg_stage($dir); + my $path = "$stage"; + $stage->unlink_on_destroy(0); + undef $stage; + xCAT::SvrUtils->remove_abandoned_rootimg_stages($dir); + ok(!-e $path, 'an abandoned stage in an image directory with a space is removed'); + ok(-d "$fixture/custom/keep", 'the directory that the first word of the image directory names stays'); + + $dir = "$fixture/other images/node"; + make_path("$dir/.stage"); + write_text("$fixture/other", "file that the first word of the image directory names\n"); + write_text("$dir/rootimg.tar.xz", "archive in another format\n"); + write_text("$dir/.stage/rootimg.cpio.gz", "new archive\n"); + is(xCAT::SvrUtils->publish_rootimg("$dir/.stage/rootimg.cpio.gz", "$dir/rootimg.cpio.gz", 1), undef, + 'an archive is published in an image directory with a space'); + ok(!-e "$dir/rootimg.tar.xz", 'the archive in another format is removed from the image directory with a space'); + ok(-e "$fixture/other", 'the file that the first word of the image directory names stays'); +} + done_testing();