From 27e01fbd742daa79dff36cf1cea1ee22a2ec1b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Sun, 11 Oct 2026 00:28:27 -0300 Subject: [PATCH] test(packimage): match the held publication lock by holder and recovery The publication lock moves to a helper that imgimport also uses, and its message will name both commands. Match the holder and the recovery step of the message instead of the command name. The test also made publication fail with a directory in place of the previous metainfo. Publication will move that metainfo aside, which works for a directory. Make rename and unlink of that path fail instead. --- xCAT-test/unit/packimage_atomic_archive.t | 34 +++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/xCAT-test/unit/packimage_atomic_archive.t b/xCAT-test/unit/packimage_atomic_archive.t index d31dabec5..8d42e6a23 100644 --- a/xCAT-test/unit/packimage_atomic_archive.t +++ b/xCAT-test/unit/packimage_atomic_archive.t @@ -11,9 +11,34 @@ use File::Slurper qw(read_binary write_text); use File::Temp qw(tempdir); use POSIX (); use Sys::Hostname qw(hostname); +use Errno qw(EIO); use Test::More; use XCAT::Test::File qw(repo_path); +# A rename or unlink of a path in %FAIL_FROM fails, as when the file system refuses it. +our %FAIL_FROM; +BEGIN { + *CORE::GLOBAL::rename = sub { + my ($from, $to) = @_; + if ($FAIL_FROM{$from}) { + $! = EIO; + return 0; + } + return CORE::rename($from, $to); + }; + *CORE::GLOBAL::unlink = sub { + my $removed = 0; + foreach my $path (@_ ? @_ : ($_)) { + if ($FAIL_FROM{$path}) { + $! = EIO; + next; + } + $removed += CORE::unlink($path); + } + return $removed; + }; +} + plan skip_all => 'packimage packs real archives with Linux tools' unless $^O eq 'linux'; local $ENV{PATH} = "$ENV{PATH}:/usr/sbin:/sbin"; @@ -302,7 +327,7 @@ SKIP: { write_text("$dest/.packimage-publish/owner", "other.host 4242\n"); utime(time() - 120, time() - 120, "$dest/.packimage-publish") or die $!; my ($result, $errors) = packimage($dest, '-m', 'cpio', '-c', 'gzip', $name); - like($errors, qr/\Q$dest\E\/\.packimage-publish is held by other\.host 4242\. If no packimage of this image runs on any host, remove it/, + like($errors, qr/\Q$dest\E\/\.packimage-publish is held by other\.host 4242\. If no .+ of this image runs on any host, remove it/, "$label: the failure names the holder and the recovery"); is(content($archive), "previous archive\n", "$label: the previous archive stays"); is(content("$dest/rootimg.previous"), "previous format\n", "$label: other formats stay"); @@ -347,19 +372,18 @@ SCRIPT { my ($name, $dest, $archive) = image('cpio', 'gzip', 'gzip', 'pass'); - my $label = 'previous metainfo that cannot be removed'; + my $label = 'previous metainfo that cannot be replaced'; write_text("$dest/bin/ctorrent", <<"SCRIPT"); #!/bin/sh while [ \$# -gt 1 ]; do [ "\$1" = -s ] && out=\$2; shift; done echo new metainfo > "\$out" SCRIPT chmod 0755, "$dest/bin/ctorrent"; - unlink("$archive.metainfo") or die $!; - make_path("$archive.metainfo/held"); + local %FAIL_FROM = ("$archive.metainfo" => 1); my (undef, $errors) = packimage($dest, '-m', 'cpio', '-c', 'gzip', '--tracker', 'http://tracker.example:6969/announce', $name); like($errors, qr/Cannot publish \Q$archive\E: /, "$label: the failure is reported"); is(content($archive), "previous archive\n", "$label: the previous archive stays"); - ok(-d "$archive.metainfo/held", "$label: the previous metainfo stays"); + is(content("$archive.metainfo"), "previous metainfo\n", "$label: the previous metainfo stays"); is(content("$dest/rootimg.previous"), "previous format\n", "$label: other formats stay"); is_deeply([ glob("$dest/.packimage-$host+*") ], [], "$label: no temporary file is left"); }