Project

General

Profile

Actions

Bug #23593

closed

function "host_param" in default value of smart class parameter is not allowed anymore. It results in undefined method `host_param' (erb):1:in `parse_string'

Added by Axel Hahn over 6 years ago. Updated about 6 years ago.

Status:
Duplicate
Priority:
Normal
Assignee:
-
Category:
Templates
Target version:
Difficulty:
Triaged:
Yes
Fixed in Releases:
Found in Releases:

Description

We upgraded from foreman 1.16 to 1.17. (We saw the issue #23581 too).

In 1.16 we used erb templating in default values of smart class parameters. Example: https://[foreman]/api/smart_class_parameters/3308 - see "default_value" in last line of the output snippet:

description    "" 
override    true
parameter_type    "string" 
hidden_value?    false
omit    false
required    false
validator_type    "" 
validator_rule    null
merge_overrides    false
merge_default    false
avoid_duplicates    false
override_value_order    "fqdn\nhostgroup\nos\ndomain" 
created_at    "2016-11-18 13:09:14 UTC" 
updated_at    "2018-05-14 13:07:08 UTC" 
use_puppet_default    false
puppetclass_name    "collectd::plugin::amqp" 
parameter    "amqphost" 
id    3308
puppetclass_id    605
override_values_count    1
default_value    "<%= host_param('graphite_rabbitmq_server') %>" 
(...)

It is possible to edit and save/ sumbit the smart class param as a string with the erb templating in the web gui. The backend works fine.
Clicking on button YAML in a host detail (https://[foreman]/hosts/[host]/externalNodes?name=[host]
on screen appears "Unable to generate output, Check log files".

... and in the log: | NoMethodError: undefined method `host_param' for #<SafeRender:0x007f78426437c0> | Did you mean? to_param | (erb):1:in `parse_string'

If I change the default value to a normal string The Yaml parsing continues (= stops on another error I need to figure out later).
Maybe it is an erb templating error missing foreman function in the environment while parsing or maybe there an additional option I need to activate?!

My environment:
  • Foreman runs on CentOs 7.5.1804
  • option safemode_render is set to false
  • settings -> puppet -> Enable smart variables in ENC: true
  • settings -> puppet -> Parameterised classes in ENC: true
    (tell me what elso you would need)

production.log:

2018-05-14 09:43:24 8de7ab7f [app] [I] Processing by HostsController#externalNodes as HTML
2018-05-14 09:43:24 8de7ab7f [app] [I]   Parameters: {"name"=>"[host]", "id"=>"[host]"}
2018-05-14 09:43:24 8de7ab7f [app] [I] Current user: foreman_api_admin (administrator)
2018-05-14 09:43:26 8de7ab7f [app] [W] Failed to generate external nodes for [host]
 | NoMethodError: undefined method `host_param' for #<SafeRender:0x007f78426437c0>
 | Did you mean?  to_param
 | (erb):1:in `parse_string'
 | /opt/rh/rh-ruby24/root/usr/share/ruby/erb.rb:896:in `eval'
 | /opt/rh/rh-ruby24/root/usr/share/ruby/erb.rb:896:in `result'
 | /usr/share/foreman/app/services/safe_render.rb:39:in `parse_string'
 | /usr/share/foreman/app/services/safe_render.rb:18:in `parse'
 | /usr/share/foreman/app/services/classification/classification_result.rb:24:in `[]'
 | /usr/share/foreman/app/models/host_info_providers/puppet_info.rb:96:in `block in smart_class_params_for'
 | /usr/share/foreman/app/models/host_info_providers/puppet_info.rb:95:in `each'
 | /usr/share/foreman/app/models/host_info_providers/puppet_info.rb:95:in `smart_class_params_for'
 | /usr/share/foreman/app/models/host_info_providers/puppet_info.rb:25:in `block in puppetclass_parameters'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/relation/delegation.rb:39:in `each'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/relation/delegation.rb:39:in `each'
 | /usr/share/foreman/app/models/host_info_providers/puppet_info.rb:24:in `puppetclass_parameters'
 | /usr/share/foreman/app/models/host_info_providers/puppet_info.rb:87:in `classes_info_hash'
 | /usr/share/foreman/app/models/host_info_providers/puppet_info.rb:11:in `host_info'
 | /usr/share/foreman/app/models/concerns/host_info_extensions.rb:29:in `block in info'
 | /usr/share/foreman/app/models/concerns/host_info_extensions.rb:27:in `each'
 | /usr/share/foreman/app/models/concerns/host_info_extensions.rb:27:in `info'
 | /usr/share/foreman/app/controllers/hosts_controller.rb:206:in `block in externalNodes'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_controller/metal/mime_responds.rb:195:in `respond_to'
 | /usr/share/foreman/app/controllers/hosts_controller.rb:204:in `externalNodes'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/abstract_controller/base.rb:186:in `process_action'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_controller/metal/rendering.rb:30:in `process_action'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:108:in `block in run_callbacks'
 | /usr/share/foreman/app/controllers/concerns/application_shared.rb:15:in `set_timezone'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
 | /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:32:in `clear_thread'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
 | /usr/share/foreman/app/controllers/concerns/foreman/controller/topbar_sweeper.rb:12:in `set_topbar_sweeper_controller'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.4.1/lib/audited/sweeper.rb:14:in `around'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.4.1/lib/audited/sweeper.rb:14:in `around'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:135:in `run_callbacks'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/abstract_controller/callbacks.rb:19:in `process_action'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_controller/metal/rescue.rb:20:in `process_action'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/notifications.rb:166:in `block in instrument'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/notifications.rb:166:in `instrument'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/railties/controller_runtime.rb:22:in `process_action'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/abstract_controller/base.rb:124:in `process'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionview-5.1.4/lib/action_view/rendering.rb:30:in `process'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_controller/metal.rb:189:in `dispatch'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_controller/metal.rb:253:in `dispatch'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:31:in `serve'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/journey/router.rb:50:in `block in serve'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/journey/router.rb:33:in `each'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/journey/router.rb:33:in `serve'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:834:in `call'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-rails-0.5.6/lib/apipie/static_dispatcher.rb:65:in `call'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-rails-0.5.6/lib/apipie/extractor/recorder.rb:136:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/middleware/static.rb:125:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/middleware/static.rb:125:in `call'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-rails-0.5.6/lib/apipie/middleware/checksum_in_headers.rb:27:in `call'
 | /usr/share/foreman/lib/middleware/catch_json_parse_errors.rb:8:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/rack-2.0.3/lib/rack/etag.rb:25:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/rack-2.0.3/lib/rack/conditional_get.rb:25:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/rack-2.0.3/lib/rack/head.rb:12:in `call'
 | /usr/share/foreman/lib/middleware/session_safe_logging.rb:17:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:232:in `context'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:226:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/middleware/cookies.rb:613:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:97:in `run_callbacks'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/middleware/callbacks.rb:24:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/railties-5.1.4/lib/rails/rack/logger.rb:36:in `call_app'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/railties-5.1.4/lib/rails/rack/logger.rb:26:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb:13:in `call'
 | /usr/share/foreman/lib/middleware/tagged_logging.rb:18:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/middleware/request_id.rb:25:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/rack-2.0.3/lib/rack/method_override.rb:22:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/rack-2.0.3/lib/rack/runtime.rb:22:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/middleware/executor.rb:12:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.4/lib/action_dispatch/middleware/static.rb:125:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/rack-2.0.3/lib/rack/sendfile.rb:111:in `call'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/secure_headers-3.4.1/lib/secure_headers/middleware.rb:12:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/railties-5.1.4/lib/rails/engine.rb:522:in `call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/railties-5.1.4/lib/rails/railtie.rb:185:in `public_send'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/railties-5.1.4/lib/rails/railtie.rb:185:in `method_missing'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/rack-2.0.3/lib/rack/urlmap.rb:68:in `block in call'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `each'
 | /opt/theforeman/tfm-ror51/root/usr/share/gems/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `call'
 | /usr/share/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
 | /usr/share/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:149:in `accept_and_process_next_request'
 | /usr/share/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop'
 | /usr/share/ruby/vendor_ruby/phusion_passenger/request_handler.rb:415:in `block (3 levels) in start_threads'
 | /usr/share/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:in `block in create_with_logging_context'
2018-05-14 09:43:26 8de7ab7f [app] [I]   Rendering text template
2018-05-14 09:43:26 8de7ab7f [app] [I]   Rendered text template (0.0ms)
2018-05-14 09:43:26 8de7ab7f [app] [I] Completed 412 Precondition Failed in 1946ms (Views: 0.5ms | ActiveRecord: 35.6ms)


Related issues 1 (0 open1 closed)

Related to Foreman - Bug #20931: Using host_params in parameters leads to @Safemode doesn't allow to access 'host_params' on #<Safemode::ScopeObject>@ClosedIvan NecasActions
Actions #1

Updated by Axel Hahn over 6 years ago

  • Category set to Templates
Actions #2

Updated by Marek Hulán over 6 years ago

  • Related to Bug #20931: Using host_params in parameters leads to @Safemode doesn't allow to access 'host_params' on #<Safemode::ScopeObject>@ added
Actions #3

Updated by Marek Hulán over 6 years ago

I think this has been fixed by http://projects.theforeman.org/issues/20931/ in 1.18, I can no longer reproduce on my dev setup. Given the patch size, I'd prefer not trying to cherry-pick to 1.17 branch.

Actions #4

Updated by Axel Hahn over 6 years ago

Thanks for adding the comment and the given orientation in which version it should be fixed!

Actions #5

Updated by Tomer Brisker over 6 years ago

  • Translation missing: en.field_release changed from 296 to 360
Actions #6

Updated by Tomer Brisker over 6 years ago

  • Translation missing: en.field_release changed from 360 to 330
  • Triaged set to No

moving to 1.18.0, will verify this is fixed indeed - if you can test this in 1.18.0-RC3 that would be awesome!

Actions #7

Updated by Tomer Brisker over 6 years ago

  • Triaged changed from No to Yes
Actions #8

Updated by Tomer Brisker over 6 years ago

  • Target version changed from 1.18.0 to 1.18.1
Actions #9

Updated by Tomer Brisker over 6 years ago

  • Target version changed from 1.18.1 to 1.18.2
Actions #10

Updated by Ondřej Pražák about 6 years ago

  • Status changed from New to Duplicate
  • Fixed in Releases 1.18.2 added
  • Found in Releases 1.17.0 added
  • Found in Releases deleted (1.7.0)

Closing as a duplicate based on previous comments.

Actions #11

Updated by Tomer Brisker about 6 years ago

  • Fixed in Releases deleted (1.18.2)
Actions

Also available in: Atom PDF