Project

General

Profile

Actions

Bug #20348

closed

Hammer Does Not Consistently Escape Quotes When Assigning JSON To A Host Parameter.

Added by Tomáš Strachota over 6 years ago. Updated over 4 years ago.

Status:
Resolved
Priority:
Normal
Category:
Hammer core
Target version:
-
Difficulty:
Triaged:
No
Team Backlog:
Marek
Fixed in Releases:
Found in Releases:
In Kanboard:

Description

Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1466059

Description of problem:

When attempting to update a host, like so:

# hammer -u username host update --name testserver.example.com --parameters diskinfo2='[{"group": "apache", "pciid": 160, "fstype": "ext4", "mntopts": "", "owner": "root", "path": "/mount/point/1", "fmtopts": "", "scsiid": 1, "size": 75}, {"group": "apache", "pciid": 160, "fstype": "xfs", "mntopts": "", "owner": "apache", "path": "/mount/point/2", "fmtopts": "", "scsiid": 2, "size": 200}]'

...the host parameter "diskinfo2" is set to:

["{\"group\": \"apache", "pciid\": 160", "fstype\": \"ext4", "mntopts\": ", "owner\": \"root", "path\": \"/mount/point/1", "fmtopts\": ", "scsiid\": 1", "size\": 75}", "{\"group\": \"apache", "pciid\": 160", "fstype\": \"xfs", "mntopts\": ", "owner\": \"apache", "path\": \"/mount/point/2", "fmtopts\": ", "scsiid\": 2", "size\": 200}"]

(Note the inconsistently escaped quotes, like "size\" instead of \"size\".)

The issue is in 'KeyValueList' option normalizer that wrongly splits the key-value pairs.


Related issues 1 (0 open1 closed)

Related to Hammer CLI - Bug #26120: Insufficient parsing capabilities of complex list type optionsClosedOleh FedorenkoActions
Actions #1

Updated by Tomáš Strachota over 6 years ago

  • Subject changed from Hammer Does Not Consistently Escape Quotes When Assigning JSON To A Host Parameter. to Hammer Does Not Consistently Escape Quotes When Assigning JSON To A Host Parameter.
  • Category changed from Other commands to Hammer core
  • Target version set to 115
Actions #2

Updated by Aditi Puntambekar over 5 years ago

  • Assignee set to Aditi Puntambekar
  • Triaged set to No
Actions #3

Updated by Tomáš Strachota over 5 years ago

Just for the record:
Setting parameters with set-parameter command works correctly and can be used as a workaround. It's only the update command that's broken.

Actions #4

Updated by The Foreman Bot over 5 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/hammer-cli/pull/290 added
Actions #5

Updated by Martin Bacovsky over 5 years ago

During testing the PR I've noticed the format used is actually not valid. For --params option we support either comma separated list of key=value or JSON. For some reason we try to parse also the value if it is list which is causing problems here. The format used is mix of CSV and JSON which needs to be avoided.

My suggestion is either to use JSON (recomended for more complex params):

hammer -u username host update --name testserver.example.com --parameters '{"diskinfo3":[{"group": "apache", "pciid": 160, "fstype": "ext4", "mntopts": "", "owner": "root", "path": "/mount/point/1", "fmtopts": "", "scsiid": 1, "size": 75}, {"group": "apache", "pciid": 160, "fstype": "xfs", "mntopts": "", "owner": "apache", "path": "/mount/point/2", "fmtopts": "", "scsiid": 2, "size": 200}]}'

or comma separated list which needs proper quoting (I didn't tested the API can handle this particular case):

hammer -u username host update --name testserver.example.com --parameters diskinfo3=['{"group": "apache", "pciid": 160, "fstype": "ext4", "mntopts": "", "owner": "root", "path": "/mount/point/1", "fmtopts": "", "scsiid": 1, "size": 75}', '{"group": "apache", "pciid": 160, "fstype": "xfs", "mntopts": "", "owner": "apache", "path": "/mount/point/2", "fmtopts": "", "scsiid": 2, "size": 200}']

The comma separated list does not work properly and needs to be fixed. I'll keep this issue to track that.

Actions #6

Updated by Martin Bacovsky about 5 years ago

  • Related to Bug #26120: Insufficient parsing capabilities of complex list type options added
Actions #7

Updated by Martin Bacovsky over 4 years ago

This issue should be fixed by the fix for the related issue #26120. Closing

Actions #8

Updated by Martin Bacovsky over 4 years ago

  • Status changed from Ready For Testing to Resolved
Actions

Also available in: Atom PDF