From 0648493417b3bfe7d92f0c9bc1dedd79c8081add Mon Sep 17 00:00:00 2001 From: Jeremy Lenz Date: Wed, 8 Oct 2025 16:24:19 -0400 Subject: [PATCH 1/2] Fixes #38814 - Remove SCA-irrelevant Candlepin event handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove handling of the following Candlepin events as they are irrelevant in SCA-only mode: - entitlement.created and entitlement.deleted - related to attaching subscriptions to hosts - compliance.created - used to update host subscription status - system_purpose_compliance.created - used to update host system purpose status Also removed orphaned methods that were no longer called: - EventHandler: subscription_facet and reindex_consumer - MessageHandler: create_pool_on_host, remove_pool_from_host, and subscription_facet_host_ids 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../katello/candlepin/event_handler.rb | 31 ---------- .../katello/candlepin/message_handler.rb | 24 -------- .../compliance.created.json | 19 ------ .../entitlement.created.json | 19 ------ .../entitlement.deleted.json | 19 ------ .../system_purpose_compliance.created.json | 19 ------ .../candlepin/message_handler_test.rb | 58 ------------------- .../katello/candlepin/event_handler_test.rb | 28 --------- 8 files changed, 217 deletions(-) delete mode 100644 test/fixtures/candlepin_messages/compliance.created.json delete mode 100644 test/fixtures/candlepin_messages/entitlement.created.json delete mode 100644 test/fixtures/candlepin_messages/entitlement.deleted.json delete mode 100644 test/fixtures/candlepin_messages/system_purpose_compliance.created.json diff --git a/app/services/katello/candlepin/event_handler.rb b/app/services/katello/candlepin/event_handler.rb index a9df69163c4..f1f79a07cc0 100644 --- a/app/services/katello/candlepin/event_handler.rb +++ b/app/services/katello/candlepin/event_handler.rb @@ -15,46 +15,15 @@ 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 diff --git a/app/services/katello/candlepin/message_handler.rb b/app/services/katello/candlepin/message_handler.rb index 528b88cd8a7..089854e75e1 100644 --- a/app/services/katello/candlepin/message_handler.rb +++ b/app/services/katello/candlepin/message_handler.rb @@ -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) @@ -103,12 +85,6 @@ def handle_content_access_mode_modified 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 diff --git a/test/fixtures/candlepin_messages/compliance.created.json b/test/fixtures/candlepin_messages/compliance.created.json deleted file mode 100644 index b113062c39e..00000000000 --- a/test/fixtures/candlepin_messages/compliance.created.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "id":null, - "type":"CREATED", - "target":"COMPLIANCE", - "targetName":"dev.example.com", - "principalStore":"{\"type\":\"trusteduser\",\"name\":\"foreman_admin\"}", - "timestamp":1523375759913, - "entityId":"e930c61b-8dcb-4bca-8282-a8248185f9af", - "ownerId":"4028f95162acf5c20162acf7fdc70001", - "consumerUuid":"e930c61b-8dcb-4bca-8282-a8248185f9af", - "referenceId":null, - "referenceType":null, - "eventData":"{\"reasons\":[{\"productName\":\"Red Hat Enterprise Linux Server\",\"message\":\"Not supported by a valid subscription.\"}],\"status\":\"invalid\"}", - "messageText":null, - "principal":{ - "type":"trusteduser", - "name":"foreman_admin" - } -} \ No newline at end of file diff --git a/test/fixtures/candlepin_messages/entitlement.created.json b/test/fixtures/candlepin_messages/entitlement.created.json deleted file mode 100644 index 1ca41c7a1c5..00000000000 --- a/test/fixtures/candlepin_messages/entitlement.created.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "id":null, - "type":"CREATED", - "target":"ENTITLEMENT", - "targetName":"test2", - "principalStore":"{\"type\":\"trusteduser\",\"name\":\"foreman_admin\"}", - "timestamp":1523382395320, - "entityId":"a6a53632d5e54d018a007cc77cd1a787", - "ownerId":"4028f95162acf5c20162acf7fdc70001", - "consumerUuid":"e930c61b-8dcb-4bca-8282-a8248185f9af", - "referenceId":"4028f95162acf5c20162b043b1c606ca", - "referenceType":"POOL", - "eventData":null, - "messageText":null, - "principal":{ - "type":"trusteduser", - "name":"foreman_admin" - } -} \ No newline at end of file diff --git a/test/fixtures/candlepin_messages/entitlement.deleted.json b/test/fixtures/candlepin_messages/entitlement.deleted.json deleted file mode 100644 index add9b2ee78b..00000000000 --- a/test/fixtures/candlepin_messages/entitlement.deleted.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "id":null, - "type":"DELETED", - "target":"ENTITLEMENT", - "targetName":"test2", - "principalStore":"{\"type\":\"trusteduser\",\"name\":\"foreman_admin\"}", - "timestamp":1523382509241, - "entityId":"a6a53632d5e54d018a007cc77cd1a787", - "ownerId":"4028f95162acf5c20162acf7fdc70001", - "consumerUuid":"e930c61b-8dcb-4bca-8282-a8248185f9af", - "referenceId":"4028f95162acf5c20162b043b1c606ca", - "referenceType":"POOL", - "eventData":null, - "messageText":null, - "principal":{ - "type":"trusteduser", - "name":"foreman_admin" - } -} \ No newline at end of file diff --git a/test/fixtures/candlepin_messages/system_purpose_compliance.created.json b/test/fixtures/candlepin_messages/system_purpose_compliance.created.json deleted file mode 100644 index 3804704e4d4..00000000000 --- a/test/fixtures/candlepin_messages/system_purpose_compliance.created.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "id":null, - "type":"CREATED", - "target":"SYSTEM_PURPOSE_COMPLIANCE", - "targetName":"dev.example.com", - "principalStore":"{\"type\":\"trusteduser\",\"name\":\"foreman_admin\"}", - "timestamp":1539144566445, - "entityId":"3b4823c3-ae91-4bad-a46e-3e1ecb5678be", - "ownerId":"4028f94a65f7979b0165f846c8c20000", - "consumerUuid":"3b4823c3-ae91-4bad-a46e-3e1ecb5678be", - "referenceId":null, - "referenceType":null, - "eventData":"{\"nonCompliantUsage\":null,\"compliantAddOns\":{},\"nonCompliantRole\":null,\"reasons\":[\"unsatisfied sla: Standard\"],\"compliantSLA\":{},\"nonCompliantAddOns\":[],\"compliantRole\":{},\"nonCompliantSLA\":\"Standard\",\"compliantUsage\":{},\"status\":\"mismatched\"}", - "messageText":null, - "principal":{ - "type":"trusteduser", - "name":"foreman_admin" - } -} diff --git a/test/services/candlepin/message_handler_test.rb b/test/services/candlepin/message_handler_test.rb index 1cb24316b09..01b120d9db5 100644 --- a/test/services/candlepin/message_handler_test.rb +++ b/test/services/candlepin/message_handler_test.rb @@ -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' } diff --git a/test/services/katello/candlepin/event_handler_test.rb b/test/services/katello/candlepin/event_handler_test.rb index 9f02c7f8e89..73e57608b26 100644 --- a/test/services/katello/candlepin/event_handler_test.rb +++ b/test/services/katello/candlepin/event_handler_test.rb @@ -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 From 2156070228ae494868f3ffe9a52bca25b0324975 Mon Sep 17 00:00:00 2001 From: Jeremy Lenz Date: Fri, 10 Oct 2025 14:11:47 -0400 Subject: [PATCH 2/2] Refs #38814 - Remove owner_content_access_mode.modified event handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also remove handling of the owner_content_access_mode.modified event as it is no longer needed. Users cannot toggle between SCA and entitlement modes anymore, making this event irrelevant. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../katello/candlepin/event_handler.rb | 2 -- .../katello/candlepin/message_handler.rb | 17 ------------- .../owner_content_access_mode.modified.json | 19 --------------- .../candlepin/message_handler_test.rb | 24 ------------------- .../katello/candlepin/event_handler_test.rb | 11 --------- 5 files changed, 73 deletions(-) delete mode 100644 test/fixtures/candlepin_messages/owner_content_access_mode.modified.json diff --git a/app/services/katello/candlepin/event_handler.rb b/app/services/katello/candlepin/event_handler.rb index f1f79a07cc0..5a24e862529 100644 --- a/app/services/katello/candlepin/event_handler.rb +++ b/app/services/katello/candlepin/event_handler.rb @@ -19,8 +19,6 @@ def handle(message) message_handler.import_pool when /pool\.deleted/ message_handler.delete_pool - when /owner_content_access_mode\.modified/ - message_handler.handle_content_access_mode_modified end end end diff --git a/app/services/katello/candlepin/message_handler.rb b/app/services/katello/candlepin/message_handler.rb index 089854e75e1..7e7f37a585f 100644 --- a/app/services/katello/candlepin/message_handler.rb +++ b/app/services/katello/candlepin/message_handler.rb @@ -68,23 +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 end end end diff --git a/test/fixtures/candlepin_messages/owner_content_access_mode.modified.json b/test/fixtures/candlepin_messages/owner_content_access_mode.modified.json deleted file mode 100644 index fd765d5ed86..00000000000 --- a/test/fixtures/candlepin_messages/owner_content_access_mode.modified.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "id": null, - "type": "MODIFIED", - "target": "OWNER_CONTENT_ACCESS_MODE", - "targetName": "Empty Organization", - "principalStore": "{\"type\":\"trusteduser\",\"name\":\"foreman_admin\"}", - "timestamp": 1598992663405, - "entityId": "4028fac873da183e0173da1da6e20000", - "ownerId": "4028fac873da183e0173da1da6e20000", - "consumerUuid": null, - "referenceId": null, - "referenceType": null, - "eventData": "{\"contentAccessMode\":\"org_environment\"}", - "messageText": null, - "principal": { - "type": "trusteduser", - "name": "foreman_admin" - } -} diff --git a/test/services/candlepin/message_handler_test.rb b/test/services/candlepin/message_handler_test.rb index 01b120d9db5..d7115357dae 100644 --- a/test/services/candlepin/message_handler_test.rb +++ b/test/services/candlepin/message_handler_test.rb @@ -55,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 diff --git a/test/services/katello/candlepin/event_handler_test.rb b/test/services/katello/candlepin/event_handler_test.rb index 73e57608b26..0cb79a02702 100644 --- a/test/services/katello/candlepin/event_handler_test.rb +++ b/test/services/katello/candlepin/event_handler_test.rb @@ -44,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