Bug #9240
closedUsing hashes via api fails with !ruby/hash:ActiveSupport::HashWithIndifferentAccess
Description
We like to use the puppetlabs/lvm module via Foreman api.
Adding this hash via WebUI works fine:
###################################### testvg: physical_volumes: - /dev/sdb - /dev/sdc logical_volumes: test1: size: 128M mountpath: /opt/test1 test2: size: 128M mountpath: /opt/test2 test3: size: 128M mountpath: /opt/test3 test4: size: 128M mountpath: /opt/test4 test5: size: 128M mountpath: /opt/test5 ######################################
When using the API with this rest call:
curl -k -u username:password -H "Accept: version=2,application/json" -H "Content-Type: application/json" -X POST -d '{"override_value": {"match": "fqdn=server.example.com","value": {"testvg":{"physical_volumes":["/dev/sdb","/dev/sdc"],"logical_volumes":{"test1":{"size":"128M","mountpath":"/opt/test1"},"test2":{"size":"128M","mountpath":"/opt/test2"},"test3":{"size":"128M","mountpath":"/opt/test3"},"test4":{"size":"128M","mountpath":"/opt/test4"},"test5":{"size":"128M","mountpath":"/opt/test5"}}}}}}' https://foreman.example.com/api/smart_class_parameters/386/override_values
The call is accepted, but the entry in Foreman looks like this:
###################################### --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess testvg: !ruby/hash:ActiveSupport::HashWithIndifferentAccess physical_volumes: - /dev/sdb - /dev/sdc logical_volumes: !ruby/hash:ActiveSupport::HashWithIndifferentAccess test1: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test1 test2: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test2 test3: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test3 test4: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test4 test5: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test5 ######################################
Updated by The Foreman Bot over 9 years ago
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/2148 added
- Pull request deleted (
)
Updated by Blaine Gardner over 9 years ago
I have found a test case that this patch only partially addresses. I am using Ruby to script deployment of Ceph monitors using the stackforge/puppet-ceph module.
Without this patch, I get:
ceph::mons:
args: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
ceph-node-name: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
ensure: present
public_addr: IP_ADDR
authentication_type: none
With this patch, I get:
ceph::mons:
args:
ceph-node-name: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
ensure: present
public_addr: IP_ADDR
authentication_type: none
My JSON request looks like this: {"override_value":{"match":"fqdn=NAME.DOMAIN.NET","value":{"ceph-node-name":{"ensure":"present","public_addr":"IP_ADDR","authentication_type":"none"}}}}
Clearly, the patch has helped, but only on the first level of the hash.
Updated by Anonymous over 9 years ago
After applying the patch to v1.7.2 i get this entry:
testvg: !ruby/hash:ActiveSupport::HashWithIndifferentAccess physical_volumes: - /dev/sdb - /dev/sdc logical_volumes: !ruby/hash:ActiveSupport::HashWithIndifferentAccess test1: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test1 test2: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test2 test3: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test3 test4: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test4 test5: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test5
Updated by Tom Caspy over 9 years ago
can I just ask why is this a bug?
what's wrong with serializing this as hash with indifferent access?
Updated by Anonymous over 9 years ago
Tom Caspy wrote:
can I just ask why is this a bug?
what's wrong with serializing this as hash with indifferent access?
Because Foreman as ENC delivers a catalog for a client that does not work. This is the complete yaml file for the client:
--- classes: lvm: volume_groups: testvg: !ruby/hash:ActiveSupport::HashWithIndifferentAccess physical_volumes: - /dev/sdb - /dev/sdc logical_volumes: !ruby/hash:ActiveSupport::HashWithIndifferentAccess test1: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test1 test2: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test2 test3: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test3 test4: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test4 test5: !ruby/hash:ActiveSupport::HashWithIndifferentAccess size: 128M mountpath: /opt/test5 parameters: puppetmaster: foreman.example.com hostgroup: dev-rhel6 foreman_env: dev environment: dev
The client cannot apply the catalog because of the "!ruby/hash:ActiveSupport::HashWithIndifferentAccess" strings.
Updated by Anonymous over 9 years ago
Tom Caspy wrote:
can I just ask why is this a bug?
what's wrong with serializing this as hash with indifferent access?
Perhaps it's enough to just remove all strings with "!ruby/hash:ActiveSupport::HashWithIndifferentAccess"
before writing the hash to the Foreman database?
Updated by Tom Caspy over 9 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 3059cea1c207718217f07b9cdc706bc516f5db1b.
Updated by Dominic Cleal over 9 years ago
- Translation missing: en.field_release set to 50
Updated by The Foreman Bot over 6 years ago
- Pull request https://github.com/theforeman/foreman/pull/5422 added
Updated by Anonymous over 6 years ago
- Related to Refactor #23183: Remove HashWithIndifferentAccess workaround added
Updated by Anonymous over 6 years ago
- Pull request deleted (
https://github.com/theforeman/foreman/pull/5422)