From 2737df4adf274c6bf64ba588bf2feafa499178db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saray=20Cabrera=20Padr=C3=B3n?= Date: Thu, 10 Dec 2020 17:04:39 +0100 Subject: [PATCH] Delay cleanup of maintenance release repositories After accepting maintenance release requests, the corresponding published repositories were removed immediately. This broke some automated maintenance tests because the repositories were removed before the tests finished. We have moved the cleanup to a delayed job, so the repositories will be removed some specific time after they are published. --- .../app/jobs/published_repositories_cleanup_job.rb | 6 ++++++ .../models/bs_request_action_maintenance_release.rb | 11 +++++++++-- src/api/config/options.yml.example | 4 ++++ src/api/test/functional/maintenance_test.rb | 6 +++++- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/api/app/jobs/published_repositories_cleanup_job.rb diff --git a/src/api/app/jobs/published_repositories_cleanup_job.rb b/src/api/app/jobs/published_repositories_cleanup_job.rb new file mode 100644 index 00000000000..cb071f9f7a6 --- /dev/null +++ b/src/api/app/jobs/published_repositories_cleanup_job.rb @@ -0,0 +1,6 @@ +class PublishedRepositoriesCleanupJob < ApplicationJob + def perform(source_project_name) + # cleanup published binaries to save disk space on ftp server and mirrors + Backend::Api::Build::Project.wipe_published_locked(source_project_name) + end +end diff --git a/src/api/app/models/bs_request_action_maintenance_release.rb b/src/api/app/models/bs_request_action_maintenance_release.rb index e63c831e2c3..dbb6bc131c2 100644 --- a/src/api/app/models/bs_request_action_maintenance_release.rb +++ b/src/api/app/models/bs_request_action_maintenance_release.rb @@ -59,8 +59,7 @@ def per_request_cleanup(opts) next if cleaned_projects[sprj] - # cleanup published binaries to save disk space on ftp server and mirrors - Backend::Api::Build::Project.wipe_published_locked(sprj) + maintenance_release_cleanup(sprj) cleaned_projects[sprj] = 1 end opts[:projectCommit] = {} @@ -169,6 +168,14 @@ def sanity_check! end end + # Delaying removal of published repositories for accepted maintenance release requests, + # gives some margin to the automated maintenance tests to be finished. + def maintenance_release_cleanup(project_name) + delay = CONFIG['maintenance_release_repositories_lifetime'] + set_options = delay ? { wait: delay.seconds } : {} + PublishedRepositoriesCleanupJob.set(set_options).perform_later(project_name) + end + #### Alias of methods end diff --git a/src/api/config/options.yml.example b/src/api/config/options.yml.example index 4c918b54fb4..accdde3e0d2 100644 --- a/src/api/config/options.yml.example +++ b/src/api/config/options.yml.example @@ -204,6 +204,10 @@ default: &default # icon: sponsor_abc # url: https://www.example.com + # Lifetime for repositories published after accepting maintenance release requests. + # Default: 2 days (172800 seconds). + # maintenance_release_repositories_lifetime: 172800 + production: <<: *default diff --git a/src/api/test/functional/maintenance_test.rb b/src/api/test/functional/maintenance_test.rb index 50362855321..c46ca560d99 100644 --- a/src/api/test/functional/maintenance_test.rb +++ b/src/api/test/functional/maintenance_test.rb @@ -901,6 +901,10 @@ def test_manual_branch_with_extend_names end def test_create_maintenance_project_and_release_packages + # FIXME: https://github.com/rails/rails/issues/37270 + (ActiveJob::Base.descendants << ActiveJob::Base).each(&:disable_test_adapter) + ActiveJob::Base.queue_adapter = :inline + # Backup system("for i in #{Rails.root}/tmp/backend_data/projects/BaseDistro2.0.pkg/*.rev; do cp $i $i.backup; done") # the birthday of J.K. @@ -1471,7 +1475,7 @@ def test_create_maintenance_project_and_release_packages run_scheduler('i586') run_scheduler('x86_64') run_publisher - # published binaries from incident got removed? + # Check that the job removed the published binaries get "/published/#{incident_project}/BaseDistro3/i586/package-1.0-1.i586.rpm" assert_response 404 get "/published/#{incident_project}/BaseDistro2.0_LinkedUpdateProject/x86_64/package-1.0-1.x86_64.rpm"