Bug 1241249 - Smart Class Parameter override default values are changed by the system, causing faulty YAML generation or error when generating YAML
Summary: Smart Class Parameter override default values are changed by the system, caus...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Configuration Management
Version: 6.1.0
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: Unspecified
Assignee: orabin
QA Contact: Kedar Bidarkar
URL:
Whiteboard:
: 1319383 1320572 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-07-08 20:21 UTC by Harald Jensås
Modified: 2020-05-14 14:59 UTC (History)
20 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-07-27 08:53:30 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2016:1500 0 normal SHIPPED_LIVE Red Hat Satellite 6.2 Base Libraries 2016-07-27 12:24:38 UTC

Description Harald Jensås 2015-07-08 20:21:45 UTC
Description of problem:
Smart Class Parameter override default values are changed by the system, causing faulty YAML generation or error when generating YAML.

Double quotes or other formating depending on the parameter type is added to the user input, causing problems if the user goes back to enable overides for other parameters of the class, or simply look at the current overrides and then press 'Submit' without any changes.

Version-Release number of selected component (if applicable):
Satellite 6.1.0 Beta

How reproducible:
Easy, detailed steps below.

Steps to Reproduce:
1. Add puppet plugins to Satellite
(This problem is not specific to these modules, but it is a good example)
https://forge.puppetlabs.com/saz/resolv_conf
https://forge.puppetlabs.com/puppetlabs/stdlib
2. Configure -> Puppet classes -> resolv_conf
3. Select "Smart Class Parameter" tab.
4. Select "nameservers" parameter.
5. Tick the "Overide" box.
6. Set "Parameter Type" == "Array"
7. In "Default value" type in: 

 ['<%= @host.subnet.dns_primary %>', '<%= @host.subnet.dns_secondary %>']

8. Select "searchpath" parameter.
9. Tick the "Overide" box.
10. Set "Parameter Type" == "Array"
11. In "Default value" type in:

 ['<%= @host.domain %>']

12. Add the puppet modules to a content view.
13. Change Puppet Environment on a host to match the content view where the modules are available.
14. Edit the puppet classes of the host to include the 'resolve_conf' class and submit changes.
15. Look at the YAML for the host.
 Example YAML at this stage:

classes:
  resolv_conf:
    nameservers:
    - 192.168.102.254
    - 192.168.101.10
    searchpath:
    - lnx.example.com

16. Configure -> Puppet classes -> resolv_conf
17. Select "Smart Class Parameter" tab.
18. Look at the current settings.
 NOTICE: Double quotes have been added to the previously entered values in "Default Values" fields.

 nameserver value is now:
   "['<%= @host.subnet.dns_primary %>', '<%= @host.subnet.dns_secondary %>']"
 searchpat value is now:
   "['<%= @host.domain %>']"
19. Do not change anything.
20. Press the 'Submit' to "apply" changes button.
21. Go back to your host and look at the YAML, it gives error:

 """ Unable to generate output, Check log files\n """

