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 #38169 - Fix operatingsystem race condition with concurrent registrations #10425

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/services/katello/rhsm_fact_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ def operatingsystem
os_attributes[:name] = "CentOS"
end

::Operatingsystem.find_or_create_by(os_attributes)
jeremylenz marked this conversation as resolved.
Show resolved Hide resolved
os = ::Operatingsystem.find_by(os_attributes)
if os.blank?
created = ::Operatingsystem.create_or_find_by(os_attributes)
created.errors.any? ? ::Operatingsystem.find_by(os_attributes) : created
else
os
end
end
end

Expand Down
13 changes: 13 additions & 0 deletions test/unit/katello/rhsm_fact_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,18 @@ def test_uname_architecture

assert 'i386', parser.architecture.name
end

def test_operatingsystem_race_condition_handling
existing_os = ::Operatingsystem.create(name: 'RedHat', major: '9', minor: '')
::Operatingsystem.expects(:find_by).twice.returns(nil)
@facts['distribution.name'] = 'Red Hat Enterprise Linux'
@facts['distribution.version'] = '9'
@facts['distribution.id'] = 'Nine'

assert_nothing_raised do
parser.operatingsystem
existing_os.destroy
end
end
end
end
Loading