Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter type normalization #1663

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions plugins/module_utils/foreman_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1755,9 +1755,7 @@ def _is_resolved(spec, what):
# Helper for (global, operatingsystem, ...) parameters
def parameter_value_to_str(value, parameter_type):
"""Helper to convert the value of parameters to string according to their parameter_type."""
if parameter_type in ['real', 'integer']:
parameter_string = str(value)
elif parameter_type in ['array', 'hash', 'yaml', 'json']:
if parameter_type in ['real', 'integer', 'string', 'array', 'hash', 'yaml', 'json'] and not isinstance(value, six.string_types):
parameter_string = json.dumps(value, sort_keys=True)
else:
parameter_string = value
Expand Down
38 changes: 17 additions & 21 deletions tests/test_playbooks/fixtures/global_parameter-0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ interactions:
uri: https://foreman.example.org/api/status
response:
body:
string: '{"result":"ok","status":200,"version":"2.2.0-rc3","api_version":2}'
string: '{"result":"ok","status":200,"version":"3.7.0","api_version":2}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Length:
- '62'
Content-Security-Policy:
- 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:;
img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self'';
Expand All @@ -33,13 +35,11 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.2.0-rc3
- 3.7.0
Keep-Alive:
- timeout=15, max=100
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Download-Options:
Expand All @@ -50,8 +50,6 @@ interactions:
- none
X-XSS-Protection:
- 1; mode=block
content-length:
- '66'
status:
code: 200
message: OK
Expand All @@ -70,14 +68,16 @@ interactions:
uri: https://foreman.example.org/api/common_parameters?show_hidden=true&search=name%3D%22TheAnswer%22&per_page=4294967296
response:
body:
string: "{\n \"total\": 0,\n \"subtotal\": 0,\n \"page\": 1,\n \"per_page\"\
: 4294967296,\n \"search\": \"name=\\\"TheAnswer\\\"\",\n \"sort\": {\n\
\ \"by\": null,\n \"order\": null\n },\n \"results\": []\n}\n"
string: "{\n \"total\": 4,\n \"subtotal\": 0,\n \"page\": 1,\n \"per_page\":
4294967296,\n \"search\": \"name=\\\"TheAnswer\\\"\",\n \"sort\": {\n \"by\":
null,\n \"order\": null\n },\n \"results\": []\n}\n"
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Length:
- '175'
Content-Security-Policy:
- 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:;
img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self'';
Expand All @@ -91,13 +91,11 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.2.0-rc3
- 3.7.0
Keep-Alive:
- timeout=15, max=99
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Download-Options:
Expand All @@ -108,13 +106,11 @@ interactions:
- none
X-XSS-Protection:
- 1; mode=block
content-length:
- '175'
status:
code: 200
message: OK
- request:
body: '{"common_parameter": {"name": "TheAnswer", "value": 42, "parameter_type":
body: '{"common_parameter": {"name": "TheAnswer", "value": "42", "parameter_type":
"string"}}'
headers:
Accept:
Expand All @@ -124,7 +120,7 @@ interactions:
Connection:
- keep-alive
Content-Length:
- '84'
- '86'
Content-Type:
- application/json
User-Agent:
Expand All @@ -133,13 +129,15 @@ interactions:
uri: https://foreman.example.org/api/common_parameters
response:
body:
string: '{"created_at":"2020-10-16 13:53:30 UTC","updated_at":"2020-10-16 13:53:30
UTC","hidden_value?":false,"hidden_value":"*****","id":11,"name":"TheAnswer","parameter_type":"string","value":42}'
string: '{"created_at":"2023-08-24 07:13:28 UTC","updated_at":"2023-08-24 07:13:28
UTC","hidden_value?":false,"hidden_value":"*****","id":9,"name":"TheAnswer","parameter_type":"string","value":"42"}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Length:
- '189'
Content-Security-Policy:
- 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:;
img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self'';
Expand All @@ -153,13 +151,11 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.2.0-rc3
- 3.7.0
Keep-Alive:
- timeout=15, max=98
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
X-Download-Options:
Expand Down
42 changes: 17 additions & 25 deletions tests/test_playbooks/fixtures/global_parameter-1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ interactions:
uri: https://foreman.example.org/api/status
response:
body:
string: '{"result":"ok","status":200,"version":"2.2.0-rc3","api_version":2}'
string: '{"result":"ok","status":200,"version":"3.7.0","api_version":2}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Length:
- '62'
Content-Security-Policy:
- 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:;
img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self'';
Expand All @@ -33,13 +35,11 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.2.0-rc3
- 3.7.0
Keep-Alive:
- timeout=15, max=100
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Download-Options:
Expand All @@ -50,8 +50,6 @@ interactions:
- none
X-XSS-Protection:
- 1; mode=block
content-length:
- '66'
status:
code: 200
message: OK
Expand All @@ -70,17 +68,17 @@ interactions:
uri: https://foreman.example.org/api/common_parameters?show_hidden=true&search=name%3D%22TheAnswer%22&per_page=4294967296
response:
body:
string: "{\n \"total\": 1,\n \"subtotal\": 1,\n \"page\": 1,\n \"per_page\"\
: 4294967296,\n \"search\": \"name=\\\"TheAnswer\\\"\",\n \"sort\": {\n\
\ \"by\": null,\n \"order\": null\n },\n \"results\": [{\"created_at\"\
:\"2020-10-16 13:53:30 UTC\",\"updated_at\":\"2020-10-16 13:53:30 UTC\",\"\
hidden_value?\":false,\"hidden_value\":\"*****\",\"id\":11,\"name\":\"TheAnswer\"\
,\"parameter_type\":\"string\",\"value\":42}]\n}\n"
string: "{\n \"total\": 5,\n \"subtotal\": 1,\n \"page\": 1,\n \"per_page\":
4294967296,\n \"search\": \"name=\\\"TheAnswer\\\"\",\n \"sort\": {\n \"by\":
null,\n \"order\": null\n },\n \"results\": [{\"created_at\":\"2023-08-24
07:13:28 UTC\",\"updated_at\":\"2023-08-24 07:13:28 UTC\",\"hidden_value?\":false,\"hidden_value\":\"*****\",\"id\":9,\"name\":\"TheAnswer\",\"parameter_type\":\"string\",\"value\":\"42\"}]\n}\n"
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Length:
- '364'
Content-Security-Policy:
- 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:;
img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self'';
Expand All @@ -94,13 +92,11 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.2.0-rc3
- 3.7.0
Keep-Alive:
- timeout=15, max=99
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Download-Options:
Expand All @@ -111,8 +107,6 @@ interactions:
- none
X-XSS-Protection:
- 1; mode=block
content-length:
- '363'
status:
code: 200
message: OK
Expand All @@ -128,16 +122,18 @@ interactions:
User-Agent:
- apypie (https://github.com/Apipie/apypie)
method: GET
uri: https://foreman.example.org/api/common_parameters/11?show_hidden=true
uri: https://foreman.example.org/api/common_parameters/9?show_hidden=true
response:
body:
string: '{"created_at":"2020-10-16 13:53:30 UTC","updated_at":"2020-10-16 13:53:30
UTC","hidden_value?":false,"hidden_value":"*****","id":11,"name":"TheAnswer","parameter_type":"string","value":42}'
string: '{"created_at":"2023-08-24 07:13:28 UTC","updated_at":"2023-08-24 07:13:28
UTC","hidden_value?":false,"hidden_value":"*****","id":9,"name":"TheAnswer","parameter_type":"string","value":"42"}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Length:
- '189'
Content-Security-Policy:
- 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:;
img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self'';
Expand All @@ -151,13 +147,11 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.2.0-rc3
- 3.7.0
Keep-Alive:
- timeout=15, max=98
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Download-Options:
Expand All @@ -168,8 +162,6 @@ interactions:
- none
X-XSS-Protection:
- 1; mode=block
content-length:
- '188'
status:
code: 200
message: OK
Expand Down
Loading
Loading