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

pull/45937/head
Jordan Borean 6 years ago committed by GitHub
parent a41c0405a7
commit fd4b282f6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -700,7 +700,8 @@ namespace Ansible.Basic
// initially parse the params and check for unsupported ones and set internal vars
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["msg"] = String.Format("remote module ({0}) does not support check mode", ModuleName);

@ -1352,6 +1352,28 @@ test_no_log - Invoked with:
$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" = {
$spec = @{
options = @{

Loading…
Cancel
Save