Bug 1053471 - Fail to parse the env vars of an array of hashes when setting multiple env vars in one API call using SET_UNSET_ENVIRONMENT_VARIABLES, ADD_CARTRIDGE, or ADD_APPLICATION APIs
Summary: Fail to parse the env vars of an array of hashes when setting multiple env va...
Alias: None
Product: OpenShift Online
Classification: Red Hat
Component: Master
Version: 2.x
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
: ---
Assignee: Lili Nader
QA Contact: libra bugs
Depends On:
TreeView+ depends on / blocked
Reported: 2014-01-15 10:15 UTC by Zhe Wang
Modified: 2015-05-15 00:56 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2014-01-15 19:43:48 UTC
Target Upstream Version:

Attachments (Terms of Use)

Description Zhe Wang 2014-01-15 10:15:32 UTC
Description of problem:
When invoking SET_UNSET_ENVIRONMENT_VARIABLES API to operate on a batch of user-defined env vars, environment_variables_controller fails to parse the params of YAML format, which is officially documented in the description of the API:

                        "default_value": null, 
                        "description": "Add/Update/Delete application environment variables, e.g. Add/Update: [{'name':'FOO', 'value':'123'}, {'name':'BAR', 'value':'abc'}], {Delete: [{'name':'FOO'}, {'name':'BAR'}]}", 
                        "name": "environment_variables", 
                        "type": "array", 
                        "valid_options": []

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

How reproducible:

Steps to Reproduce:
1. create an app
3. add some env vars with the API using the example given in its description
curl -k -u user:password https://<BROKER_DNS>/broker/rest/application/52d64852afb999beeb000007/environment-variables -XPATCH -d environment_variables="[{'name':'FOO', 'value':'123'}, {'name':'BAR', 'value':'abc'}]" | python -m json.tool

Actual results:
When adding the BAR and FOO env vars in the example, it fails with the error below:

"api_version": 1.6, 
    "data": null, 
    "messages": [
            "exit_code": 186, 
            "field": "environment_variables", 
            "index": null, 
            "severity": "error", 
            "text": "Invalid environment variables: expected array of hashes"

Expected results:
Operating on a batch of env vars with SET_UNSET_ENVIRONMENT_VARIABLES API should be successful, with the param format given in the example. Otherwise, we need to update the documentation of this API.

Additional info:

Comment 1 Zhe Wang 2014-01-15 10:38:51 UTC
Similar problem also exists in the following APIs:

ADD_APPLICATION (with multiple env vars)
e.g., curl -k -u  user:password https://<BROKER_DNS>/broker/rest/domain/stg621/applications -XPOST -d name=py273 -d cartridges[][name]=python-2.7 -d environment_variables=[{'name':'FOO', 'value':'123'}, {'name':'BAR', 'value':'abc'}] | python -m json.tool

ADD_CARTRIDGE (with multiple env vars):
e.g., curl -k -u  user:password https://<BROKER_DNS>/broker/rest/application/52d635f96993b9bb88000007/cartridges -d name=mongodb-2.2 -d environment_variables="[{'name':'FOO', 'value':'123'}, {'name':'BAR', 'value':'abc'}]" | python -m json.tool

Comment 2 Zhe Wang 2014-01-15 13:49:37 UTC
I also tried with the following format, but none of these succeeded. Maybe we need to change the type of environment_variables to string, or change the description somehow.

1. without white spaces in the value of environment_variables

-d environment_variables=[{'name':'BAR','value':'123'},{'name':'FOO','value':'abc'}] 

curl -k -u user:password 
https://<BROKER>/broker/rest/application/52d68ddd819d378008000007/environment-variables -d environment_variables=[{'name':'BAR', 'value':'123'},{'name':'FOO', 'value':'abc'}] -XPATCH | python -m json.tool

2. -d environment_variables[]=[{'name':'BAR', 'value':'123'},{'name':'FOO', 'value':'abc'}]

3. -d environment_variables[0]={'name':'BAR', 'value':'123'} 

4. using escaping chars
-d environment_variables=\[\{\'name\'\:\'BAR\'\,\'value\'\:\'123\'\}\,\{\'name\'\:\'FOO\'\,\'value\'\:\'abc\'\}\]

5. using a json obj:
{'environment_variables': [{'name':'BAR','value':'123'},{'name':'FOO','value':'abc'}]}

Comment 3 Clayton Coleman 2014-01-15 19:43:48 UTC
You have to post as valid JSON

curl -X PATCH -H "Content-Type: application/json" -d "{'environment_variables': [{'name':'BAR','value':'123'},{'name':'FOO','value':'abc'}]}"

That works for me.

-d environment_variables=[...] is not a valid JSON document, you'd have to be using:


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