In production log:
015-07-08 22:02:12 [I] Processing by HostsController#externalNodes as HTML
2015-07-08 22:02:12 [I]   Parameters: {"name"=>"test01.lnx.example.com", "id"=>"test01.lnx.example.com"}
2015-07-08 22:02:12 [W] No SSL cert with CN supplied - request from 192.168.102.1, 
2015-07-08 22:02:14 [W] Failed to generate external nodes for test01.lnx.example.com with undefined local variable or method `logger' for #<Classification::ClassParam:0x0000000e812370>
2015-07-08 22:02:14 [I]   Rendered text template (0.0ms)
2015-07-08 22:02:14 [I] Completed 412 Precondition Failed in 1675ms (Views: 205.3ms | ActiveRecord: 69.7ms)


Actual results:
double quotes and something other escape chars are added to the original input in the "Default Value" field of smart parameters. 

This causes YAML to either fail to render, or change the result.

Expected results:
The values typed in should not be changed, and looking at or changing a different smart parameter value and submitting changes should to cause changes to other smart parameter default value overrides to change and break previously working configuration

Additional info:
Try to play with using yaml format in overrides instead of array as well.

Example:
nameserver default value type as yaml:
- <%= @host.subnet.dns_primary %>
- <%= @host.subnet.dns_secondary %>
searchpath default value type as yaml:
- <%= @host.domain %>

Submit, and YAML result is:

classes:
  resolv_conf:
    nameservers:
    - 192.168.102.254
    - 192.168.101.10
    searchpath:
    - lnx.example.com

Go back and look at Smart Class Parmeters for the puppet class, notice that values have changed to:

namservers:
--- ! "- <%= @host.subnet.dns_primary %>\r\n- <%= @host.subnet.dns_secondary %>"
searchpath
--- ! '- <%= @host.domain %>'

WHY? WHAT?

Don't change anything, press submit again and have a look at the host YAML wich is now _broken_.

classes:
  resolv_conf:
    nameservers: ! "- 192.168.102.254\r\n- 192.168.101.10"
    searchpath: ! '- lnx.example.com'

Comment 1 RHEL Program Management 2015-07-08 20:35:57 UTC
Since this issue was entered in Red Hat Bugzilla, the release flag has been
set to ? to ensure that it is properly evaluated for this release.

Comment 5 Tom Caspy 2015-07-19 14:02:44 UTC
When using ERB we evaluate the value only when creating the ENC output. This is done so erb values can use parameters that haven't been evaluated yet and you do not need all of the information available when editing the erb. As a result the erb values are left untouched (as strings) so your value was converted to a string.
When using the Ruby array your value gets evaluated and then cast to an array as needed.

Workaround:
instead, use a Ruby array:
<%= [@host.subnet.dns_primary, @host.subnet.dns_secondary] %>

Comment 9 Dennis Ortsen 2015-10-07 12:12:08 UTC
For those interested: there is another workaround for json parameter types. We've found that these exhibit the same problem as with arrays. We've just updated Satellite 6.0.8 to 6.1.2 and have encountered the exact same error. But not only with arrays, also with  json parameter types.

After trial and error, we've found a workaround to get json parsed as YAML. Perhaps it's a feature but we haven't found it in documentation (or haven't searched hard enough).

Without further a do:

On overriding, check the paramater type to be a hash, and enter a json string into the value box. Upon clicking the submit button, the json string is converted in correct, parsing YAML (which is what we needed). The YAML output for a host is now accepted and puppet agents can run again.

For instance, what we had working before the Satellite upgrade was:

{"zabbix":{"priority":"10","content":"Cmnd_Alias ZABBIX_CMNDS = /usr/sbin/dmidecode , /usr/bin/facter , /usr/bin/zems\nzabbix ALL = NOPASSWD : ZABBIX_CMNDS\nDefaults:zabbix !requiretty"}}

Which didn't work after the upgrade. Following the example above, this json string was converted to:

zabbix:
  priority: '10'
  content: ! 'Cmnd_Alias ZABBIX_CMNDS = /usr/sbin/dmidecode , /usr/bin/facter , /usr/bin/zems

    zabbix ALL = NOPASSWD : ZABBIX_CMNDS

    Defaults:zabbix !requiretty'


(for those interested, we are overriding the config for this puppet module: https://forge.puppetlabs.com/saz/sudo/readme)

Comment 13 Bryan Kearney 2016-04-20 13:40:20 UTC
*** Bug 1319383 has been marked as a duplicate of this bug. ***

Comment 14 Kedar Bidarkar 2016-07-13 11:05:02 UTC
VERIFIED this with sat62-snap19(GA)


1) added those parameters and submitted
2) the YAML file for the host displayed both "nameserver" and "searchpath"
3) Edited the pupp-class parameters and submitted
4) The YAML file now can still be viewed from the UI without any issues.

Please feel free to reopen this bug if this issue is seen for other types or with other puppet-class parameters.

Comment 16 errata-xmlrpc 2016-07-27 08:53:30 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2016:1500

Comment 19 orabin 2017-12-26 15:43:02 UTC
*** Bug 1320572 has been marked as a duplicate of this bug. ***


Note You need to log in before you can comment on or make changes to this bug.