From 7c930bee9d33c4e3dff9e711a7101473a4d5d09b 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 23:10:23 -0300 Subject: [PATCH] test(imgport): cover the image lock of a statelite import A statelite import must ask for the lock of its image directory. While another command holds the lock, the import must fail, report the lock, leave the tree in the bundle, and keep the image definition. --- xCAT-test/unit/imgport_rootimg_checksum.t | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/xCAT-test/unit/imgport_rootimg_checksum.t b/xCAT-test/unit/imgport_rootimg_checksum.t index c550a1742..d264bcf78 100644 --- a/xCAT-test/unit/imgport_rootimg_checksum.t +++ b/xCAT-test/unit/imgport_rootimg_checksum.t @@ -70,11 +70,12 @@ sub import_image { write_text("$dest/initrd-stateless.gz", "published ramdisk\n"); write_text("$bundle/kernel", "kernel from the bundle\n"); write_text("$bundle/initrd-stateless.gz", "ramdisk from the bundle\n"); - $prepare->($dest) if $prepare; + $prepare->($dest, $bundle) if $prepare; @LOCKED = (); my @errors; my $checksum = delete $manifest{rootimgchecksum}; my $nodes = delete $manifest{nodes}; + my $omit = delete $manifest{omit} || []; my $name = "import-$sequence"; xCAT::Table->new('osimage', -create => 1)->setAttribs({ imagename => $name }, { osvers => 'rhels9.5', provmethod => 'netboot' }); my $data = { @@ -85,6 +86,7 @@ sub import_image { (defined $checksum ? (linuximage => { rootimgchecksum => $checksum }) : ()), osimage => { imagename => $name, osvers => 'rhels9.6', osarch => 'x86_64', profile => 'compute', provmethod => 'netboot' }, }; + delete @{$data}{@$omit}; my $placed = xCAT_plugin::imgport::place_image($data, $bundle, sub { push @errors, @{ $_[0]{error} || [] } }, $nodes); return ($placed, join("\n", @errors), $dest, "$dest/$archive_name"); } @@ -128,6 +130,22 @@ for my $archive_name (qw(rootimg.cpio.gz rootimg.tar.xz rootimg.sfs)) { is(definition($dest), 'rhels9.5', 'the image definition stays while the image lock is held'); } +{ + # A statelite bundle has a rootimgtree and no rootimg, and its import needs the image lock too. + local $HELD = 1; + my $tree; + my ($placed, $errors, $dest) = import_image('rootimg.cpio.gz', sub { + my (undef, $bundle) = @_; + $tree = "$bundle/rootimgtree.gz"; + write_text($tree, "tree from the bundle\n"); + }, rootimgtree => 'DEST/rootimgtree.gz', omit => [qw(rootimg kernel ramdisk)]); + ok(!$placed, 'a statelite import fails while another command holds the image lock'); + like($errors, qr/failed to acquire lock/, 'the held image lock is reported for a statelite import'); + is_deeply(\@LOCKED, ["$dest/rootimg"], 'a statelite import asks for the lock of its image directory'); + ok(-e $tree, 'the tree stays in the bundle while the lock is held'); + is(definition($dest), 'rhels9.5', 'the image definition stays while the lock of a statelite image is held'); +} + { my ($placed, $errors, $dest, $archive) = import_image('rootimg.cpio.gz', sub { my ($dest) = @_;