Skip to content

Commit

Permalink
fixup! Fixes #38048 - Add rolling content views
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bucher committed Nov 28, 2024
1 parent aebf0e5 commit 02cc0ec
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ def plan(content_view, repository_ids)
concurrence do
::Katello::Repository.where(id: repository_ids).each do |repository|
sequence do
clone = repository.build_clone(content_view: content_view, environment: library)
clone.save!
clone = content_view.get_repo_clone(library, repository).first
if clone.nil?
clone = repository.build_clone(content_view: content_view, environment: library)
clone.save!
end
plan_action(RefreshRollingRepo, clone)

view_env_cp_id = content_view.content_view_environment(library).cp_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def plan(repository)
sequence do
plan_self(repository_id: repository.id)
plan_action(Pulp3::Repository::RefreshDistribution, repository, SmartProxy.pulp_primary)
plan_action(Repository::IndexContent, id: repository.id)
plan_action(Repository::IndexContent, id: repository.id, source_repository_id: repository.library_instance.id)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ def plan(content_view, repository_ids)
concurrence do
::Katello::Repository.where(id: repository_ids).each do |repository|
clone_repo = content_view.get_repo_clone(library, repository).first
next if clone_repo.nil?

clone_repo_ids << clone_repo.id
plan_action(Candlepin::Environment::SetContent, content_view, library, content_view.content_view_environment(library))
plan_action(Actions::Pulp3::Repository::DeleteDistributions, clone_repo.id, SmartProxy.pulp_primary)
end
plan_action(Candlepin::Environment::SetContent, content_view, library, content_view.content_view_environment(library))
end
plan_self(repository_ids: clone_repo_ids)
end
Expand Down
9 changes: 9 additions & 0 deletions app/lib/actions/katello/repository/import_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ def plan(repository, uploads, options = {})
plan_action(Katello::Repository::MetadataGenerate, repository, force_publication: true) if generate_metadata
plan_action(Actions::Katello::Applicability::Repository::Regenerate, :repo_ids => [repository.id]) if generate_applicability
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
end
end
# rubocop:enable Metrics/MethodLength
Expand Down
2 changes: 2 additions & 0 deletions app/models/katello/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@ def environmental_instances(view)
def archived_instance
if self.environment_id.nil? || self.library_instance_id.nil?
self
elsif self.content_view.rolling?
self.library_instance
else
self.content_view_version.archived_repos.where(:root_id => self.root_id).first
end
Expand Down
138 changes: 120 additions & 18 deletions test/actions/katello/content_view_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,130 @@ class PublishTest < TestBase
class AddRollingRepoCloneTest < TestBase
let(:action_class) { ::Actions::Katello::ContentView::AddRollingRepoClone }
let(:content_view) { katello_content_views(:rolling_view) }
let(:repository) { katello_repositories(:fedora_17_x86_64) }
let(:repository_rpm) { katello_repositories(:fedora_17_x86_64) }
let(:repository_deb) { katello_repositories(:debian_10_amd64) }
let(:library) { katello_environments(:library) }
let(:clone_rpm) do
FactoryBot.create :katello_repository,
root: repository_rpm.root,
content_view_version: content_view.versions.first,
environment: library
end
let(:clone_deb) do
FactoryBot.create :katello_repository,
root: repository_deb.root,
content_view_version: content_view.versions.first,
environment: library
end
let(:cv_env) { content_view.content_view_environment(library) }

before do
Dynflow::Testing::DummyPlannedAction.any_instance.stubs(:repository_mapping).returns({})
[repository_rpm, repository_deb].each do |repository|
repository.version_href = 'foo'
repository.publication_href = 'bar'
repository.save!
end
end
it 'plans' do

it 'plans multiple' do
action.stubs(:task).returns(success_task)
repository.version_href = 'foo'
repository.publication_href = 'bar'
repository.save!

clone = Katello::Repository.new(
library_instance: repository,
root: repository.root,
content_view_version: content_view.versions.first,
environment: library,
relative_path: 'some_unique_path'
)
Katello::Repository.any_instance.expects(:build_clone).returns(clone)
plan_action(action, content_view, [repository.id])

assert_action_planned_with action, ::Actions::Katello::ContentView::RefreshRollingRepo, clone

