Hello community, here is the log from the commit of package openQA for openSUSE:Factory checked in at 2018-01-10 23:36:11 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/openQA (Old) and /work/SRC/openSUSE:Factory/.openQA.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "openQA" Wed Jan 10 23:36:11 2018 rev:7 rq:563070 version:4.5.1515509269.fa07a084 Changes: -------- --- /work/SRC/openSUSE:Factory/openQA/openQA.changes 2018-01-09 14:50:48.102529293 +0100 +++ /work/SRC/openSUSE:Factory/.openQA.new/openQA.changes 2018-01-10 23:36:18.804798797 +0100 @@ -1,0 +2,6 @@ +Tue Jan 09 16:08:32 UTC 2018 - co...@suse.com + +- Update to version 4.5.1515509269.fa07a084: + * Remove assets from disk when deleting database entry (#1553) + +------------------------------------------------------------------- Old: ---- openQA-4.5.1513750232.be133588.tar.xz New: ---- openQA-4.5.1515509269.fa07a084.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ openQA.spec ++++++ --- /var/tmp/diff_new_pack.6hLMZu/_old 2018-01-10 23:36:19.852749628 +0100 +++ /var/tmp/diff_new_pack.6hLMZu/_new 2018-01-10 23:36:19.852749628 +0100 @@ -36,7 +36,7 @@ # runtime requirements that also the testsuite needs %define t_requires perl(DBD::Pg) perl(DBIx::Class) perl(Config::IniFiles) perl(SQL::Translator) perl(Date::Format) perl(File::Copy::Recursive) perl(DateTime::Format::Pg) perl(Net::OpenID::Consumer) perl(Mojolicious::Plugin::RenderFile) perl(Mojolicious::Plugin::AssetPack) perl(aliased) perl(Config::Tiny) perl(DBIx::Class::DynamicDefault) perl(DBIx::Class::Schema::Config) perl(DBIx::Class::Storage::Statistics) perl(IO::Socket::SSL) perl(Data::Dump) perl(DBIx::Class::OptimisticLocking) perl(Text::Markdown) perl(Net::DBus) perl(IPC::Run) perl(Archive::Extract) perl(CSS::Minifier::XS) perl(JavaScript::Minifier::XS) perl(Time::ParseDate) perl(Sort::Versions) perl(Mojo::RabbitMQ::Client) perl(BSD::Resource) perl(Cpanel::JSON::XS) Name: openQA -Version: 4.5.1513750232.be133588 +Version: 4.5.1515509269.fa07a084 Release: 0 Summary: The openQA web-frontend, scheduler and tools License: GPL-2.0+ ++++++ openQA-4.5.1513750232.be133588.tar.xz -> openQA-4.5.1515509269.fa07a084.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/openQA-4.5.1513750232.be133588/lib/OpenQA/Schema/Result/Assets.pm new/openQA-4.5.1515509269.fa07a084/lib/OpenQA/Schema/Result/Assets.pm --- old/openQA-4.5.1513750232.be133588/lib/OpenQA/Schema/Result/Assets.pm 2017-12-20 07:10:32.000000000 +0100 +++ new/openQA-4.5.1515509269.fa07a084/lib/OpenQA/Schema/Result/Assets.pm 2018-01-09 15:47:49.000000000 +0100 @@ -117,7 +117,14 @@ use File::Path 'remove_tree'; remove_tree($file) || print "can't remove $file\n"; } +} + +# override to automatically remove the corresponding file from disk when deleteing the database entry +sub delete { + my ($self) = @_; + $self->remove_from_disk; + return $self->SUPER::delete; } sub ensure_size { @@ -380,7 +387,7 @@ ->get_column('id')->as_query; my @pendassets = $app->db->resultset('JobsAssets')->search({job_id => {-in => $pending}})->get_column('asset_id')->all; - my $removes = $app->db->resultset('Assets')->search( + $app->db->resultset('Assets')->search( { -and => [ id => {in => [sort keys %toremove]}, @@ -389,11 +396,7 @@ }, { order_by => qw(t_created) - }); - while (my $a = $removes->next) { - $a->remove_from_disk; - $a->delete; - } + })->delete_all; } # update accumulated sizes in the data base @@ -412,7 +415,6 @@ next if $a->fixed; my $delta = $a->t_created->delta_days(DateTime->now)->in_units('days'); if ($delta >= 14 || $a->ensure_size == 0) { - $a->remove_from_disk; $a->delete; } else { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/openQA-4.5.1513750232.be133588/lib/OpenQA/WebAPI/Controller/API/V1/Asset.pm new/openQA-4.5.1515509269.fa07a084/lib/OpenQA/WebAPI/Controller/API/V1/Asset.pm --- old/openQA-4.5.1513750232.be133588/lib/OpenQA/WebAPI/Controller/API/V1/Asset.pm 2017-12-20 07:10:32.000000000 +0100 +++ new/openQA-4.5.1515509269.fa07a084/lib/OpenQA/WebAPI/Controller/API/V1/Asset.pm 2018-01-09 15:47:49.000000000 +0100 @@ -91,7 +91,7 @@ my $asset = $self->app->schema->resultset("Assets")->search(\%cond, \%attrs); return unless $asset; - my $rs = $asset->delete; + my $rs = $asset->delete_all; $self->emit_event('openqa_asset_delete', \%args); $self->render(json => {count => $rs}); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/openQA-4.5.1513750232.be133588/t/14-grutasks.t new/openQA-4.5.1515509269.fa07a084/t/14-grutasks.t --- old/openQA-4.5.1513750232.be133588/t/14-grutasks.t 2017-12-20 07:10:32.000000000 +0100 +++ new/openQA-4.5.1515509269.fa07a084/t/14-grutasks.t 2018-01-09 15:47:49.000000000 +0100 @@ -47,6 +47,7 @@ # @deleted array sub mock_delete { my ($self) = @_; + $self->remove_from_disk; push @deleted, $self->name; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/openQA-4.5.1513750232.be133588/t/api/02-assets.t new/openQA-4.5.1515509269.fa07a084/t/api/02-assets.t --- old/openQA-4.5.1513750232.be133588/t/api/02-assets.t 2017-12-20 07:10:32.000000000 +0100 +++ new/openQA-4.5.1515509269.fa07a084/t/api/02-assets.t 2018-01-09 15:47:49.000000000 +0100 @@ -26,6 +26,7 @@ use lib "$FindBin::Bin/../lib"; use Test::More; use Test::Mojo; +use Test::MockModule; use Test::Warnings ':all'; use OpenQA::Test::Case; use OpenQA::Client; @@ -56,6 +57,14 @@ return $h; } +# a mock 'delete' method for Assets which does not actually remove the file from the disk +#sub mock_delete { +# my ($self) = @_; +# return $self->SUPER::delete; +#} +#my $module = new Test::MockModule('OpenQA::Schema::Result::Assets'); +#$module->mock(delete => \&mock_delete); + OpenQA::Test::Case->new->init_data; my $t = Test::Mojo->new('OpenQA::WebAPI'); @@ -77,13 +86,21 @@ my $ret; -my $iso1 = 'test-dvd-1.iso'; -my $iso2 = 'test-dvd-2.iso'; +sub iso_path { + my ($iso) = @_; + return "t/data/openqa/share/factory/iso/$iso"; +} -for my $i ($iso1, $iso2) { - ok(open(FH, '>', "t/data/openqa/share/factory/iso/$i"), "touch $i"); - close FH; +sub touch_isos { + my ($isos) = @_; + for my $iso (@$isos) { + ok(open(FH, '>', iso_path($iso)), "touch $iso"); + close FH; + } } +my $iso1 = 'test-dvd-1.iso'; +my $iso2 = 'test-dvd-2.iso'; +touch_isos [$iso1, $iso2]; my $listing = [ { @@ -147,16 +164,20 @@ # verify it's really gone $ret = $t->get_ok('/api/v1/assets/' . $listing->[0]->{id})->status_is(404); +ok(!-e iso_path($iso1), 'iso file 1 has been removed'); # but two must be still there $ret = $t->get_ok('/api/v1/assets/' . $listing->[1]->{id})->status_is(200); +ok(-e iso_path($iso2), 'iso file 2 is still there'); # register it again +touch_isos [$iso1]; $ret = $t->post_ok('/api/v1/assets', form => {type => 'iso', name => $iso1})->status_is(200); is($ret->tx->res->json->{id}, $listing->[1]->{id} + 1, "asset has next id"); # delete by name $ret = $t->delete_ok('/api/v1/assets/iso/' . $iso2)->status_is(200); is($ret->tx->res->json->{count}, 1, "one asset deleted"); +ok(!-e iso_path($iso2), 'iso file 2 has been removed'); # but three must be still there $ret = $t->get_ok('/api/v1/assets/' . ($listing->[1]->{id} + 1))->status_is(200); @@ -181,9 +202,7 @@ $ret = $t->delete_ok('/api/v1/assets/iso/' . $iso1)->status_is(403, 'asset deletion forbidden for operator'); # asset must be still there $ret = $t->get_ok('/api/v1/assets/' . ($listing->[1]->{id} + 1))->status_is(200); - -for my $i ($iso1, $iso2) { - ok(unlink("t/data/openqa/share/factory/iso/$i"), "rm $i"); -} +ok(-e iso_path($iso1), 'iso file 1 is still there'); +ok(unlink(iso_path($iso1)), 'remove iso file 1 manually'); done_testing(); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/openQA-4.5.1513750232.be133588/t/ui/13-admin.t new/openQA-4.5.1515509269.fa07a084/t/ui/13-admin.t --- old/openQA-4.5.1513750232.be133588/t/ui/13-admin.t 2017-12-20 07:10:32.000000000 +0100 +++ new/openQA-4.5.1515509269.fa07a084/t/ui/13-admin.t 2018-01-09 15:47:49.000000000 +0100 @@ -24,6 +24,8 @@ use Mojo::Base -strict; use FindBin; use lib "$FindBin::Bin/../lib"; +use File::Path qw(remove_tree); +use File::Spec::Functions 'catfile'; use Test::More; use Test::Mojo; use Test::Warnings; @@ -531,6 +533,14 @@ 'assets of "assets by group"' ); + # add the file for asset 4 actually in the file system to check deletion + my $asset_path + = catfile($OpenQA::Utils::assetdir, 'iso', 'openSUSE-Factory-staging_e-x86_64-Build87.5011-Media.iso'); + open(my $fh, '>', $asset_path); + print $fh "ISO\n"; + close($fh); + ok(-e $asset_path, 'dummy asset present at ' . $asset_path); + # delete one of the assets $driver->find_element('#asset_4 .name a')->click(); wait_for_ajax; @@ -538,6 +548,9 @@ $driver->get($driver->get_current_url()); wait_for_ajax; is(scalar @{$driver->find_elements('#asset_4')}, 0, 'asset gone forever'); + + ok(!-e $asset_path, 'dummy asset should have been removed'); + unlink($asset_path); }; kill_driver();