Skip to content

Commit

Permalink
Fixes #5863 - create consumer in plan phase
Browse files Browse the repository at this point in the history
The failure is quite possible when creating a consumer in
Candlepin (mainly because of the activation key might be over-consumed
already).
  • Loading branch information
iNecas committed May 28, 2014
1 parent a83fb6b commit d98d29b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
15 changes: 13 additions & 2 deletions app/lib/actions/candlepin/consumer/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ class Create < Candlepin::Abstract
param :uuid
param :capabilities
param :activation_keys
param :response
end

def run
output[:response] = ::Katello::Resources::Candlepin::Consumer.
# We need to call this in plan phase as this can lean to error responses
# when the activation key fails to subscribe to the products
def plan(input)
response = ::Katello::Resources::Candlepin::Consumer.
create(input[:cp_environment_id],
input[:organization_label],
input[:name],
Expand All @@ -43,6 +46,14 @@ def run
input[:uuid],
input[:capabilities],
input[:activation_keys])
plan_self(input.merge(response: response))
end

def run
# we still keep the output interface the same for case there is other
# way how to check the ability to subscribe the system with the actiovation key
# or we have better support for rolling back in Dynflow
output[:response] = input[:response]
end
end
end
Expand Down
35 changes: 20 additions & 15 deletions app/lib/actions/katello/system/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,27 @@ def plan(system, activation_keys = [])
activation_key_plan = plan_action(Katello::System::ActivationKeys, system, activation_keys)
return if activation_key_plan.error

cp_create = plan_action(Candlepin::Consumer::Create,
cp_environment_id: system.cp_environment_id,
organization_label: system.organization.label,
name: system.name,
cp_type: system.cp_type,
facts: system.facts,
installed_products: system.installedProducts,
autoheal: system.autoheal,
release_ver: system.release,
service_level: system.serviceLevel,
uuid: system.uuid,
capabilities: system.capabilities,
activation_keys: activation_keys)
# we need to prepare the input for consumer create before we call save!
# as the before filters do some magic with the attributes
consumer_create_input = { cp_environment_id: system.cp_environment_id,
organization_label: system.organization.label,
name: system.name,
cp_type: system.cp_type,
facts: system.facts,
installed_products: system.installedProducts,
autoheal: system.autoheal,
release_ver: system.release,
service_level: system.serviceLevel,
uuid: system.uuid,
capabilities: system.capabilities,
activation_keys: activation_keys }
system.save!
action_subject system, uuid: cp_create.output[:response][:uuid]
plan_self
action_subject system

cp_create = plan_action(Candlepin::Consumer::Create, consumer_create_input)
return if cp_create.error

plan_self(uuid: cp_create.output[:response][:uuid])
plan_action(Pulp::Consumer::Create,
uuid: cp_create.output[:response][:uuid],
name: system.name)
Expand Down
2 changes: 0 additions & 2 deletions test/actions/katello/system_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class CreateTest < TestBase
system.expects(:save!)
action.stubs(:action_subject).with do |subject, params|
subject.must_equal(system)
params[:uuid].must_be_kind_of Dynflow::ExecutionPlan::OutputReference
params[:uuid].subkeys.must_equal %w[response uuid]
end
#::Actions::Katello::System::ActivationKeys.any_instance.stubs(:error).returns(nil)
Dynflow::Testing::DummyPlannedAction.any_instance.stubs(:error).returns(nil)
Expand Down

0 comments on commit d98d29b

Please sign in to comment.