Project

General

Profile

Actions

Bug #9240

closed

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

Added by Anonymous over 9 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
API
Target version:
Difficulty:
Triaged:
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 1 (1 open0 closed)

Related to Foreman - Refactor #23183: Remove HashWithIndifferentAccess workaroundNewActions
Actions #1

Updated by Dominic Cleal over 9 years ago

  • Description updated (diff)
Actions #2

Updated by Tom Caspy over 9 years ago

  • Assignee set to Tom Caspy
Actions #3

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 ()
Actions #4

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.

Actions #5

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

Actions #6

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?

Actions #7

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.

Actions #8

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?

Actions #9

Updated by Tom Caspy over 9 years ago

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

Updated by Dominic Cleal over 9 years ago

  • Translation missing: en.field_release set to 50
Actions #11

Updated by The Foreman Bot over 6 years ago

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

Updated by Anonymous over 6 years ago

  • Related to Refactor #23183: Remove HashWithIndifferentAccess workaround added
Actions #13

Updated by Anonymous over 6 years ago

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

Also available in: Atom PDF