Skip to content

Commit

Permalink
fixup! [PR] Fixes #38048 - Add rolling content views
Browse files Browse the repository at this point in the history
* Do not show ApplicableErrata on HostDetails page
  for rolling CVs, because for them applicable === installable errata

* Move RollingRepoRefresh from sync into post-finalize async-task

* Add humanized_name to rollingCV refresh

* Fix Regenerate Applicability after RollingCV Refresh
  • Loading branch information
m-bucher committed Feb 21, 2025
1 parent 3940f88 commit 57245ce
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 18 deletions.
18 changes: 13 additions & 5 deletions app/lib/actions/helpers/rolling_cv_repos.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
module Actions
module Helpers
module RollingCVRepos
def concerned_repos(repo)
repo.root.repositories.in_environment(repo.environment).where(
content_view_version: ::Katello::ContentViewVersion.where(content_view: ::Katello::ContentView.rolling)
)
end

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|
concerned_repos(repo).each do |rolling_repo|
plan_action(::Actions::Katello::ContentView::RefreshRollingRepo, rolling_repo)
end
end
end

def update_rolling_content_views_async(repo)
concerned_repos(repo).each do |rolling_repo|
ForemanTasks.async_task(::Actions::Katello::ContentView::RefreshRollingRepo, rolling_repo)
end
end
end
end
end
5 changes: 5 additions & 0 deletions app/lib/actions/katello/content_view/refresh_rolling_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ def plan(repository)
plan_self(repository_id: repository.id)
plan_action(Pulp3::Repository::RefreshDistribution, repository, SmartProxy.pulp_primary)
plan_action(Repository::IndexContent, id: repository.id, source_repository_id: repository.library_instance.id)
plan_action(Actions::Katello::Applicability::Repository::Regenerate, :repo_ids => [repository.id])
end
end

def humanized_name
_('Refresh RollingCV Repo')
end

def run
repository = ::Katello::Repository.find(input[:repository_id])
library_instance = repository.library_instance
Expand Down
7 changes: 5 additions & 2 deletions app/lib/actions/katello/repository/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def plan(repo, options = {})
end
plan_self(:id => repo.id, :sync_result => output, :skip_metadata_check => skip_metadata_check, :validate_contents => validate_contents,
:contents_changed => output[:contents_changed])
update_rolling_content_views(repo)
plan_action(Katello::Repository::SyncHook, :id => repo.id)
end
end
Expand All @@ -71,7 +70,11 @@ def run
end

def finalize
::Katello::Repository.find(input[:id])&.audit_sync
repo = ::Katello::Repository.find(input[:id])
if repo
repo&.audit_sync
update_rolling_content_views_async(repo)
end
end

def humanized_name
Expand Down
42 changes: 32 additions & 10 deletions test/actions/katello/content_view_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,7 @@ class RefreshRollingRepoTest < TestBase

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
assert_action_planned_with action, ::Actions::Katello::Applicability::Repository::Regenerate, repo_ids: [clone_deb.id]
end

it 'triggers with upload_files' do
Expand All @@ -162,7 +154,7 @@ class RefreshRollingRepoTest < TestBase
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
action_class.any_instance.expects(:plan_action).at_least(3)

ForemanTasks.sync_task(action_class, clone_deb)

Expand All @@ -174,6 +166,36 @@ class RefreshRollingRepoTest < TestBase
end
end

class SyncRepositoryRefreshRollingRepoTest < TestBase
let(:action_class) { ::Actions::Katello::Repository::Sync }
let(:content_view) { katello_content_views(:rolling_view) }
let(:repository_rpm) { katello_repositories(:fedora_17_x86_64) }
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

before do
repository_rpm.version_href = 'foo'
repository_rpm.publication_href = 'bar'
repository_rpm.save!
clone_rpm.save!
end

it 'triggers async RefreshRollingRepo' do
action.stubs(:input).returns(
id: clone_rpm.id
)
ForemanTasks.expects(:async_task).with(::Actions::Katello::ContentView::RefreshRollingRepo,
clone_rpm)
action.finalize
end
end

class AddRollingRepoCloneTest < TestBase
let(:action_class) { ::Actions::Katello::ContentView::AddRollingRepoClone }
let(:content_view) { katello_content_views(:rolling_view) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ export const ErrataTab = () => {
) : null;

const hostIsNonLibrary = (
contentFacet?.contentViewDefault === false || contentFacet.lifecycleEnvironmentLibrary === false
(contentFacet?.contentViewDefault === false ||
contentFacet.lifecycleEnvironmentLibrary === false) &&
contentFacet.contentView.rolling === false
);
const toggleGroup = (
<Split hasGutter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const contentFacetAttributes = {
id: 11,
uuid: 'e5761ea3-4117-4ecf-83d0-b694f99b389e',
content_view_default: false,
contentView: {
rolling: false,
},
lifecycle_environment_library: false,
errata_counts: {
total: 3,
Expand Down Expand Up @@ -655,6 +658,35 @@ test('Toggle Group does not show if it\'s the default content view and library e
assertNockRequest(scope, done); // Pass jest callback to confirm test is done
});

test('Toggle Group does not show if it\'s a rolling content view and library environment', async (done) => {
// Setup autocomplete with mockForemanAutoComplete since we aren't adding /katello
const autocompleteScope = mockForemanAutocomplete(nockInstance, autocompleteUrl);
const mockErrata = makeMockErrata({});
const options = renderOptions({
...cfWithErrataTotal(mockErrata.total),
contentView: {
rolling: true,
},
lifecycle_environment_library: true,
});
// return errata data results when we look for errata
const scope = nockInstance
.get(hostErrata)
.query(defaultQuery)
.reply(200, mockErrata);

const {
queryByLabelText,
getAllByText,
} = renderWithRedux(<ErrataTab />, options);

// Assert that the errata are now showing on the screen, but wait for them to appear.
await patientlyWaitFor(() => expect(getAllByText('Important')[0]).toBeInTheDocument());
expect(queryByLabelText('Installable Errata')).not.toBeInTheDocument();
assertNockRequest(autocompleteScope);
assertNockRequest(scope, done); // Pass jest callback to confirm test is done
});

test('Selection is disabled for errata which are applicable but not installable', async (done) => {
// Setup autocomplete with mockForemanAutoComplete since we aren't adding /katello
const autocompleteScope = mockForemanAutocomplete(nockInstance, autocompleteUrl);
Expand Down

0 comments on commit 57245ce

Please sign in to comment.