Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set asset size on job creation #5369

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
my $assets = $schema->resultset('Assets');
my %asset_info = (type => 'iso', name => 'dvdsize42.iso');
$schema->storage->dbh->prepare('delete from assets where name = ? ')->execute('dvdsize42.iso');
is $assets->find(\%asset_info), undef, 'dvdsize42.iso is not known yet';
$scheduled_product = $scheduled_products->create(\%settings);
$scheduled_product->schedule_iso({ISO => 'dvdsize42.iso'});
is $assets->find(\%asset_info)->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!
Loading