Skip to content

Commit

Permalink
changed parameter_type to be None instead of empty string when overri…
Browse files Browse the repository at this point in the history
…de is set to false
  • Loading branch information
yuqo2450 authored and evgeni committed Jul 26, 2023
1 parent 7e36b39 commit 4ab1774
Show file tree
Hide file tree
Showing 62 changed files with 2,284 additions and 2,211 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- smart_class_parameter - correctly allow setting ``override`` to ``false`` (https://github.com/theforeman/foreman-ansible-modules/issues/1644)
2 changes: 1 addition & 1 deletion plugins/modules/smart_class_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def main():
module.set_entity('entity', entity)
# When override is set to false, foreman API don't accept parameter_type and all 'override options' have to be set to false if present
if not module_params.get('override', False):
module_params['parameter_type'] = ''
module_params['parameter_type'] = None
for override_option in ['merge_default', 'merge_overrides', 'avoid_duplicates']:
if override_option in entity and entity[override_option]:
module_params[override_option] = False
Expand Down
43 changes: 21 additions & 22 deletions tests/test_playbooks/fixtures/smart_class_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":"3.5.0-rc1","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:
- 3.5.0-rc1
- 3.7.0
Keep-Alive:
- timeout=15, max=100
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
X-Download-Options:
Expand Down Expand Up @@ -71,13 +71,15 @@ interactions:
string: "{\n \"total\": 71,\n \"subtotal\": 1,\n \"page\": 1,\n \"per_page\":
4294967296,\n \"search\": \"puppetclass_name=ntp and parameter=logfile\",\n
\ \"sort\": {\n \"by\": null,\n \"order\": null\n },\n \"results\":
[{\"description\":\"\",\"override\":false,\"parameter_type\":\"\",\"hidden_value?\":false,\"omit\":null,\"required\":false,\"validator_type\":null,\"validator_rule\":null,\"merge_overrides\":false,\"merge_default\":false,\"avoid_duplicates\":false,\"override_value_order\":\"fqdn\\nhostgroup\\nos\\ndomain\",\"created_at\":\"2022-11-25
11:45:14 UTC\",\"updated_at\":\"2022-11-25 11:46:51 UTC\",\"parameter\":\"logfile\",\"id\":16,\"puppetclass_id\":2,\"override_values_count\":0,\"default_value\":\"\",\"puppetclass_name\":\"ntp\"}]\n}\n"
[{\"description\":\"\",\"override\":false,\"parameter_type\":\"\",\"hidden_value?\":false,\"omit\":false,\"required\":false,\"validator_type\":null,\"validator_rule\":null,\"merge_overrides\":false,\"merge_default\":false,\"avoid_duplicates\":false,\"override_value_order\":\"fqdn\\nhostgroup\\nos\\ndomain\",\"created_at\":\"2023-07-26
07:53:31 UTC\",\"updated_at\":\"2023-07-26 08:08:34 UTC\",\"parameter\":\"logfile\",\"id\":16,\"puppetclass_id\":2,\"override_values_count\":0,\"default_value\":\"\",\"puppetclass_name\":\"ntp\"}]\n}\n"
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Length:
- '672'
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 +93,11 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 3.5.0-rc1
- 3.7.0
Keep-Alive:
- timeout=15, max=99
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
X-Download-Options:
Expand Down Expand Up @@ -126,13 +126,15 @@ interactions:
uri: https://foreman.example.org/foreman_puppet/api/smart_class_parameters/16
response:
body:
string: '{"description":"","override":false,"parameter_type":"","hidden_value?":false,"omit":null,"required":false,"validator_type":null,"validator_rule":null,"merge_overrides":false,"merge_default":false,"avoid_duplicates":false,"override_value_order":"fqdn\nhostgroup\nos\ndomain","created_at":"2022-11-25
11:45:14 UTC","updated_at":"2022-11-25 11:46:51 UTC","parameter":"logfile","id":16,"puppetclass_id":2,"override_values_count":0,"default_value":"","puppetclass_name":"ntp","environments":[{"name":"production","id":1}],"puppetclass":{"id":2,"name":"ntp","module_name":"ntp"},"override_values":[]}'
string: '{"description":"","override":false,"parameter_type":"","hidden_value?":false,"omit":false,"required":false,"validator_type":null,"validator_rule":null,"merge_overrides":false,"merge_default":false,"avoid_duplicates":false,"override_value_order":"fqdn\nhostgroup\nos\ndomain","created_at":"2023-07-26
07:53:31 UTC","updated_at":"2023-07-26 08:08:34 UTC","parameter":"logfile","id":16,"puppetclass_id":2,"override_values_count":0,"default_value":"","puppetclass_name":"ntp","environments":[{"name":"production","id":1}],"puppetclass":{"id":2,"name":"ntp","module_name":"ntp"},"override_values":[]}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Length:
- '595'
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 @@ -146,13 +148,11 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 3.5.0-rc1
- 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 All @@ -167,8 +167,7 @@ interactions:
code: 200
message: OK
- request:
body: '{"smart_class_parameter": {"override": true, "description": "ntp log file",
"omit": false}}'
body: '{"smart_class_parameter": {"override": true, "description": "ntp log file"}}'
headers:
Accept:
- application/json;version=2
Expand All @@ -177,7 +176,7 @@ interactions:
Connection:
- keep-alive
Content-Length:
- '91'
- '76'
Content-Type:
- application/json
User-Agent:
Expand All @@ -186,13 +185,15 @@ interactions:
uri: https://foreman.example.org/foreman_puppet/api/smart_class_parameters/16
response:
body:
string: '{"description":"ntp log file","override":true,"parameter_type":"","hidden_value?":false,"omit":false,"required":false,"validator_type":null,"validator_rule":null,"merge_overrides":false,"merge_default":false,"avoid_duplicates":false,"override_value_order":"fqdn\nhostgroup\nos\ndomain","created_at":"2022-11-25
11:45:14 UTC","updated_at":"2022-11-25 11:46:53 UTC","parameter":"logfile","id":16,"puppetclass_id":2,"override_values_count":0,"default_value":"","puppetclass_name":"ntp","environments":[{"name":"production","id":1}],"puppetclass":{"id":2,"name":"ntp","module_name":"ntp"},"override_values":[]}'
string: '{"description":"ntp log file","override":true,"parameter_type":"","hidden_value?":false,"omit":false,"required":false,"validator_type":null,"validator_rule":null,"merge_overrides":false,"merge_default":false,"avoid_duplicates":false,"override_value_order":"fqdn\nhostgroup\nos\ndomain","created_at":"2023-07-26
07:53:31 UTC","updated_at":"2023-07-26 08:08:37 UTC","parameter":"logfile","id":16,"puppetclass_id":2,"override_values_count":0,"default_value":"","puppetclass_name":"ntp","environments":[{"name":"production","id":1}],"puppetclass":{"id":2,"name":"ntp","module_name":"ntp"},"override_values":[]}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Length:
- '606'
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 @@ -206,13 +207,11 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 3.5.0-rc1
- 3.7.0
Keep-Alive:
- timeout=15, max=97
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
X-Download-Options:
Expand Down
28 changes: 14 additions & 14 deletions tests/test_playbooks/fixtures/smart_class_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":"3.5.0-rc1","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:
- 3.5.0-rc1
- 3.7.0
Keep-Alive:
- timeout=15, max=100
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
X-Download-Options:
Expand Down Expand Up @@ -71,13 +71,15 @@ interactions:
string: "{\n \"total\": 71,\n \"subtotal\": 1,\n \"page\": 1,\n \"per_page\":
4294967296,\n \"search\": \"puppetclass_name=ntp and parameter=logfile\",\n
\ \"sort\": {\n \"by\": null,\n \"order\": null\n },\n \"results\":
[{\"description\":\"ntp log file\",\"override\":true,\"parameter_type\":\"\",\"hidden_value?\":false,\"omit\":false,\"required\":false,\"validator_type\":null,\"validator_rule\":null,\"merge_overrides\":false,\"merge_default\":false,\"avoid_duplicates\":false,\"override_value_order\":\"fqdn\\nhostgroup\\nos\\ndomain\",\"created_at\":\"2022-11-25
11:45:14 UTC\",\"updated_at\":\"2022-11-25 11:46:53 UTC\",\"parameter\":\"logfile\",\"id\":16,\"puppetclass_id\":2,\"override_values_count\":0,\"default_value\":\"\",\"puppetclass_name\":\"ntp\"}]\n}\n"
[{\"description\":\"ntp log file\",\"override\":true,\"parameter_type\":\"\",\"hidden_value?\":false,\"omit\":false,\"required\":false,\"validator_type\":null,\"validator_rule\":null,\"merge_overrides\":false,\"merge_default\":false,\"avoid_duplicates\":false,\"override_value_order\":\"fqdn\\nhostgroup\\nos\\ndomain\",\"created_at\":\"2023-07-26
07:53:31 UTC\",\"updated_at\":\"2023-07-26 08:08:37 UTC\",\"parameter\":\"logfile\",\"id\":16,\"puppetclass_id\":2,\"override_values_count\":0,\"default_value\":\"\",\"puppetclass_name\":\"ntp\"}]\n}\n"
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Length:
- '683'
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 +93,11 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 3.5.0-rc1
- 3.7.0
Keep-Alive:
- timeout=15, max=99
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
X-Download-Options:
Expand Down Expand Up @@ -126,13 +126,15 @@ interactions:
uri: https://foreman.example.org/foreman_puppet/api/smart_class_parameters/16
response:
body:
string: '{"description":"ntp log file","override":true,"parameter_type":"","hidden_value?":false,"omit":false,"required":false,"validator_type":null,"validator_rule":null,"merge_overrides":false,"merge_default":false,"avoid_duplicates":false,"override_value_order":"fqdn\nhostgroup\nos\ndomain","created_at":"2022-11-25
11:45:14 UTC","updated_at":"2022-11-25 11:46:53 UTC","parameter":"logfile","id":16,"puppetclass_id":2,"override_values_count":0,"default_value":"","puppetclass_name":"ntp","environments":[{"name":"production","id":1}],"puppetclass":{"id":2,"name":"ntp","module_name":"ntp"},"override_values":[]}'
string: '{"description":"ntp log file","override":true,"parameter_type":"","hidden_value?":false,"omit":false,"required":false,"validator_type":null,"validator_rule":null,"merge_overrides":false,"merge_default":false,"avoid_duplicates":false,"override_value_order":"fqdn\nhostgroup\nos\ndomain","created_at":"2023-07-26
07:53:31 UTC","updated_at":"2023-07-26 08:08:37 UTC","parameter":"logfile","id":16,"puppetclass_id":2,"override_values_count":0,"default_value":"","puppetclass_name":"ntp","environments":[{"name":"production","id":1}],"puppetclass":{"id":2,"name":"ntp","module_name":"ntp"},"override_values":[]}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Length:
- '606'
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 @@ -146,13 +148,11 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 3.5.0-rc1
- 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
Loading

0 comments on commit 4ab1774

Please sign in to comment.