Katello::Repository.any_instance.expects(:build_clone).returns(clone_deb)
Katello::Repository.any_instance.expects(:build_clone).returns(clone_rpm)
plan_action(action, content_view, [repository_rpm.id, repository_deb.id])

assert_action_planned_with action, ::Actions::Katello::ContentView::RefreshRollingRepo, clone_rpm
assert_action_planned_with action, ::Actions::Katello::ContentView::RefreshRollingRepo, clone_deb

assert_action_planned_with action, ::Actions::Candlepin::Environment::AddContentToEnvironment,
view_env_cp_id: cv_env.cp_id, content_id: repository_rpm.content_id
assert_action_planned_with action, ::Actions::Candlepin::Environment::AddContentToEnvironment,
view_env_cp_id: cv_env.cp_id, content_id: repository_deb.content_id
end

it 'plan refresh for existing' do
clone_deb.library_instance = repository_deb
clone_deb.version_href = 'some_version'
clone_deb.publication_href = 'some_publication'
clone_deb.save!

refute_equal repository_deb.version_href, clone_deb.version_href
refute_equal repository_deb.publication_href, clone_deb.publication_href
# double-add
plan_action(action, content_view, [repository_deb.id])

assert_equal 1, content_view.get_repo_clone(library, repository_deb).count
assert_action_planned_with action, ::Actions::Katello::ContentView::RefreshRollingRepo, clone_deb
assert_action_planned_with action, ::Actions::Candlepin::Environment::AddContentToEnvironment,
view_env_cp_id: cv_env.cp_id, content_id: repository_deb.content_id
end

it 'plans nothing' do
plan_action(action, content_view, [])

refute_action_planned action, ::Actions::Katello::ContentView::RefreshRollingRepo
refute_action_planned action, ::Actions::Candlepin::Environment::AddContentToEnvironment
end
end

class RemoveRollingRepoCloneTest < TestBase
let(:action_class) { ::Actions::Katello::ContentView::RemoveRollingRepoClone }
let(:content_view) { katello_content_views(:rolling_view) }
let(:repository_rpm) { katello_repositories(:fedora_17_x86_64) }
let(:repository_deb) { katello_repositories(:debian_10_amd64) }
let(:library) { katello_environments(:library) }
let(:clone_rpm) do
FactoryBot.create :katello_repository,
root: repository_rpm.root,
library_instance: repository_rpm,
content_view_version: content_view.versions.first,
environment: library
end
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
let(:primary) { SmartProxy.pulp_primary }

before do
[repository_rpm, repository_deb].each do |repository|
repository.version_href = 'foo'
repository.publication_href = 'bar'
repository.save!
end
end

it 'plans remove multiple' do
clone_rpm.save!
clone_deb.save!

plan_action(action, content_view, [repository_rpm.id, repository_deb.id])

assert_action_planned_with action, ::Actions::Pulp3::Repository::DeleteDistributions, clone_rpm.id, primary
assert_action_planned_with action, ::Actions::Pulp3::Repository::DeleteDistributions, clone_deb.id, primary

cv_env = content_view.content_view_environment(library)
assert_action_planned_with action, ::Actions::Candlepin::Environment::SetContent, content_view, library, cv_env
end

it 'plan ignores gone repo' do
clone_rpm.destroy

plan_action(action, content_view, [repository_rpm.id])

refute_action_planned action, ::Actions::Pulp3::Repository::DeleteDistributions

cv_env = content_view.content_view_environment(library)
assert_action_planned_with action, ::Actions::Candlepin::Environment::SetContent, content_view, library, cv_env
end

it 'plans nothing' do
plan_action(action, content_view, [])
refute_action_planned action, ::Actions::Pulp3::Repository::DeleteDistributions
assert_action_planned action, ::Actions::Candlepin::Environment::SetContent
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/factories/content_view_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
trait :import_only do
import_only { true }
end

trait :rolling do
rolling { true }
end
end
end
6 changes: 5 additions & 1 deletion webpack/scenes/ContentViews/Details/ContentViewDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ export default () => {
<FlexItem>
<TextContent>
<Text ouiaId="cv-details-header-name" component={TextVariants.h1}>
<ContentViewIcon count={truncate(name)} composite={composite} rolling={rolling} />
<ContentViewIcon
count={truncate(name)}
composite={composite}
rolling={rolling}
/>
</Text>
</TextContent>
</FlexItem>
Expand Down

0 comments on commit 02cc0ec

Please sign in to comment.