-
Notifications
You must be signed in to change notification settings - Fork 297
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 #36878 - Override host bulk destroy #10782
Merged
jeremylenz
merged 5 commits into
Katello:master
from
jeremylenz:36878-override-bulk-host-delete
Nov 7, 2023
Merged
Fixes #36878 - Override host bulk destroy #10782
jeremylenz
merged 5 commits into
Katello:master
from
jeremylenz:36878-override-bulk-host-delete
Nov 7, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jeremylenz
force-pushed
the
36878-override-bulk-host-delete
branch
from
November 1, 2023 18:23
aa9eb4b
to
0adc3fd
Compare
jeremylenz
force-pushed
the
36878-override-bulk-host-delete
branch
from
November 1, 2023 18:29
0adc3fd
to
0ad763c
Compare
parthaa
approved these changes
Nov 2, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
APJ
jeremylenz
force-pushed
the
36878-override-bulk-host-delete
branch
from
November 3, 2023 20:36
83d3337
to
a4c7889
Compare
Please remove From 392797402ad34213ace9ac571dcde08a06db0050 Mon Sep 17 00:00:00 2001
From: Partha Aji <[email protected]>
Date: Fri, 3 Nov 2023 16:44:49 -0400
Subject: [PATCH] more
more
---
.../v2/content_view_versions_controller.rb | 2 +-
.../api/v2/hosts_bulk_actions_controller.rb | 2 +-
.../concerns/api/v2/bulk_hosts_extensions.rb | 47 -------------------
.../katello/remote_execution_controller.rb | 2 +-
.../v2/concerns/bulk_hosts_extensions_test.rb | 2 +-
...bulk_actions_controller_extensions_test.rb | 7 +--
6 files changed, 8 insertions(+), 54 deletions(-)
delete mode 100644 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
diff --git a/app/controllers/katello/api/v2/content_view_versions_controller.rb b/app/controllers/katello/api/v2/content_view_versions_controller.rb
index 662292d13d..851813dccb 100644
--- a/app/controllers/katello/api/v2/content_view_versions_controller.rb
+++ b/app/controllers/katello/api/v2/content_view_versions_controller.rb
@@ -1,6 +1,6 @@
module Katello
class Api::V2::ContentViewVersionsController < Api::V2::ApiController
- include Concerns::Api::V2::BulkHostsExtensions
+ include ::Api::V2::BulkHostsExtension
include Katello::Concerns::FilteredAutoCompleteSearch
before_action :find_authorized_katello_resource, :only => [:show, :update, :promote, :destroy, :republish_repositories]
diff --git a/app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb b/app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb
index c63c2a96e1..155646db65 100644
--- a/app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb
+++ b/app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb
@@ -1,7 +1,7 @@
module Katello
# this is Katello's host bulk actions controller, not to be confused with Foreman's
class Api::V2::HostsBulkActionsController < Api::V2::ApiController
- include Concerns::Api::V2::BulkHostsExtensions
+ include ::Api::V2::BulkHostsExtension
include Katello::Concerns::Api::V2::ContentOverridesController
include Katello::ContentSourceHelper
include ::Foreman::Renderer::Scope::Macros::Base
diff --git a/app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb b/app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
deleted file mode 100644
index a90b7a2d6b..0000000000
--- a/app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-module Katello
- module Concerns
- module Api::V2::BulkHostsExtensions
- extend ActiveSupport::Concern
-
- def bulk_hosts_relation(permission, org)
- relation = ::Host::Managed.authorized(permission)
- relation = relation.where(organization: org) if org
- relation
- end
-
- def find_bulk_hosts(permission, bulk_params, restrict_to = nil)
- #works on a structure of param_group bulk_params and transforms it into a list of systems
- bulk_params[:included] ||= {}
- bulk_params[:excluded] ||= {}
-
- if !params[:install_all] && bulk_params[:included][:ids].blank? && bulk_params[:included][:search].nil?
- fail HttpErrors::BadRequest, _("No hosts have been specified.")
- end
-
- find_organization
- @hosts = bulk_hosts_relation(permission, @organization)
-
- if bulk_params[:included][:ids].present?
- @hosts = @hosts.where(id: bulk_params[:included][:ids])
- end
-
- if bulk_params[:included][:search].present?
- @hosts = @hosts.search_for(bulk_params[:included][:search])
- end
-
- @hosts = restrict_to.call(@hosts) if restrict_to
-
- if bulk_params[:excluded][:ids].present?
- @hosts = @hosts.where.not(id: bulk_params[:excluded][:ids])
- end
- fail HttpErrors::Forbidden, _("No hosts matched search, or action unauthorized for selected hosts.") if @hosts.empty?
-
- @hosts
- end
-
- def find_organization
- @organization ||= Organization.find_by_id(params[:organization_id])
- end
- end
- end
-end
diff --git a/app/controllers/katello/remote_execution_controller.rb b/app/controllers/katello/remote_execution_controller.rb
index 08b61ea550..909e2b54dc 100644
--- a/app/controllers/katello/remote_execution_controller.rb
+++ b/app/controllers/katello/remote_execution_controller.rb
@@ -1,7 +1,7 @@
module Katello
if Katello.with_remote_execution?
class RemoteExecutionController < JobInvocationsController
- include Concerns::Api::V2::BulkHostsExtensions
+ include ::Api::V2::BulkHostsExtension
include Concerns::Api::V2::HostErrataExtensions
def new
diff --git a/test/controllers/api/v2/concerns/bulk_hosts_extensions_test.rb b/test/controllers/api/v2/concerns/bulk_hosts_extensions_test.rb
index 5de02ac5a6..be23dce337 100644
--- a/test/controllers/api/v2/concerns/bulk_hosts_extensions_test.rb
+++ b/test/controllers/api/v2/concerns/bulk_hosts_extensions_test.rb
@@ -4,7 +4,7 @@ require "katello_test_helper"
module Katello
class TestController
- include Concerns::Api::V2::BulkHostsExtensions
+ include ::Api::V2::BulkHostsExtension
def initialize(params = {})
@params = params
diff --git a/test/controllers/api/v2/hosts_bulk_actions_controller_extensions_test.rb b/test/controllers/api/v2/hosts_bulk_actions_controller_extensions_test.rb
index cc2ff2fbd7..a18a51ad75 100644
--- a/test/controllers/api/v2/hosts_bulk_actions_controller_extensions_test.rb
+++ b/test/controllers/api/v2/hosts_bulk_actions_controller_extensions_test.rb
@@ -3,9 +3,10 @@ require 'katello_test_helper'
module Katello
# testing Katello's overrides of Foreman's HostsBulkActionsController
class Api::V2::HostsBulkActionsControllerExtensionsTest < ActionController::TestCase
+ tests ::Api::V2::HostsBulkActionsController
def setup
- @host1 = FactoryBot.create(:host, :with_subscription, :with_content, :organization => @view.organization, :content_view => @view, :lifecycle_environment => @library)
- @host2 = FactoryBot.create(:host, :with_subscription, :with_content, :organization => @view.organization, :content_view => @view, :lifecycle_environment => @library)
+ @host1 = hosts(:one)
+ @host2 = hosts(:two)
end
def test_bulk_destroy
@@ -14,4 +15,4 @@ module Katello
assert_response :success
end
end
-end
+end
\ No newline at end of file
--
2.41.0 |
jeremylenz
force-pushed
the
36878-override-bulk-host-delete
branch
from
November 6, 2023 18:49
38bd882
to
bcd4478
Compare
looks like tests will be failing until the Foreman PR is merged, since that's what adds |
[test katello] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What are the changes introduced in this pull request?
We're adding bulk host deletion to the Foreman V2 API, to support the new All Hosts index page. Need to add overrides to Katello to ensure hosts are unregistered and artifacts are properly destroyed.
Also includes some misc. items:
Considerations taken when implementing this change?
What are the testing steps for this pull request?
Check out theforeman/foreman#9878
Delete some hosts and ensure they're properly unregistered and artifacts removed (content facet, etc. -check registration_manager.rb#remove_host_artifacts)