Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #22909 - Remove subscriptions from upstream allocation
- Loading branch information
Showing
12 changed files
with
184 additions
and
5 deletions.
There are no files selected for viewing
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
22 changes: 22 additions & 0 deletions
22
app/lib/actions/katello/upstream_subscriptions/remove_entitlement.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Actions | ||
module Katello | ||
module UpstreamSubscriptions | ||
class RemoveEntitlement < Actions::Base | ||
middleware.use Actions::Middleware::KeepCurrentTaxonomies | ||
middleware.use Actions::Middleware::PropagateCandlepinErrors | ||
|
||
input_format do | ||
param :entitlement_id | ||
end | ||
|
||
def run | ||
output[:response] = ::Katello::Resources::Candlepin::UpstreamConsumer.remove_entitlement(input[:entitlement_id]) | ||
end | ||
|
||
def run_progress_weight | ||
0.01 | ||
end | ||
end | ||
end | ||
end | ||
end |
35 changes: 35 additions & 0 deletions
35
app/lib/actions/katello/upstream_subscriptions/remove_entitlements.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Actions | ||
module Katello | ||
module UpstreamSubscriptions | ||
class RemoveEntitlements < Actions::Base | ||
middleware.use Actions::Middleware::KeepCurrentTaxonomies | ||
|
||
def plan(pool_ids = []) | ||
ids = pool_ids.uniq.compact | ||
fail _("No pool IDs were provided.") if ids.blank? | ||
fail _("Current organization is not set.") unless ::Organization.current | ||
|
||
sequence do | ||
ids.each do |pid| | ||
pool = ::Katello::Pool.find(pid) | ||
|
||
fail("Provided pool with id #{pid} has no upstream entitlement") if pool.upstream_entitlement_id.nil? | ||
|
||
plan_action(::Actions::Katello::UpstreamSubscriptions::RemoveEntitlement, entitlement_id: pool.upstream_entitlement_id) | ||
end | ||
|
||
plan_action(::Actions::Katello::Organization::ManifestRefresh, ::Organization.current) | ||
end | ||
end | ||
|
||
def humanized_name | ||
N_("Delete Upstream Subscription") | ||
end | ||
|
||
def rescue_strategy | ||
Dynflow::Action::Rescue::Skip | ||
end | ||
end | ||
end | ||
end | ||
end |
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
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
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
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
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
18 changes: 18 additions & 0 deletions
18
test/actions/katello/upstream_subscriptions/remove_entitlement_test.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'katello_test_helper' | ||
|
||
describe ::Actions::Katello::UpstreamSubscriptions::RemoveEntitlement do | ||
include Dynflow::Testing | ||
|
||
subject { described_class } | ||
|
||
before :all do | ||
@org = FactoryBot.create(:katello_organization) | ||
set_organization(@org) | ||
@planned_action = create_and_plan_action(subject, org_id: @org.id, entitlement_id: 'foo') | ||
end | ||
|
||
it 'runs' do | ||
::Katello::Resources::Candlepin::UpstreamConsumer.expects(:remove_entitlement).with('foo') | ||
run_action @planned_action | ||
end | ||
end |
52 changes: 52 additions & 0 deletions
52
test/actions/katello/upstream_subscriptions/remove_entitlements_test.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'katello_test_helper' | ||
|
||
describe ::Actions::Katello::UpstreamSubscriptions::RemoveEntitlements do | ||
include Dynflow::Testing | ||
|
||
subject { described_class } | ||
|
||
before :all do | ||
@org = FactoryBot.build(:katello_organization) | ||
set_organization(@org) | ||
@action = create_action(subject) | ||
@remove_action_class = ::Actions::Katello::UpstreamSubscriptions::RemoveEntitlement | ||
@manifest_action_class = ::Actions::Katello::Organization::ManifestRefresh | ||
end | ||
|
||
it 'plans' do | ||
pool1 = katello_pools(:pool_one) | ||
pool2 = katello_pools(:pool_two) | ||
|
||
pool1.expects(:upstream_entitlement_id).returns('a').twice | ||
pool2.expects(:upstream_entitlement_id).returns('b').twice | ||
|
||
::Katello::Pool.expects(:find).with(pool1.id).returns(pool1) | ||
::Katello::Pool.expects(:find).with(pool2.id).returns(pool2) | ||
|
||
plan_action(@action, [pool1.id, pool2.id]) | ||
|
||
assert_action_planned_with(@action, @remove_action_class, entitlement_id: 'a') | ||
assert_action_planned_with(@action, @remove_action_class, entitlement_id: 'b') | ||
assert_action_planned_with(@action, @manifest_action_class, @org) | ||
end | ||
|
||
it 'raises an error when the pool has no upstream entitlement' do | ||
pool1 = katello_pools(:pool_one) | ||
pool1.expects(:upstream_entitlement_id).returns(nil) | ||
::Katello::Pool.expects(:find).with(pool1.id).returns(pool1) | ||
|
||
error = proc { plan_action(@action, [pool1.id]) }.must_raise RuntimeError | ||
error.message.must_match(/upstream/) | ||
end | ||
|
||
it 'raises an error when given no entitlement ids' do | ||
error = proc { plan_action(@action, []) }.must_raise RuntimeError | ||
error.message.must_match(/provided/) | ||
end | ||
|
||
it 'raises an error when organization is set' do | ||
set_organization(nil) | ||
error = proc { plan_action(@action, [:foo]) }.must_raise RuntimeError | ||
error.message.must_match(/is not set/) | ||
end | ||
end |
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
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