diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/integration/targets/win_power_plan/tasks/main.yml | 48 | ||||
-rw-r--r-- | test/sanity/pslint/ignore.txt | 1 |
2 files changed, 17 insertions, 32 deletions
diff --git a/test/integration/targets/win_power_plan/tasks/main.yml b/test/integration/targets/win_power_plan/tasks/main.yml index 0b6f0c315e..000d8b1a66 100644 --- a/test/integration/targets/win_power_plan/tasks/main.yml +++ b/test/integration/targets/win_power_plan/tasks/main.yml @@ -1,26 +1,16 @@ -- name: register os version (seems integration tests don't gather this fact) - raw: powershell.exe "gwmi Win32_OperatingSystem | select -expand version" - register: os_version - changed_when: False -# ^^ seems "raw" is the only module that works on 2008 non-r2. win_command and win_shell both failed +# I dislike this but 2008 doesn't support the Win32_PowerPlan WMI provider +- name: get current plan details + win_shell: | + $plan_info = powercfg.exe /list + ($plan_info | Select-String -Pattern '\(([\w\s]*)\) \*$').Matches.Groups[1].Value + ($plan_info | Select-String -Pattern '\(([\w\s]*)\)$').Matches.Groups[1].Value + register: plan_info -- name: check if module fails gracefully when older than 2008r2 - win_power_plan: - name: "high performance" - when: os_version.stdout_lines[0] is version('6.1','lt') - check_mode: yes - register: old_os_check - failed_when: old_os_check.msg != 'The win_power_plan Ansible module is only available on Server 2008r2 (6.1) and newer' +- set_fact: + original_plan: '{{ plan_info.stdout_lines[0] }}' + name: '{{ plan_info.stdout_lines[1] }}' - block: - - name: register inactive power plan to test with - win_shell: (Get-CimInstance -Name root\cimv2\power -Class win32_PowerPlan | ? {! $_.IsActive}).ElementName[0] - register: disabled_power_plan - changed_when: False - - - set_fact: - name: "{{ disabled_power_plan.stdout_lines[0] }}" - #Test that plan detects change is needed, but doesn't actually apply change - name: set power plan (check mode) win_power_plan: @@ -28,20 +18,17 @@ register: set_plan_check check_mode: yes -# - debug: -# var: set_plan_check - - name: get result of set power plan (check mode) - win_shell: (Get-CimInstance -Name root\cimv2\power -Class win32_PowerPlan -Filter "ElementName = '{{ name }}'").IsActive + win_shell: (powercfg.exe /list | Select-String -Pattern '\({{ name }}\)').Line register: set_plan_check_result changed_when: False - + # verify that the powershell check is showing the plan as still inactive on the system - name: assert setting plan (check mode) assert: that: - set_plan_check is changed - - set_plan_check_result.stdout == 'False\r\n' + - not set_plan_check_result.stdout_lines[0].endswith('*') #Test that setting plan and that change is applied - name: set power plan @@ -50,7 +37,7 @@ register: set_plan - name: get result of set power plan - win_shell: (Get-CimInstance -Name root\cimv2\power -Class win32_PowerPlan -Filter "ElementName = '{{ name }}'").IsActive + win_shell: (powercfg.exe /list | Select-String -Pattern '\({{ name }}\)').Line register: set_plan_result changed_when: False @@ -58,7 +45,7 @@ assert: that: - set_plan is changed - - set_plan_result.stdout == 'True\r\n' + - set_plan_result.stdout_lines[0].endswith('*') #Test that plan doesn't apply change if it is already set - name: set power plan (idempotent) @@ -71,8 +58,7 @@ that: - set_plan_idempotent is not changed - when: os_version.stdout_lines[0] is version('6.1','ge') always: - - name: always change back plan to high performance when done testing + - name: always change back plan to the original when done testing win_power_plan: - name: high performance + name: '{{ original_plan }}' diff --git a/test/sanity/pslint/ignore.txt b/test/sanity/pslint/ignore.txt index e123acfcb1..2f9327bcb0 100644 --- a/test/sanity/pslint/ignore.txt +++ b/test/sanity/pslint/ignore.txt @@ -54,7 +54,6 @@ lib/ansible/modules/windows/win_pagefile.ps1 PSAvoidUsingPositionalParameters lib/ansible/modules/windows/win_pagefile.ps1 PSAvoidUsingWMICmdlet lib/ansible/modules/windows/win_pagefile.ps1 PSUseDeclaredVarsMoreThanAssignments lib/ansible/modules/windows/win_pagefile.ps1 PSUseSupportsShouldProcess -lib/ansible/modules/windows/win_power_plan.ps1 PSUseDeclaredVarsMoreThanAssignments lib/ansible/modules/windows/win_psmodule.ps1 PSAvoidUsingCmdletAliases lib/ansible/modules/windows/win_rabbitmq_plugin.ps1 PSAvoidUsingCmdletAliases lib/ansible/modules/windows/win_rabbitmq_plugin.ps1 PSAvoidUsingInvokeExpression |