From 865b457a6e7c5d14ceda53b7248603d3d44c7c4f Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Wed, 11 Jan 2023 08:05:50 +1000 Subject: [PATCH] ansible-test - fix ps argspec check inside cmdlet (#79699) * ansible-test - fix ps argspec check inside cmdlet * Added error condition test * Fix sanity problem (cherry picked from commit ee33be9484b2240aa7b6b3bfdb30b452b6048e85) --- changelogs/fragments/validate-module-ps-cmdlet.yml | 2 ++ .../validate_modules/ps_argspec.ps1 | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/validate-module-ps-cmdlet.yml diff --git a/changelogs/fragments/validate-module-ps-cmdlet.yml b/changelogs/fragments/validate-module-ps-cmdlet.yml new file mode 100644 index 00000000000..5ae24bc5699 --- /dev/null +++ b/changelogs/fragments/validate-module-ps-cmdlet.yml @@ -0,0 +1,2 @@ +bugfixes: +- ansible-test - Fix validate-modules error when retrieving PowerShell argspec when retrieved inside a Cmdlet diff --git a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/ps_argspec.ps1 b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/ps_argspec.ps1 index fb4a61740a6..adad692a7de 100644 --- a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/ps_argspec.ps1 +++ b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/ps_argspec.ps1 @@ -97,13 +97,21 @@ Add-CSharpType -References @(Get-Content -LiteralPath $manifest.ansible_basic -R $powershell.AddScript($module_code) > $null $powershell.Invoke() > $null +$arg_spec = $powershell.Runspace.SessionStateProxy.GetVariable('ansibleTestArgSpec') + +if (-not $arg_spec) { + $err = $powershell.Streams.Error + if ($err) { + $err + } + else { + "Unknown error trying to get PowerShell arg spec" + } -if ($powershell.HadErrors) { - $powershell.Streams.Error exit 1 } -$arg_spec = $powershell.Runspace.SessionStateProxy.GetVariable('ansibleTestArgSpec') + Resolve-CircularReference -Hash $arg_spec ConvertTo-Json -InputObject $arg_spec -Compress -Depth 99