Skip to content

Commit

Permalink
Fixes #27580 - Allow register to profile without DMI UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
jturel committed Aug 12, 2019
1 parent cf1acc5 commit d498ed7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions app/models/katello/host/subscription_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,17 @@ def self.find_host(facts, organization)

if hosts_size == 1
host = hosts.first
found_uuid = host.fact_values.find { |fv| fv.fact_name_id == uuid_fact_id }

return host if host.name == host_name && (host.build || found_uuid&.value == host_uuid)
if host.name == host_name
unless host.build
found_uuid = host.fact_values.where(fact_name_id: uuid_fact_id).first
if found_uuid && found_uuid.value != host_uuid
fail Katello::Errors::RegistrationError, _("This host is reporting a DMI UUID that differs from the existing registration.")
end
end

return host
end
end

hostnames = hosts.pluck(:name).sort.join(', ')
Expand Down
12 changes: 10 additions & 2 deletions test/models/host/subscription_facet_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ def test_find_host_existing_uuid
assert_equal find_host_error % host.name, error.message
end

def test_find_host_null_uuid_existing_host
# this test case is critical for bootstrap.py which creates a host via API (which lacks the dmi uuid fact)
# and *then* registers to it with subscription-manager
assert_empty host.fact_values

assert_equal host, Katello::Host::SubscriptionFacet.find_host({'network.hostname' => host.name, 'dmi.system.uuid' => 'actual-uuid'}, org)
end

def test_find_host_nil_uuid
# hostname does not match existing record, and the dmi.system.uuid is nil.
fv = FactValue.create(value: nil, host: host, fact_name: uuid_fact_name)
Expand All @@ -253,7 +261,7 @@ def test_find_host_nil_uuid
fv.value = "something"
fv.save!
error = assert_raises(Katello::Errors::RegistrationError) { Katello::Host::SubscriptionFacet.find_host({'network.hostname' => host.name, 'dmi.system.uuid' => nil}, org) }
assert_equal find_host_error % host.name, error.message
assert_match(/DMI UUID that differs/, error.message)
end

def test_find_host_existing_uuid_and_name_multiple
Expand All @@ -276,7 +284,7 @@ def test_find_host_existing_name_new_uuid
facts = {'dmi.system.uuid' => 'inexistent_uuid', 'network.hostname' => host.name}

error = assert_raises(Katello::Errors::RegistrationError) { Katello::Host::SubscriptionFacet.find_host(facts, org) }
assert_equal find_host_error % host.name, error.message
assert_match(/DMI UUID that differs/, error.message)
end

def test_find_host_existing_uuid_and_name
Expand Down

0 comments on commit d498ed7

Please sign in to comment.