azure windows: changed pagefile to dynamically get the path (#35376)

pull/35383/head
Jordan Borean 7 years ago committed by Matt Clay
parent b1d14d5b06
commit ea7d29e262

@ -77,17 +77,34 @@
- cmdout is skipped - cmdout is skipped
- cmdout.msg is search('exists') - cmdout.msg is search('exists')
- name: get path of pagefile
win_shell: |
$pagefile = $null
$cs = Get-CimInstance -ClassName Win32_ComputerSystem
if ($cs.AutomaticManagedPagefile) {
$pagefile = "$($env:SystemRoot.Substring(0, 1)):\pagefile.sys"
} else {
$pf = Get-CimInstance -ClassName Win32_PageFileSetting
if ($pf -ne $null) {
$pagefile = $pf[0].Name
}
}
$pagefile
register: pagefile_path
- name: test creates with hidden system file, should skip - name: test creates with hidden system file, should skip
win_command: echo no win_command: echo no
args: args:
creates: C:\pagefile.sys creates: '{{pagefile_path.stdout_lines[0]}}'
register: cmdout register: cmdout
when: pagefile_path.stdout_lines|count != 0
- name: validate result - name: validate result
assert: assert:
that: that:
- cmdout is skipped - cmdout is skipped
- cmdout.msg is search('exists') - cmdout.msg is search('exists')
when: pagefile_path.stdout_lines|count != 0
- name: ensure testfile is still present - name: ensure testfile is still present
win_stat: win_stat:

@ -17,10 +17,33 @@ Function Assert-Equals($actual, $expected) {
} }
} }
Function Get-PagefilePath() {
$pagefile = $null
$cs = Get-CimInstance -ClassName Win32_ComputerSystem
if ($cs.AutomaticManagedPagefile) {
$pagefile = "$($env:SystemRoot.Substring(0, 1)):\pagefile.sys"
} else {
$pf = Get-CimInstance -ClassName Win32_PageFileSetting
if ($null -ne $pf) {
$pagefile = $pf[0].Name
}
}
return $pagefile
}
$pagefile = Get-PagefilePath
if ($pagefile) {
# Test-AnsiblePath Hidden system file # Test-AnsiblePath Hidden system file
$actual = Test-AnsiblePath -Path C:\pagefile.sys $actual = Test-AnsiblePath -Path $pagefile
Assert-Equals -actual $actual -expected $true Assert-Equals -actual $actual -expected $true
# Get-AnsibleItem file
$actual = Get-AnsibleItem -Path $pagefile
Assert-Equals -actual $actual.FullName -expected $pagefile
Assert-Equals -actual $actual.Attributes.HasFlag([System.IO.FileAttributes]::Directory) -expected $false
Assert-Equals -actual $actual.Exists -expected $true
}
# Test-AnsiblePath File that doesn't exist # Test-AnsiblePath File that doesn't exist
$actual = Test-AnsiblePath -Path C:\fakefile $actual = Test-AnsiblePath -Path C:\fakefile
Assert-Equals -actual $actual -expected $false Assert-Equals -actual $actual -expected $false
@ -46,13 +69,6 @@ Assert-Equals -actual $failed -expected $true
$actual = Get-AnsibleItem -Path C:\fakefile -ErrorAction SilentlyContinue $actual = Get-AnsibleItem -Path C:\fakefile -ErrorAction SilentlyContinue
Assert-Equals -actual $actual -expected $null Assert-Equals -actual $actual -expected $null
# Get-AnsibleItem file
$actual = Get-AnsibleItem -Path C:\pagefile.sys
Assert-Equals -actual $actual.FullName -expected C:\pagefile.sys
Assert-Equals -actual $actual.Attributes.HasFlag([System.IO.FileAttributes]::Directory) -expected $false
Assert-Equals -actual $actual.Exists -expected $true
# Get-AnsibleItem directory # Get-AnsibleItem directory
$actual = Get-AnsibleItem -Path C:\Windows $actual = Get-AnsibleItem -Path C:\Windows
Assert-Equals -actual $actual.FullName -expected C:\Windows Assert-Equals -actual $actual.FullName -expected C:\Windows

@ -105,17 +105,34 @@
- shellout is skipped - shellout is skipped
- shellout.msg is search('exists') - shellout.msg is search('exists')
- name: get path of pagefile
win_shell: |
$pagefile = $null
$cs = Get-CimInstance -ClassName Win32_ComputerSystem
if ($cs.AutomaticManagedPagefile) {
$pagefile = "$($env:SystemRoot.Substring(0, 1)):\pagefile.sys"
} else {
$pf = Get-CimInstance -ClassName Win32_PageFileSetting
if ($pf -ne $null) {
$pagefile = $pf[0].Name
}
}
$pagefile
register: pagefile_path
- name: test creates with hidden system file, should skip - name: test creates with hidden system file, should skip
win_shell: echo test win_shell: echo test
args: args:
creates: C:\pagefile.sys creates: '{{pagefile_path.stdout_lines[0]}}'
register: shellout register: shellout
when: pagefile_path.stdout_lines|count != 0
- name: validate result - name: validate result
assert: assert:
that: that:
- shellout is skipped - shellout is skipped
- shellout.msg is search('exists') - shellout.msg is search('exists')
when: pagefile_path.stdout_lines|count != 0
- name: ensure testfile is still present - name: ensure testfile is still present
win_stat: win_stat:

@ -465,17 +465,34 @@
failed_when: "win_stat_no_args.msg != 'Get-AnsibleParam: Missing required argument: path'" failed_when: "win_stat_no_args.msg != 'Get-AnsibleParam: Missing required argument: path'"
# https://github.com/ansible/ansible/issues/30258 # https://github.com/ansible/ansible/issues/30258
- name: get path of pagefile
win_shell: |
$pagefile = $null
$cs = Get-CimInstance -ClassName Win32_ComputerSystem
if ($cs.AutomaticManagedPagefile) {
$pagefile = "$($env:SystemRoot.Substring(0, 1)):\pagefile.sys"
} else {
$pf = Get-CimInstance -ClassName Win32_PageFileSetting
if ($pf -ne $null) {
$pagefile = $pf[0].Name
}
}
$pagefile
register: pagefile_path
- name: get stat of pagefile - name: get stat of pagefile
win_stat: win_stat:
path: C:\pagefile.sys path: '{{pagefile_path.stdout_lines[0]}}'
get_md5: no get_md5: no
get_checksum: no get_checksum: no
register: pagefile_stat register: pagefile_stat
when: pagefile_path.stdout_lines|count != 0
- name: assert get stat of pagefile - name: assert get stat of pagefile
assert: assert:
that: that:
- pagefile_stat.stat.exists == True - pagefile_stat.stat.exists == True
when: pagefile_path.stdout_lines|count != 0
# Tests with normal user # Tests with normal user
- set_fact: - set_fact:

Loading…
Cancel
Save