Skip to content

Commit

Permalink
Merge pull request #5220 from perlpunk/symlink-assets
Browse files Browse the repository at this point in the history
Do not hardlink symlink assets
  • Loading branch information
mergify[bot] committed Jun 23, 2023
2 parents 7f0df1e + 2cde027 commit e11feac
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
12 changes: 9 additions & 3 deletions lib/OpenQA/Worker/Engines/isotovideo.pm
Expand Up @@ -176,10 +176,16 @@ sub _link_asset ($asset, $pooldir) {
# Try to use hardlinks first and only fall back to symlinks when that fails,
# to ensure that assets cannot be purged early from the pool even if the
# cache service runs out of space
eval { link($asset, $target) or die qq{Cannot create link from "$asset" to "$target": $!} };
if (my $err = $@) {
# If the given asset is a symlink itself, do not hardlink a symlink
my $linked = 0;
unless (-l $asset) {
$linked = eval { link($asset, $target) or die qq{Cannot create link from "$asset" to "$target": $!} };
if (my $err = $@) {
log_debug(qq{Symlinking asset because hardlink failed: $err}); # uncoverable statement
}
}
unless ($linked) {
symlink($asset, $target) or die qq{Cannot create symlink from "$asset" to "$target": $!};
log_debug(qq{Symlinked asset because hardlink failed: $err});
}
log_debug(qq{Linked asset "$asset" to "$target"});

Expand Down
26 changes: 19 additions & 7 deletions t/24-worker-engine.t
Expand Up @@ -428,21 +428,33 @@ subtest 'behavior with ABSOLUTE_TEST_CONFIG_PATHS=1' => sub {
};
};

subtest 'symlink asset' => sub {
subtest 'link asset' => sub {
my $pool_directory = tempdir('poolXXXX');
my $worker = OpenQA::Test::FakeWorker->new(pool_directory => $pool_directory);
my $client = Test::FakeClient->new;
my $settings
= {JOBTOKEN => 'token000', ISO => 'openSUSE-13.1-DVD-x86_64-Build0091-Media.iso', HDD_1 => 'foo.qcow2'};
my $settings = {
JOBTOKEN => 'token000',
ISO => 'openSUSE-13.1-DVD-x86_64-Build0091-Media.iso',
HDD_1 => 'foo.qcow2',
HDD_2 => 'symlink.qcow2',
};
my $job = OpenQA::Worker::Job->new($worker, $client, {id => 16, settings => $settings});
combined_like { my $result = _run_engine($job) }
qr/Linked asset/, 'linked asset';
my $vars_data = get_job_json_data($pool_directory);
ok(-e "$pool_directory/openSUSE-13.1-DVD-x86_64-Build0091-Media.iso", 'the iso is symlinked to pool directory');
ok(-e "$pool_directory/foo.qcow2", 'the hdd is symlinked to pool directory');
my $orig_hdd = locate_asset('hdd', 'foo.qcow2');
my $orig_iso = locate_asset('iso', 'openSUSE-13.1-DVD-x86_64-Build0091-Media.iso');
my $linked_iso = "$pool_directory/openSUSE-13.1-DVD-x86_64-Build0091-Media.iso";
my $linked_hdd = "$pool_directory/foo.qcow2";
my $linked_hdd2 = "$pool_directory/symlink.qcow2";
ok -e $linked_iso, 'the iso is linked to pool directory';
ok -e $linked_hdd, 'the hdd is linked to pool directory';
ok -l $linked_hdd2, 'the hdd 2 is symlinked to pool directory';
is((stat $linked_hdd)[1], (stat $orig_hdd)[1], 'hdd is hardlinked');
is((stat $linked_iso)[1], (stat $orig_iso)[1], 'iso is hardlinked');
is $vars_data->{ISO}, 'openSUSE-13.1-DVD-x86_64-Build0091-Media.iso',
'the value of ISO is basename when doing symlink';
is $vars_data->{HDD_1}, 'foo.qcow2', 'the value of HDD_1 is basename when doing symlink';
'the value of ISO is basename when doing link';
is $vars_data->{HDD_1}, 'foo.qcow2', 'the value of HDD_1 is basename when doing link';
};

done_testing();
1 change: 1 addition & 0 deletions t/data/openqa/share/factory/hdd/symlink.qcow2

0 comments on commit e11feac

Please sign in to comment.