Project

General

Profile

Bug #9240

Using hashes via api fails with !ruby/hash:ActiveSupport::HashWithIndifferentAccess

Added by Anonymous over 7 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
API
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

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
######################################

Related issues

Related to Foreman - Refactor #23183: Remove HashWithIndifferentAccess workaroundNew

Associated revisions

Revision 3059cea1 (diff)
Added by Tom Caspy about 7 years ago

fixes #9240 - in case of hash with indifferent access, serialize as hash

Revision 7875f359 (diff)
Added by Tom Caspy about 7 years ago

fixes #9240 - in case of hash with indifferent access, serialize as hash

(cherry picked from commit 3059cea1c207718217f07b9cdc706bc516f5db1b)

History

#1 Updated by Dominic Cleal over 7 years ago

  • Description updated (diff)

#2 Updated by Tom Caspy over 7 years ago

  • Assignee set to Tom Caspy

#3 Updated by The Foreman Bot over 7 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/2148 added
  • Pull request deleted ()

#4 Updated by Blaine Gardner over 7 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.

#5 Updated by Anonymous over 7 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

#6 Updated by Tom Caspy over 7 years ago

can I just ask why is this a bug?
what's wrong with serializing this as hash with indifferent access?

#7 Updated by Anonymous over 7 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.

#8 Updated by Anonymous over 7 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?

#9 Updated by Tom Caspy about 7 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#10 Updated by Dominic Cleal about 7 years ago

  • Legacy Backlogs Release (now unused) set to 50

#11 Updated by The Foreman Bot about 4 years ago

  • Pull request https://github.com/theforeman/foreman/pull/5422 added

#12 Updated by Anonymous about 4 years ago

  • Related to Refactor #23183: Remove HashWithIndifferentAccess workaround added

#13 Updated by Anonymous about 4 years ago

  • Pull request deleted (https://github.com/theforeman/foreman/pull/5422)

Also available in: Atom PDF