Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #32556 - disable scopes on cv promote errata calc #9613

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,12 @@ def rescue_strategy_for_self
end

def finalize
# update errata applicability counts for all hosts in the CV & LE
::Katello::Host::ContentFacet.where(:content_view_id => input[:content_view_id],
:lifecycle_environment_id => input[:environment_id]).each do |facet|
facet.update_applicability_counts
facet.update_errata_status
end
environment = ::Katello::KTEnvironment.find(input[:environment_id])
::Katello::ContentView.find(input[:content_view_id]).update_host_statuses(environment)

history = ::Katello::ContentViewHistory.find(input[:history_id])
history.status = ::Katello::ContentViewHistory::SUCCESSFUL
history.save!
environment = ::Katello::KTEnvironment.find(input[:environment_id])

if !input[:incremental_update] && sync_proxies?(environment)
ForemanTasks.async_task(ContentView::CapsuleSync,
Expand Down
13 changes: 13 additions & 0 deletions app/models/katello/content_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,19 @@ def publish_repositories(override_components = nil)
end
end

def update_host_statuses(environment)
# update errata applicability counts for all hosts in the CV & LE
Location.no_taxonomy_scope do
User.as_anonymous_admin do
::Katello::Host::ContentFacet.where(:content_view_id => self,
:lifecycle_environment_id => environment).each do |facet|
facet.update_applicability_counts
facet.update_errata_status
end
end
end
end

def component_repositories
components.map(&:archived_repos).flatten
end
Expand Down
12 changes: 12 additions & 0 deletions test/models/content_view_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -607,5 +607,17 @@ def test_import_only_immutable
cv.import_only = false
refute cv.valid?
end

def test_update_host_statuses
other_location = taxonomies(:location2)
facet = katello_content_facets(:content_facet_two)

refute_equal facet.host.location, other_location
assert_nothing_raised do
Location.as_taxonomy(facet.host.organization, other_location) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, what does as_taxonomy do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The foreman application has 3 'states' that determine the scope of some query:

User.current
Location.current
Organization.current

(Note that these are Thread local variables, not class variables) These are usually determined by what user is logged in, or the current location or organization that is set. In this case, Location.as_taxonomy() sets the current Location and Organization temporarily within the block of code that is passed. So even if Location.current is set to Location1 (or nil), it will override that and temporarily set Location.current to what is passed in.

facet.content_view.update_host_statuses(facet.lifecycle_environment)
end
end
end
end
end