Skip to content
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
33 changes: 0 additions & 33 deletions app/services/katello/candlepin/event_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,13 @@ def handle(message)
@message_handler = ::Katello::Candlepin::MessageHandler.new(message)
data[:entity_id] = @message_handler.entity_id
case message_handler.subject
when /entitlement\.created/
message_handler.import_pool
message_handler.create_pool_on_host
when /entitlement\.deleted/
message_handler.import_pool
message_handler.remove_pool_from_host
when /pool\.created/
message_handler.import_pool
when /pool\.deleted/
message_handler.delete_pool
when /^compliance\.created/
event_no_longer_handled
when /system_purpose_compliance\.created/
event_no_longer_handled
when /owner_content_access_mode\.modified/
message_handler.handle_content_access_mode_modified
end
end
end

private

def event_no_longer_handled
@logger.error "Received #{message_handler.subject} event from Candlepin. Handling of this event is no longer supported."
end

def subscription_facet
message_handler.subscription_facet
end

def reindex_consumer
if subscription_facet.nil?
@logger.debug "skip re-indexing of non-existent content host #{message_handler.consumer_uuid}"
return
end

@logger.debug "re-indexing content host #{subscription_facet.host.name}"

yield
end
end
end
end
41 changes: 0 additions & 41 deletions app/services/katello/candlepin/message_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,9 @@ def pool_id
case subject
when 'pool.created', 'pool.deleted'
content['entityId']
when 'entitlement.created', 'entitlement.deleted'
content['referenceId']
end
end

def create_pool_on_host
return if self.subscription_facet.nil? || pool.nil?
old_host_ids = subscription_facet_host_ids
::Katello::SubscriptionFacetPool.where(subscription_facet_id: self.subscription_facet.id,
pool_id: pool.id).first_or_create
pool.import_audit_record(old_host_ids)
end

def remove_pool_from_host
return if self.subscription_facet.nil? || pool.nil?
old_host_ids = subscription_facet_host_ids
::Katello::SubscriptionFacetPool.where(subscription_facet_id: self.subscription_facet.id,
pool_id: pool.id).destroy_all
pool.import_audit_record(old_host_ids)
end

def import_pool(index_hosts = true)
if pool
::Katello::EventQueue.push_event(::Katello::Events::ImportPool::EVENT_TYPE, pool.id)
Expand All @@ -86,29 +68,6 @@ def delete_pool
Rails.logger.info "Deleted Katello::Pool with cp_id=#{pool_id}"
end
end

def handle_content_access_mode_modified
# Ideally the target_name would be the Candlepin Owner key
# Since it's the displayName, and we don't update that after org creation, there could be a mismatch
# For now, find the Candlepin Owner displayName from this event, and tie it back to a Katello org based on owner key
owners = Katello::Resources::Candlepin::Owner.all
owner = owners.find { |o| o['displayName'] == target_name }

unless owner
fail("Candlepin Owner %s could not be found" % target_name)
end

org = ::Organization.find_by!(label: owner['key'])

Rails.logger.error "Received content_access_mode_modified event for org #{org.label}. This event is no longer supported."
org.simple_content_access?(cached: false)
end

private

def subscription_facet_host_ids
::Katello::SubscriptionFacetPool.where(pool_id: pool_id).joins(:subscription_facet).pluck(:host_id)
end
end
end
end
19 changes: 0 additions & 19 deletions test/fixtures/candlepin_messages/compliance.created.json

This file was deleted.

19 changes: 0 additions & 19 deletions test/fixtures/candlepin_messages/entitlement.created.json

This file was deleted.

19 changes: 0 additions & 19 deletions test/fixtures/candlepin_messages/entitlement.deleted.json

This file was deleted.

This file was deleted.

This file was deleted.

82 changes: 0 additions & 82 deletions test/services/candlepin/message_handler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,64 +21,6 @@ def setup
end
end

class ComplianceCreatedTest < MessageHandlerTestBase
let(:event_name) { 'compliance.created' }

def test_consumer_uuid
assert_equal @consumer_uuid, handler.consumer_uuid
end

def test_reasons
assert_equal 1, handler.reasons.count
assert_equal 'Red Hat Enterprise Linux Server', handler.reasons[0]['productName']
end

def test_status
assert_equal 'invalid', handler.status
end

def test_subscription_facet
assert_equal @facet, handler.subscription_facet
end
end

class EntitlementCreatedTest < MessageHandlerTestBase
let(:event_name) { 'entitlement.created' }

def test_pool_id
assert_equal @pool_id, handler.pool_id
end

def test_consumer_uuid
assert_equal @consumer_uuid, handler.consumer_uuid
end

def test_create_pool_on_host
@facet.pools = []

handler.create_pool_on_host
refute_empty @facet.pools.where(:cp_id => @pool_id)
end
end

class EntitlementDeletedTest < MessageHandlerTestBase
let(:event_name) { 'entitlement.deleted' }

def test_consumer_uuid
assert_equal @consumer_uuid, handler.consumer_uuid
end

def test_pool_id
assert_equal @pool_id, handler.pool_id
end

def test_remove_pool_from_host
@facet.pools = [@pool]
handler.remove_pool_from_host
assert_empty @facet.pools.where(:cp_id => @pool_id)
end
end

class PoolCreatedTest < MessageHandlerTestBase
let(:event_name) { 'pool.created' }

Expand Down Expand Up @@ -113,28 +55,4 @@ def test_delete_pool_on_null
assert_empty Katello::Pool.find_by(:cp_id => @pool_id)
end
end

class OwnerContentAccessModeModifiedTest < MessageHandlerTestBase
let(:event_name) { 'owner_content_access_mode.modified' }

def setup
@org = get_organization(:empty_organization)
Katello::Resources::Candlepin::Owner.expects(:all).returns(
[
{
'displayName' => @org.name,
'key' => @org.label,
},
]
)
super
end

def test_content_access_mode_modified
Organization.any_instance.expects(:simple_content_access?).with(cached: false)
Rails.logger.expects(:error).with("Received content_access_mode_modified event for org #{@org.label}. This event is no longer supported.")

handler.handle_content_access_mode_modified
end
end
end
39 changes: 0 additions & 39 deletions test/services/katello/candlepin/event_handler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,6 @@ def message(subject, content = {})
OpenStruct.new(result)
end

describe 'handles compliance.created' do
let(:mymessage) do
message("compliance.created", 'eventData' => "{\"status\":\"invalid\"}")
end
end

describe 'handles entitlement.created' do
let(:mymessage) do
message("entitlement.created", :referenceId => pool_id)
end

it 'reindex the pool' do
Katello::Candlepin::MessageHandler.any_instance.expects(:import_pool)
handler.handle(mymessage)
end
end

describe 'handles entitlement.deleted' do
let(:mymessage) do
message("entitlement.deleted", :referenceId => pool_id)
end

it 'reindex the pool' do
Katello::Candlepin::MessageHandler.any_instance.expects(:import_pool)
handler.handle(mymessage)
end
end

describe 'handles pool.created' do
let(:mymessage) do
message "pool.created", :entityId => pool_id
Expand All @@ -72,16 +44,5 @@ def message(subject, content = {})
handler.handle(mymessage)
end
end

describe 'handles owner_content_access_mode.modified' do
let(:mymessage) do
message "owner_content_access_mode.modified"
end

it 'calls the right MessageHandler method' do
Katello::Candlepin::MessageHandler.any_instance.expects(:handle_content_access_mode_modified)
handler.handle(mymessage)
end
end
end
end
Loading