Skip to content

Commit

Permalink
Fixes #18122 - move rhsm fact update to run phase
Browse files Browse the repository at this point in the history
During fact importing, RhsmFactName objects are created
in large quantity. Because first_or_create is very susceptible
to race conditions, we rescue on RecordNotUnique within
RhsmFactImporter#add_fact_name.  However if duplicate record
exception is thrown while in a transaction the entire
transaction is aborted.  The run phase does not use a transaction
so the problem should not occur there.
  • Loading branch information
jlsherrill committed Jan 24, 2017
1 parent d6f204f commit 98bb66d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions app/lib/actions/katello/host/register.rb
Expand Up @@ -24,16 +24,14 @@ def plan(host, consumer_params, content_view_environment, activation_keys = [])
host.subscription_facet = plan_subscription_facet(host, activation_keys, consumer_params)
host.save!

::Katello::Host::SubscriptionFacet.update_facts(host, consumer_params[:facts]) unless consumer_params[:facts].blank?

action_subject host

cp_create = plan_action(Candlepin::Consumer::Create, cp_environment_id: content_view_environment.cp_id,
consumer_parameters: consumer_params, activation_keys: activation_keys.map(&:cp_name))
return if cp_create.error

plan_self(uuid: cp_create.output[:response][:uuid], host_id: host.id, hostname: host.name,
user_id: User.current.id)
user_id: User.current.id, :facts => consumer_params[:facts])
plan_action(Pulp::Consumer::Create, uuid: cp_create.output[:response][:uuid], name: host.name)
end
end
Expand All @@ -46,6 +44,14 @@ def humanized_name
end
end

def run
host = ::Host.find(input[:host_id])
unless input[:facts].blank?
::Katello::Host::SubscriptionFacet.update_facts(host, input[:facts])
input[:facts] = 'TRIMMED'
end
end

def finalize
host = ::Host.find(input[:host_id])
host.content_facet.uuid = input[:uuid]
Expand Down
11 changes: 9 additions & 2 deletions app/lib/actions/katello/host/update.rb
Expand Up @@ -6,7 +6,7 @@ class Update < Actions::EntryAction

def plan(host, consumer_params = nil)
action_subject host
plan_self(:hostname => host.name)
plan_self(:hostname => host.name, :facts => consumer_params.try(:[], :facts), :host_id => host.id)

sequence do
host.content_facet.save! if host.content_facet
Expand All @@ -17,7 +17,6 @@ def plan(host, consumer_params = nil)
else
consumer_params = host.subscription_facet.consumer_attributes
end
::Katello::Host::SubscriptionFacet.update_facts(::Host.find(host.id), consumer_params[:facts]) unless consumer_params[:facts].blank?
host.subscription_facet.save!
plan_action(::Actions::Candlepin::Consumer::Update, host.subscription_facet.uuid, consumer_params)
end
Expand All @@ -28,6 +27,14 @@ def plan(host, consumer_params = nil)
end
end

def run
host = ::Host.find(input[:host_id])
unless input[:facts].blank?
::Katello::Host::SubscriptionFacet.update_facts(host, input[:facts])
input[:facts] = 'TRIMMED'
end
end

def resource_locks
:update
end
Expand Down
1 change: 0 additions & 1 deletion test/actions/katello/host/register_test.rb
Expand Up @@ -26,7 +26,6 @@ class RegisterTest < ActiveSupport::TestCase
action = create_action action_class
new_host = Host::Managed.new(:name => 'foobar', :managed => false)
action.stubs(:action_subject).with(new_host)
::Katello::Host::SubscriptionFacet.expects(:update_facts).with(new_host, rhsm_params[:facts])
plan_action action, new_host, rhsm_params, @content_view_environment

assert_action_planed_with(action, candlepin_class, :cp_environment_id => @content_view_environment.cp_id,
Expand Down

0 comments on commit 98bb66d

Please sign in to comment.