1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Ansible.Basic.cs - fix check mode run with nested spec (#48838)

This commit is contained in:
Jordan Borean 2018-11-17 18:15:36 +10:00 committed by GitHub
parent a41c0405a7
commit fd4b282f6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View file

@ -700,7 +700,8 @@ namespace Ansible.Basic
// initially parse the params and check for unsupported ones and set internal vars // initially parse the params and check for unsupported ones and set internal vars
CheckUnsupportedArguments(param, legalInputs); CheckUnsupportedArguments(param, legalInputs);
if (CheckMode && !(bool)spec["supports_check_mode"]) // Only run this check if we are at the root argument (optionsContext.Count == 0)
if (CheckMode && !(bool)spec["supports_check_mode"] && optionsContext.Count == 0)
{ {
Result["skipped"] = true; Result["skipped"] = true;
Result["msg"] = String.Format("remote module ({0}) does not support check mode", ModuleName); Result["msg"] = String.Format("remote module ({0}) does not support check mode", ModuleName);

View file

@ -1352,6 +1352,28 @@ test_no_log - Invoked with:
$actual.invocation | Assert-DictionaryEquals -Expected @{module_args = @{option_key = "abc"}} $actual.invocation | Assert-DictionaryEquals -Expected @{module_args = @{option_key = "abc"}}
} }
"Check mode with suboption without supports_check_mode" = {
$spec = @{
options = @{
sub_options = @{
# This tests the situation where a sub key doesn't set supports_check_mode, the logic in
# Ansible.Basic automatically sets that to $false and we want it to ignore it for a nested check
type = "dict"
options = @{
sub_option = @{ type = "str"; default = "value" }
}
}
}
supports_check_mode = $true
}
$complex_args = @{
_ansible_check_mode = $true
}
$m = [Ansible.Basic.AnsibleModule]::Create(@(), $spec)
$m.CheckMode | Assert-Equals -Expected $true
}
"Type conversion error" = { "Type conversion error" = {
$spec = @{ $spec = @{
options = @{ options = @{