Skip to content

Commit

Permalink
Set asset size on job creation
Browse files Browse the repository at this point in the history
Assets without a size are treated like they don't exist. With POST isos,
referenced assets don't directly get a size and are thus not shown as
downloadable. Only the next limit_assets task run changes this by running
refresh_assets. Improve this by setting the size for assets on job creation.
  • Loading branch information
Vogtinator committed Nov 22, 2023
1 parent 34068e3 commit 9eab53e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/OpenQA/Schema/Result/ScheduledProducts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ sub _schedule_iso {
for my $asset (values %{parse_assets_from_settings($args)}) {
my ($name, $type) = ($asset->{name}, $asset->{type});
return {error => 'Asset type and name must not be empty.'} unless $name && $type;
return {error => "Failed to register asset $name."} unless $assets->register($type, $name, {missing_ok => 1});
return {error => "Failed to register asset $name."}
unless $assets->register($type, $name, {missing_ok => 1, refresh_size => 1});
}

# read arguments for deprioritization and obsoleten
Expand Down
11 changes: 11 additions & 0 deletions t/39-scheduled_products-table.t
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ subtest 'handling assets with invalid name' => sub {

is $scheduled_product->schedule_iso(\%settings), undef, 'scheduling the same product again prevented';

subtest 'asset registration on scheduling' => sub {
$schema->storage->dbh->prepare('delete from assets where name = ? ')->execute('dvdsize42.iso');
is $schema->resultset('Assets')->find({type => 'iso', name => 'dvdsize42.iso'}), undef,
'dvdsize42.iso is not known yet';
$scheduled_product = $scheduled_products->create(\%settings);
$scheduled_product->schedule_iso({ISO => 'dvdsize42.iso'});
is $schema->resultset('Assets')->find({type => 'iso', name => 'dvdsize42.iso'})->size, 42,
'dvdsize42.iso has known size';
$scheduled_product->discard_changes;
};

my $test_job = $scheduled_product->jobs->create({TEST => 'testjob'});
subtest 'cancellation after product has been scheduled' => sub {
is $scheduled_product->cancel('test reason 1'), 1, 'cancel returns the number of affected jobs';
Expand Down
1 change: 1 addition & 0 deletions t/data/openqa/share/factory/iso/dvdsize42.iso
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this asset file is exactly 42 bytes long!

0 comments on commit 9eab53e

Please sign in to comment.