Skip to content

Commit

Permalink
fixup! [PR] Fixes #38048 - Add rolling content views
Browse files Browse the repository at this point in the history
* fix bug in Sync/FileUpload triggering repo-refresh
* DRYed code
* tests ;-)
  • Loading branch information
m-bucher committed Dec 2, 2024
1 parent fe2b5b3 commit 4ba6d32
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 25 deletions.
17 changes: 17 additions & 0 deletions app/lib/actions/helpers/rolling_cv_repos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Actions
module Helpers
module RollingCVRepos
def update_rolling_content_views(repo)
concurrence do
repos = repo.root.repositories.in_environment(repo.environment).where(
content_view_version: ::Katello::ContentViewVersion.where(content_view: ::Katello::ContentView.rolling)
)

repos.each do |rolling_repo|
plan_action(::Actions::Katello::ContentView::RefreshRollingRepo, rolling_repo)
end
end
end
end
end
end
10 changes: 3 additions & 7 deletions app/lib/actions/katello/repository/import_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module Actions
module Katello
module Repository
class ImportUpload < Actions::EntryAction
include Helpers::RollingCVRepos

# rubocop:disable Metrics/MethodLength
def plan(repository, uploads, options = {})
action_subject(repository)
Expand Down Expand Up @@ -54,13 +56,7 @@ def plan(repository, uploads, options = {})
plan_self(repository_id: repository.id, sync_capsule: sync_capsule, upload_results: upload_results)

# Refresh rolling CVs that have this repository
repos = repository.root.repositories.in_environment(1).where(content_view_version: ::Katello::ContentViewVersion.where(content_view: ::Katello::ContentView.rolling))

concurrence do
repos.each do |rolling_repo|
plan_action(ContentView::RefreshRollingRepo, rolling_repo)
end
end
update_rolling_content_views(repository)
end
end
# rubocop:enable Metrics/MethodLength
Expand Down
11 changes: 1 addition & 10 deletions app/lib/actions/katello/repository/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Repository
class Sync < Actions::EntryAction
extend ApipieDSL::Class
include Helpers::Presenter
include Helpers::RollingCVRepos
include ::Actions::ObservableAction
middleware.use Actions::Middleware::ExecuteIfContentsChanged

Expand Down Expand Up @@ -111,16 +112,6 @@ def update_deb_content(repo)
metadata_expire: repo.root.metadata_expire)
end

def update_rolling_content_views(repo)
concurrence do
repos = repo.root.repositories.in_environment(1).where(content_view_version: ::Katello::ContentViewVersion.where(content_view: ::Katello::ContentView.rolling))

repos.each do |rolling_repo|
plan_action(ContentView::RefreshRollingRepo, rolling_repo)
end
end
end

def rescue_strategy
Dynflow::Action::Rescue::Skip
end
Expand Down
12 changes: 4 additions & 8 deletions app/lib/actions/katello/repository/upload_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ module Actions
module Katello
module Repository
class UploadFiles < Actions::EntryAction
def plan(repository, files, content_type = nil, options = {}) # rubocop:disable Metrics/MethodLength
include Helpers::RollingCVRepos

def plan(repository, files, content_type = nil, options = {})
action_subject(repository)
repository.check_ready_to_act!
repository.clear_smart_proxy_sync_histories
Expand Down Expand Up @@ -40,13 +42,7 @@ def plan(repository, files, content_type = nil, options = {}) # rubocop:disable
plan_action(Actions::Katello::Applicability::Repository::Regenerate, :repo_ids => [repository.id]) if generate_applicability

# Refresh rolling CVs that have this repository
repos = repository.root.repositories.in_environment(1).where(content_view_version: ::Katello::ContentViewVersion.where(content_view: ::Katello::ContentView.rolling))

concurrence do
repos.each do |rolling_repo|
plan_action(ContentView::RefreshRollingRepo, rolling_repo)
end
end
update_rolling_content_views(repository)
end
ensure
# Delete tmp files when some exception occurred. Would be
Expand Down
75 changes: 75 additions & 0 deletions test/actions/katello/content_view_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,81 @@ class PublishTest < TestBase
end
end

class RefreshRollingRepoTest < TestBase
let(:action_class) { ::Actions::Katello::ContentView::RefreshRollingRepo }
let(:content_view) { katello_content_views(:rolling_view) }
let(:repository_deb) { katello_repositories(:debian_10_amd64) }
let(:library) { katello_environments(:library) }
let(:clone_deb) do
FactoryBot.create :katello_repository,
root: repository_deb.root,
library_instance: repository_deb,
content_view_version: content_view.versions.first,
environment: library
end

before do
repository_deb.version_href = 'foo'
repository_deb.publication_href = 'bar'
repository_deb.save!
clone_deb.save!
end

it 'plans' do
action.stubs(:task).returns(success_task)
refute_equal repository_deb.version_href, clone_deb.version_href

plan_action(action, clone_deb)

assert_action_planned_with action, ::Actions::Pulp3::Repository::RefreshDistribution, clone_deb, SmartProxy.pulp_primary
assert_action_planned_with action, ::Actions::Katello::Repository::IndexContent, id: clone_deb.id, source_repository_id: repository_deb.id
end

it 'triggers with sync' do
sync_action = create_action ::Actions::Katello::Repository::Sync
sync_action.stubs(:task).returns(success_task)

plan_action(sync_action, repository_deb)

assert_action_planned_with sync_action, action_class, clone_deb
end

it 'triggers with upload_files' do
upload_action = create_action ::Actions::Katello::Repository::UploadFiles
upload_action.stubs(:task).returns(success_task)
upload_action.stubs(:prepare_tmp_files).returns([{path: 'some/path'}])

plan_action(upload_action, repository_deb, [{path: 'nowhere'}])

assert_action_planned_with upload_action, action_class, clone_deb
end

it 'triggers with import_upload' do
import_action = create_action ::Actions::Katello::Repository::ImportUpload
import_action.stubs(:task).returns(success_task)
file = File.join(::Katello::Engine.root, 'test', 'fixtures', 'files', 'frigg_1.0_ppc64.deb')
#action.expects(:action_subject).with(custom_repository)

plan_action import_action, repository_deb, [{:path => file, :filename => 'frigg_1.0_ppc64.deb'}]

assert_action_planned_with import_action, action_class, clone_deb
end

it 'updates pulp_hrefs' do
last_changed = DateTime.new(2024, 12, 2.5)
DateTime.stubs(:now).returns(last_changed)
action_class.any_instance.expects(:plan_action).twice

ForemanTasks.sync_task(action_class, clone_deb)

clone_deb.reload
assert_equal repository_deb.version_href, clone_deb.version_href
assert_equal repository_deb.publication_href, clone_deb.publication_href
assert_equal repository_deb.content_id, clone_deb.content_id
assert_equal last_changed, clone_deb.last_contents_changed
end
end

class AddRollingRepoCloneTest < TestBase
let(:action_class) { ::Actions::Katello::ContentView::AddRollingRepoClone }
let(:content_view) { katello_content_views(:rolling_view) }
Expand Down

0 comments on commit 4ba6d32

Please sign in to comment.