From ad528dfee6dd2a66dfffc9baef333dc36a71d9f9 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:02:30 -0300 Subject: [PATCH] test(imgport): cover the node check of an import Import for a defined node and for an undefined one, and check that an undefined node changes nothing. --- xCAT-test/unit/imgport_rootimg_checksum.t | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/xCAT-test/unit/imgport_rootimg_checksum.t b/xCAT-test/unit/imgport_rootimg_checksum.t index b2d90fb52..dece63cd4 100644 --- a/xCAT-test/unit/imgport_rootimg_checksum.t +++ b/xCAT-test/unit/imgport_rootimg_checksum.t @@ -35,6 +35,9 @@ require xCAT::Table; require(repo_path('xCAT-server/lib/xcat/plugins/imgport.pm')); xCAT::Table->new('site', -create => 1)->setAttribs({ key => 'installdir' }, { value => "$fixture/install" }); +# noderange keeps the node list for a few seconds, so the node is defined before the first import. +xCAT::Table->new('nodelist', -create => 1)->setAttribs({ node => 'psnode' }, { groups => 'compute' }); + # The image lock lives in /var/lock/xcat, so the test records the request and decides whether another operation holds it. our ($HELD, @LOCKED); { @@ -71,6 +74,7 @@ sub import_image { @LOCKED = (); my @errors; my $checksum = delete $manifest{rootimgchecksum}; + my $nodes = delete $manifest{nodes}; my $name = "import-$sequence"; xCAT::Table->new('osimage', -create => 1)->setAttribs({ imagename => $name }, { osvers => 'rhels9.5', provmethod => 'netboot' }); my $data = { @@ -81,7 +85,7 @@ sub import_image { (defined $checksum ? (linuximage => { rootimgchecksum => $checksum }) : ()), osimage => { imagename => $name, osvers => 'rhels9.6', osarch => 'x86_64', profile => 'compute', provmethod => 'netboot' }, }; - my $placed = xCAT_plugin::imgport::place_image($data, $bundle, sub { push @errors, @{ $_[0]{error} || [] } }); + my $placed = xCAT_plugin::imgport::place_image($data, $bundle, sub { push @errors, @{ $_[0]{error} || [] } }, $nodes); return ($placed, join("\n", @errors), $dest, "$dest/$archive_name"); } @@ -172,4 +176,19 @@ for my $failed (qw(rootimg.cpio.gz.sha256 rootimg.cpio.gz)) { 'the marker of the bundled initial ramdisk is placed next to it'); } +for my $nodes (qw(psnode undefined-node)) { + # The nodes that get the postscripts of the image exist, or not. + my ($placed, $errors, $dest, $archive) = import_image('rootimg.cpio.gz', undef, nodes => $nodes); + if ($nodes eq 'psnode') { + is($errors, '', 'an import for a defined node is placed'); + is(read_binary($archive), $imported, 'the image of an import for a defined node is published'); + next; + } + ok(!$placed, 'an import for an undefined node fails'); + like($errors, qr/The nodes undefined-node are not defined in xCAT DB\./, 'the undefined node is reported'); + is(read_binary($archive), $published, 'the published image stays for an undefined node'); + is(read_binary("$dest/kernel"), "published kernel\n", 'the published kernel stays for an undefined node'); + is(definition($dest), 'rhels9.5', 'the image definition stays for an undefined node'); +} + done_testing();