Problem:
Since we are not using Puppet anymore (Ansible only), I recently disabled Puppet support inside of Foreman/Katello. However, it looks like something was not cleaned up internally.
When deleting a host I get an error 500 and the host is not deleted. The production log shows:
2023-01-30T20:56:23 [I|app|a5b0dcf7] Backtrace for 'Action failed' error (ActiveRecord::InvalidForeignKey): PG::ForeignKeyViolation: ERROR: update or delete on table "hosts" violates foreign key constraint "fk_rails_cadab260b9" on table "host_puppet_facets"
a5b0dcf7 | DETAIL: Key (id)=(49) is still referenced from table "host_puppet_facets".
a5b0dcf7 |
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:672:in `exec_params'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:672:in `block (2 levels) in exec_no_cache'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `block in exec_no_cache'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_adapter.rb:696:in `block (2 levels) in log'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_adapter.rb:695:in `block in log'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_adapter.rb:687:in `log'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:670:in `exec_no_cache'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `execute_and_clear'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql/database_statements.rb:72:in `exec_delete'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/database_statements.rb:185:in `delete'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/query_cache.rb:22:in `delete'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/persistence.rb:395:in `_delete_record'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/persistence.rb:877:in `_delete_row'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/persistence.rb:873:in `destroy_row'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/counter_cache.rb:176:in `destroy_row'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/locking/optimistic.rb:120:in `destroy_row'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/persistence.rb:539:in `destroy'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/callbacks.rb:439:in `block in destroy'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/callbacks.rb:106:in `run_callbacks'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/callbacks.rb:824:in `_run_destroy_callbacks'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/callbacks.rb:439:in `destroy'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/transactions.rb:294:in `block in destroy'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/transactions.rb:354:in `block in with_transaction_returning_status'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/transactions.rb:350:in `with_transaction_returning_status'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/transactions.rb:294:in `destroy'
a5b0dcf7 | /usr/share/gems/gems/katello-4.7.0/app/services/katello/registration_manager.rb:196:in `destroy_host_record'
a5b0dcf7 | /usr/share/gems/gems/katello-4.7.0/app/services/katello/registration_manager.rb:141:in `unregister_host'
a5b0dcf7 | /usr/share/gems/gems/katello-4.7.0/app/controllers/katello/concerns/api/v2/hosts_controller_extensions.rb:23:in `destroy'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/abstract_controller/base.rb:228:in `process_action'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_controller/metal/rendering.rb:30:in `process_action'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
a5b0dcf7 | /usr/share/foreman/app/controllers/concerns/foreman/controller/timezone.rb:10:in `set_timezone'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
a5b0dcf7 | /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:32:in `clear_thread'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
a5b0dcf7 | /usr/share/foreman/app/controllers/concerns/foreman/controller/topbar_sweeper.rb:12:in `set_topbar_sweeper_controller'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
a5b0dcf7 | /usr/share/gems/gems/audited-5.0.2/lib/audited/sweeper.rb:16:in `around'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
a5b0dcf7 | /usr/share/gems/gems/audited-5.0.2/lib/audited/sweeper.rb:16:in `around'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/callbacks.rb:137:in `run_callbacks'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/abstract_controller/callbacks.rb:41:in `process_action'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_controller/metal/rescue.rb:22:in `process_action'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/notifications.rb:203:in `block in instrument'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/notifications.rb:203:in `instrument'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_controller/metal/instrumentation.rb:33:in `process_action'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_controller/metal/params_wrapper.rb:249:in `process_action'
a5b0dcf7 | /usr/share/gems/gems/activerecord-6.1.7/lib/active_record/railties/controller_runtime.rb:27:in `process_action'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/abstract_controller/base.rb:165:in `process'
a5b0dcf7 | /usr/share/gems/gems/actionview-6.1.7/lib/action_view/rendering.rb:39:in `process'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_controller/metal.rb:190:in `dispatch'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_controller/metal.rb:254:in `dispatch'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/routing/route_set.rb:33:in `serve'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/routing/mapper.rb:19:in `block in <class:Constraints>'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/routing/mapper.rb:49:in `serve'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/journey/router.rb:50:in `block in serve'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/journey/router.rb:32:in `each'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/journey/router.rb:32:in `serve'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/routing/route_set.rb:842:in `call'
a5b0dcf7 | /usr/share/gems/gems/katello-4.7.0/lib/katello/middleware/organization_created_enforcer.rb:18:in `call'
a5b0dcf7 | /usr/share/gems/gems/katello-4.7.0/lib/katello/middleware/event_daemon.rb:10:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/static.rb:24:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/static.rb:24:in `call'
a5b0dcf7 | /usr/share/gems/gems/apipie-dsl-2.5.0/lib/apipie_dsl/static_dispatcher.rb:67:in `call'
a5b0dcf7 | /usr/share/gems/gems/apipie-rails-0.8.2/lib/apipie/static_dispatcher.rb:68:in `call'
a5b0dcf7 | /usr/share/gems/gems/apipie-rails-0.8.2/lib/apipie/extractor/recorder.rb:137:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/static.rb:24:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/static.rb:24:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/static.rb:24:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/static.rb:24:in `call'
a5b0dcf7 | /usr/share/foreman/lib/foreman/middleware/libvirt_connection_cleaner.rb:9:in `call'
a5b0dcf7 | /usr/share/foreman/lib/foreman/middleware/telemetry.rb:10:in `call'
a5b0dcf7 | /usr/share/gems/gems/apipie-rails-0.8.2/lib/apipie/middleware/checksum_in_headers.rb:27:in `call'
a5b0dcf7 | /usr/share/gems/gems/rack-2.2.4/lib/rack/tempfile_reaper.rb:15:in `call'
a5b0dcf7 | /usr/share/gems/gems/rack-2.2.4/lib/rack/etag.rb:27:in `call'
a5b0dcf7 | /usr/share/gems/gems/rack-2.2.4/lib/rack/conditional_get.rb:40:in `call'
a5b0dcf7 | /usr/share/gems/gems/rack-2.2.4/lib/rack/head.rb:12:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/http/permissions_policy.rb:22:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/http/content_security_policy.rb:19:in `call'
a5b0dcf7 | /usr/share/foreman/lib/foreman/middleware/logging_context_session.rb:22:in `call'
a5b0dcf7 | /usr/share/gems/gems/rack-2.2.4/lib/rack/session/abstract/id.rb:266:in `context'
a5b0dcf7 | /usr/share/gems/gems/rack-2.2.4/lib/rack/session/abstract/id.rb:260:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/cookies.rb:689:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/callbacks.rb:98:in `run_callbacks'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
a5b0dcf7 | /usr/share/gems/gems/railties-6.1.7/lib/rails/rack/logger.rb:37:in `call_app'
a5b0dcf7 | /usr/share/gems/gems/railties-6.1.7/lib/rails/rack/logger.rb:28:in `call'
a5b0dcf7 | /usr/share/gems/gems/sprockets-rails-3.4.2/lib/sprockets/rails/quiet_assets.rb:13:in `call'
a5b0dcf7 | /usr/share/foreman/lib/foreman/middleware/logging_context_request.rb:11:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/request_id.rb:26:in `call'
a5b0dcf7 | /usr/share/gems/gems/katello-4.7.0/lib/katello/prevent_json_parsing.rb:12:in `call'
a5b0dcf7 | /usr/share/gems/gems/rack-2.2.4/lib/rack/method_override.rb:24:in `call'
a5b0dcf7 | /usr/share/gems/gems/rack-2.2.4/lib/rack/runtime.rb:22:in `call'
a5b0dcf7 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/executor.rb:14:in `call'
a5b0dcf7 | /usr/share/gems/gems/rack-2.2.4/lib/rack/sendfile.rb:110:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/ssl.rb:77:in `call'
a5b0dcf7 | /usr/share/gems/gems/actionpack-6.1.7/lib/action_dispatch/middleware/host_authorization.rb:142:in `call'
a5b0dcf7 | /usr/share/gems/gems/secure_headers-6.5.0/lib/secure_headers/middleware.rb:11:in `call'
a5b0dcf7 | /usr/share/gems/gems/railties-6.1.7/lib/rails/engine.rb:539:in `call'
a5b0dcf7 | /usr/share/gems/gems/railties-6.1.7/lib/rails/railtie.rb:207:in `public_send'
a5b0dcf7 | /usr/share/gems/gems/railties-6.1.7/lib/rails/railtie.rb:207:in `method_missing'
a5b0dcf7 | /usr/share/gems/gems/rack-2.2.4/lib/rack/urlmap.rb:74:in `block in call'
a5b0dcf7 | /usr/share/gems/gems/rack-2.2.4/lib/rack/urlmap.rb:58:in `each'
a5b0dcf7 | /usr/share/gems/gems/rack-2.2.4/lib/rack/urlmap.rb:58:in `call'
a5b0dcf7 | /usr/share/gems/gems/puma-5.6.5/lib/puma/configuration.rb:252:in `call'
a5b0dcf7 | /usr/share/gems/gems/puma-5.6.5/lib/puma/request.rb:77:in `block in handle_request'
a5b0dcf7 | /usr/share/gems/gems/puma-5.6.5/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
a5b0dcf7 | /usr/share/gems/gems/puma-5.6.5/lib/puma/request.rb:76:in `handle_request'
a5b0dcf7 | /usr/share/gems/gems/puma-5.6.5/lib/puma/server.rb:443:in `process_client'
a5b0dcf7 | /usr/share/gems/gems/puma-5.6.5/lib/puma/thread_pool.rb:147:in `block in spawn_thread'
a5b0dcf7 | /usr/share/gems/gems/logging-2.3.1/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
2023-01-30T20:56:23 [I|app|a5b0dcf7] Rendered api/v2/errors/standard_error.json.rabl within api/v2/layouts/error_layout (Duration: 6.0ms | Allocations: 5390)
2023-01-30T20:56:23 [I|app|a5b0dcf7] Rendered layout api/v2/layouts/error_layout.json.erb (Duration: 11.1ms | Allocations: 10765)
2023-01-30T20:56:23 [I|app|a5b0dcf7] Completed 500 Internal Server Error in 4663ms (Views: 12.0ms | ActiveRecord: 1566.2ms | Allocations: 354026)
I found another thread in here, which pointed me to the right solution: https://community.theforeman.org/t/reports-processing-failure-associationtypemismatch/21357
So I had to execute
DELETE FROM host_puppet_facets WHERE host_id='49';
in Postgres and afterwards I could delete the host just fine.
Is it possible, that the disabling of Puppet should have also cleaned out all host_puppet_facet entries inside the table? Or is it a missing ON DELETE CASCADE?
Expected outcome:
Delete a host without any error.
Foreman and Proxy versions:
F 3.5.1
K 4.7
Foreman and Proxy plugin versions:
Distribution and version:
Rocky 8
Other relevant data: