summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Borean <jborean93@gmail.com>2020-03-21 13:24:11 +1000
committerMatt Clay <matt@mystile.com>2020-03-20 21:04:36 -0700
commitc6d7baeec5bca7f02fc4ddbb7052f8de081f9cdf (patch)
treef4d2313d9b0cfcb446dc1048783867d5b75ba56e
parent77732ed50db3b8e27d463663f347088334094bed (diff)
downloadansible-temp-2.10-devel.tar.gz
validate-modules - fix ps module delegate type inspectiontemp-2.10-devel
-rw-r--r--changelogs/fragments/ps-argspec-type.yaml2
-rwxr-xr-xtest/lib/ansible_test/_data/sanity/validate-modules/validate_modules/ps_argspec.ps149
2 files changed, 48 insertions, 3 deletions
diff --git a/changelogs/fragments/ps-argspec-type.yaml b/changelogs/fragments/ps-argspec-type.yaml
new file mode 100644
index 0000000000..71c72b7539
--- /dev/null
+++ b/changelogs/fragments/ps-argspec-type.yaml
@@ -0,0 +1,2 @@
+bugfixes:
+- validate-modules - Fix hang when inspecting module with a delegate args spec type
diff --git a/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/ps_argspec.ps1 b/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/ps_argspec.ps1
index 4293d2d854..49491634a3 100755
--- a/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/ps_argspec.ps1
+++ b/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/ps_argspec.ps1
@@ -5,6 +5,45 @@ Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
$WarningPreference = "Stop"
+Function Resolve-CircularReference {
+ <#
+ .SYNOPSIS
+ Removes known types that cause a circular reference in their json serialization.
+
+ .PARAMETER Hash
+ The hash to scan for circular references
+ #>
+ [CmdletBinding()]
+ param (
+ [Parameter(Mandatory=$true)]
+ [System.Collections.IDictionary]
+ $Hash
+ )
+
+ foreach ($key in [String[]]$Hash.Keys) {
+ $value = $Hash[$key]
+ if ($value -is [System.Collections.IDictionary]) {
+ Resolve-CircularReference -Hash $value
+ } elseif ($value -is [Array] -or $value -is [System.Collections.IList]) {
+ $values = @(foreach ($v in $value) {
+ if ($v -is [System.Collections.IDictionary]) {
+ Resolve-CircularReference -Hash $v
+ }
+ ,$v
+ })
+ $Hash[$key] = $values
+ } elseif ($value -is [delegate]) {
+ # Type can be set to a delegate function which defines it's own type. For the documentation we just
+ # reflection that as raw
+ if ($key -eq 'type') {
+ $Hash[$key] = 'raw'
+ } else {
+ $Hash[$key] = $value.ToString() # Shouldn't ever happen but just in case.
+ }
+ }
+ }
+}
+
$manifest = ConvertFrom-Json -InputObject $args[0] -AsHashtable
if (-not $manifest.Contains('module_path') -or -not $manifest.module_path) {
Write-Error -Message "No module specified."
@@ -33,9 +72,8 @@ namespace Ansible.Basic
{
public AnsibleModule(string[] args, IDictionary argumentSpec)
{
- PSObject rawOut = ScriptBlock.Create("ConvertTo-Json -InputObject $args[0] -Depth 99 -Compress").Invoke(argumentSpec)[0];
- Console.WriteLine(rawOut.BaseObject.ToString());
- ScriptBlock.Create("Set-Variable -Name LASTEXITCODE -Value 0 -Scope Global; exit 0").Invoke();
+ ScriptBlock.Create("Set-Variable -Name arg_spec -Value $args[0] -Scope Global; exit 0"
+ ).Invoke(new Object[] { argumentSpec });
}
public static AnsibleModule Create(string[] args, IDictionary argumentSpec)
@@ -81,3 +119,8 @@ if ($powershell.HadErrors) {
$powershell.Streams.Error
exit 1
}
+
+$arg_spec = $powershell.Runspace.SessionStateProxy.GetVariable('arg_spec')
+Resolve-CircularReference -Hash $arg_spec
+
+ConvertTo-Json -InputObject $arg_spec -Compress -Depth 99 \ No newline at end of file