mirror of https://github.com/ansible/ansible.git
win_dotnet_ngen: fix after broken in 2.4 (#31076)
* win_dotnet_ngen: fix after broken in 2.4
* added description to return values
(cherry picked from commit 12a4dca447
)
pull/31222/head
parent
2513078f39
commit
737a0d6015
@ -1,71 +1,62 @@
|
|||||||
#!powershell
|
#!powershell
|
||||||
# This file is part of Ansible
|
# This file is part of Ansible
|
||||||
#
|
|
||||||
# Copyright 2015, Peter Mounce <public@neverrunwithscissors.com>
|
# Copyright 2015, Peter Mounce <public@neverrunwithscissors.com>
|
||||||
#
|
# Copyright (c) 2017 Ansible Project
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
#Requires -Module Ansible.ModuleUtils.Legacy.psm1
|
||||||
|
#Requires -Module Ansible.ModuleUtils.CommandUtil.psm1
|
||||||
|
|
||||||
# WANT_JSON
|
$ErrorActionPreference = 'Stop'
|
||||||
# POWERSHELL_COMMON
|
|
||||||
|
|
||||||
$params = Parse-Args $args;
|
$params = Parse-Args $args -supports_check_mode $true
|
||||||
|
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
|
||||||
|
|
||||||
$result = @{
|
$result = @{
|
||||||
changed = $false
|
changed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
function Invoke-NGen
|
Function Invoke-Ngen($architecture="") {
|
||||||
{
|
$cmd = "$($env:windir)\Microsoft.NET\Framework$($architecture)\v4.0.30319\ngen.exe"
|
||||||
[CmdletBinding()]
|
|
||||||
|
|
||||||
param
|
|
||||||
(
|
|
||||||
[Parameter(Mandatory=$false, Position=0)] [string] $arity = ""
|
|
||||||
)
|
|
||||||
|
|
||||||
if ($arity -eq $null)
|
if (Test-Path -Path $cmd) {
|
||||||
{
|
$arguments = "update /force"
|
||||||
$arity = ""
|
if ($check_mode) {
|
||||||
|
$ngen_result = @{
|
||||||
|
rc = 0
|
||||||
|
stdout = "check mode output for $cmd $arguments"
|
||||||
}
|
}
|
||||||
$cmd = "$($env:windir)\microsoft.net\framework$($arity)\v4.0.30319\ngen.exe"
|
} else {
|
||||||
if (test-path $cmd)
|
try {
|
||||||
{
|
$ngen_result = Run-Command -command "$cmd $arguments"
|
||||||
$update = Invoke-Expression "$cmd update /force";
|
} catch {
|
||||||
$(result.dotnet_ngen$($arity)_update_exit_code) = $lastexitcode
|
Fail-Json -obj $result -message "failed to execute '$cmd $arguments': $($_.Exception.Message)"
|
||||||
$(result.dotnet_ngen$($arity)_update_output) = $update
|
}
|
||||||
$eqi = Invoke-Expression "$cmd executequeueditems";
|
}
|
||||||
$(result.dotnet_ngen$($arity)_eqi_exit_code) = $lastexitcode
|
$result."dotnet_ngen$($architecture)_update_exit_code" = $ngen_result.rc
|
||||||
$(result.dotnet_ngen$($arity)_eqi_output) = $eqi
|
$result."dotnet_ngen$($architecture)_update_output" = $ngen_result.stdout
|
||||||
|
|
||||||
$result.changed = $true
|
$arguments = "executeQueuedItems"
|
||||||
|
if ($check_mode) {
|
||||||
|
$executed_queued_items = @{
|
||||||
|
rc = 0
|
||||||
|
stdout = "check mode output for $cmd $arguments"
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
try {
|
||||||
Write-Host "Not found: $cmd"
|
$executed_queued_items = Run-Command -command "$cmd $arguments"
|
||||||
|
} catch {
|
||||||
|
Fail-Json -obj $result -message "failed to execute '$cmd $arguments': $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result."dotnet_ngen$($architecture)_eqi_exit_code" = $executed_queued_items.rc
|
||||||
|
$result."dotnet_ngen$($architecture)_eqi_output" = $executed_queued_items.stdout
|
||||||
|
$result.changed = $true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Try
|
Invoke-Ngen
|
||||||
{
|
Invoke-Ngen -architecture "64"
|
||||||
Invoke-NGen
|
|
||||||
Invoke-NGen -arity "64"
|
|
||||||
|
|
||||||
Exit-Json $result;
|
Exit-Json -obj $result
|
||||||
}
|
|
||||||
Catch
|
|
||||||
{
|
|
||||||
Fail-Json $result $_.Exception.Message
|
|
||||||
}
|
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
windows/ci/group1
|
@ -0,0 +1,20 @@
|
|||||||
|
# this only tests check mode as the full run can take several minutes to
|
||||||
|
# complete, this way we at least verify the script is parsable
|
||||||
|
---
|
||||||
|
- name: run in check mode
|
||||||
|
win_dotnet_ngen:
|
||||||
|
register: result_check
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: assert run in check mode
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result_check|changed
|
||||||
|
- result_check.dotnet_ngen_update_exit_code == 0
|
||||||
|
- result_check.dotnet_ngen_update_output == "check mode output for C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\ngen.exe update /force"
|
||||||
|
- result_check.dotnet_ngen_eqi_exit_code == 0
|
||||||
|
- result_check.dotnet_ngen_eqi_output == "check mode output for C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\ngen.exe executeQueuedItems"
|
||||||
|
- result_check.dotnet_ngen64_update_exit_code == 0
|
||||||
|
- result_check.dotnet_ngen64_update_output == "check mode output for C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\ngen.exe update /force"
|
||||||
|
- result_check.dotnet_ngen64_eqi_exit_code == 0
|
||||||
|
- result_check.dotnet_ngen64_eqi_output == "check mode output for C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\ngen.exe executeQueuedItems"
|
Loading…
Reference in New Issue