Bug #24786
closedMysql2::Error: Unknown column 'fact_names.name' when importing facts.
Description
When i try to send facts from chef-client to foreman I get the error:
Mysql2::Error: Unknown column 'fact_names.name' in 'field list': SELECT fact_names.name FROM `fact_values` WHERE `fact_values`.`host_id` = 1 AND `fact_values`.`fact_name_id` IN (6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132) (ActiveRecord::StatementInvalid)
With stacktrace:
| /usr/share/foreman/vendor/ruby/2.3.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `_query' | /usr/share/foreman/vendor/ruby/2.3.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `block in query' | /usr/share/foreman/vendor/ruby/2.3.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `handle_interrupt' | /usr/share/foreman/vendor/ruby/2.3.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `query' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:214:in `block (2 levels) in execute' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/dependencies/interlock.rb:46:in `block in permit_concurrent_loads' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/concurrency/share_lock.rb:185:in `yield_shares' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/dependencies/interlock.rb:45:in `permit_concurrent_loads' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:213:in `block in execute' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract_adapter.rb:613:in `block (2 levels) in log' | /usr/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block in log' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/notifications/instrumenter.rb:21:in `instrument' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract_adapter.rb:604:in `log' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:212:in `execute' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/mysql/database_statements.rb:26:in `execute' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:223:in `execute_and_free' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/mysql/database_statements.rb:31:in `exec_query' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:371:in `select' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:42:in `select_all' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/query_cache.rb:95:in `block in select_all' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/query_cache.rb:118:in `block in cache_sql' | /usr/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/query_cache.rb:104:in `cache_sql' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/query_cache.rb:95:in `select_all' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/mysql/database_statements.rb:10:in `select_all' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/relation/calculations.rb:176:in `pluck' | /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman_chef-0.8.0/app/models/foreman_chef/fact_importer.rb:74:in `facts_to_create' | /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman_chef-0.8.0/app/models/foreman_chef/fact_importer.rb:66:in `add_fact' | /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman_chef-0.8.0/app/models/foreman_chef/fact_importer.rb:60:in `block in add_missing_facts' | /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman_chef-0.8.0/app/models/foreman_chef/fact_importer.rb:32:in `each' | /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman_chef-0.8.0/app/models/foreman_chef/fact_importer.rb:32:in `add_missing_facts' | /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman_chef-0.8.0/app/models/foreman_chef/fact_importer.rb:27:in `add_new_facts' | /usr/share/foreman/app/services/fact_importer.rb:61:in `block in import!' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction' | /usr/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/transactions.rb:210:in `transaction' | /usr/share/foreman/app/services/fact_importer.rb:58:in `import!' | /usr/share/foreman/app/models/host/base.rb:144:in `block in import_facts' | /usr/share/foreman/app/services/foreman/telemetry_helper.rb:27:in `telemetry_duration_histogram' | /usr/share/foreman/app/models/host/base.rb:143:in `import_facts' | /usr/share/foreman/app/models/host/managed.rb:317:in `import_facts' | /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman-tasks-0.13.2/app/lib/actions/foreman/host/import_facts.rb:32:in `block in run' | /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:100:in `as' | /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman-tasks-0.13.2/app/lib/actions/foreman/host/import_facts.rb:27:in `run' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/action.rb:538:in `block (3 levels) in execute_run' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware/stack.rb:26:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware.rb:18:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman-tasks-0.13.2/app/lib/actions/middleware/rails_executor_wrap.rb:14:in `block in run' | /usr/share/foreman/vendor/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/execution_wrapper.rb:85:in `wrap' | /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman-tasks-0.13.2/app/lib/actions/middleware/rails_executor_wrap.rb:13:in `run' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware/stack.rb:22:in `call' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware/stack.rb:26:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware.rb:18:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/action/progress.rb:30:in `with_progress_calculation' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/action/progress.rb:16:in `run' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware/stack.rb:22:in `call' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware/stack.rb:26:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware.rb:18:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman-tasks-0.13.2/app/lib/actions/middleware/keep_current_user.rb:15:in `block in run' | /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman-tasks-0.13.2/app/lib/actions/middleware/keep_current_user.rb:43:in `restore_curent_user' | /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman-tasks-0.13.2/app/lib/actions/middleware/keep_current_user.rb:15:in `run' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware/stack.rb:22:in `call' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware/stack.rb:26:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware.rb:18:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware.rb:31:in `run' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware/stack.rb:22:in `call' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/middleware/world.rb:30:in `execute' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/action.rb:537:in `block (2 levels) in execute_run' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/action.rb:536:in `catch' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/action.rb:536:in `block in execute_run' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/action.rb:451:in `block in with_error_handling' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/action.rb:451:in `catch' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/action.rb:451:in `with_error_handling' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/action.rb:531:in `execute_run' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/action.rb:278:in `execute' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/execution_plan/steps/abstract_flow_step.rb:17:in `block (2 levels) in execute' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/execution_plan/steps/abstract.rb:162:in `with_meta_calculation' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/execution_plan/steps/abstract_flow_step.rb:16:in `block in execute' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/execution_plan/steps/abstract_flow_step.rb:30:in `open_action' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/execution_plan/steps/abstract_flow_step.rb:15:in `execute' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/director.rb:43:in `execute' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/executors/parallel/worker.rb:12:in `block in on_message' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/executors.rb:12:in `run_user_code' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/executors/parallel/worker.rb:11:in `on_message' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/context.rb:46:in `on_envelope' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/executes_context.rb:7:in `on_envelope' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/abstract.rb:25:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/dynflow-1.1.0/lib/dynflow/actor.rb:26:in `on_envelope' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/abstract.rb:25:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/awaits.rb:15:in `on_envelope' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/abstract.rb:25:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/sets_results.rb:14:in `on_envelope' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/abstract.rb:25:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/buffer.rb:38:in `process_envelope' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/buffer.rb:31:in `process_envelopes?' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/buffer.rb:20:in `on_envelope' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/abstract.rb:25:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/termination.rb:55:in `on_envelope' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/abstract.rb:25:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/removes_child.rb:10:in `on_envelope' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/abstract.rb:25:in `pass' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/behaviour/sets_results.rb:14:in `on_envelope' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/core.rb:161:in `process_envelope' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/core.rb:95:in `block in on_envelope' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/core.rb:118:in `block (2 levels) in schedule_execution' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/synchronization/mri_lockable_object.rb:38:in `block in synchronize' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/synchronization/mri_lockable_object.rb:38:in `synchronize' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/synchronization/mri_lockable_object.rb:38:in `synchronize' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-edge-0.2.4/lib/concurrent/actor/core.rb:115:in `block in schedule_execution' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/serialized_execution.rb:18:in `call' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/serialized_execution.rb:96:in `work' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/serialized_execution.rb:77:in `block in call_job' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `run_task' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:337:in `block (3 levels) in create_worker' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `loop' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `block (2 levels) in create_worker' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `catch' | /usr/share/foreman/vendor/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `block in create_worker' | /usr/share/foreman/vendor/ruby/2.3.0/gems/logging-2.2.2/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
To reproduce:
Install foreman 1.18.1 or 1.19, configure mysql2-driver, add foreman_chef 0.8.0 and foreman-tasks 0.13.2 (currently requires this ugly workaround: https://github.com/bjozet/foreman-tasks/commit/b29735edf9dbc37d93a77ed447eedfdb06451169) . Send facts from with chef-client and receive the error above.
The exact same setup works fine in Foreman 1.16.
I found that foreman_salt had a similar issue that was fixed in https://projects.theforeman.org/issues/24108. I don't know really how to convert those changes into something that foreman_chef would understand.
Please help! :-)
Updated by Björn Zettergren over 6 years ago
- Fixed in Releases deleted (
foreman_chef 0.8.0)
Updated by Björn Zettergren over 6 years ago
To send facts as "fake" chef-client, use curl and a json:
curl -u admin:password -v -d @/etc/foreman/test-chef.json -H "Content-Type: application/json" http://localhost:3000/api/hosts/facts
Where /etc/foreman/test-chef.json
is:
{ "facts": { "_timestamp": "2018-09-10 10:25:43 +0000", "_type": "foreman_chef", "chef_node_name": "ubuntu-xenial", "cookbooks::git::version": "0.1.0", "operatingsystem": "Ubuntu", "operatingsystemrelease": "16.04" }, "name": "test01.local.net" }
Edit for appropriate names/timestamps
Updated by Björn Zettergren over 6 years ago
- Pull request https://github.com/theforeman/foreman_chef/pull/88 added
Created a pullrequest, not necessarily for merging, but for reviewing atleast, or continuing debugging.
I figured that after foreman-core fact_import refactor, there were similar issues in this code as found in foreman_salt, and i've tried to implement it. In my dev-environment, i can import facts from chef without the mysql-errors, and facts seem to get imported, dynflow-console says "success". But i'm far from certain that this is the correct approach.
please advice :)
Updated by The Foreman Bot over 6 years ago
- Status changed from New to Ready For Testing
Updated by Marek Hulán about 6 years ago
- Target version set to foreman_chef 0.9.0
- Fixed in Releases foreman_chef 0.9.0 added
Updated by Anonymous about 6 years ago
- Status changed from Ready For Testing to Closed
Applied in changeset foreman_chef|9ae207462b61551d898e1962835a57b45876857c.