diff options
author | Jordan Borean <jborean93@gmail.com> | 2017-10-17 22:30:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-17 22:30:33 +0200 |
commit | 743ff4897aadc9ae3695b5393badcf7e581d5fea (patch) | |
tree | 12a9f9e969b86c406b58670ef96ef67ffbfa716b /test/integration | |
parent | Improve python 2/3 ABC fallback for pylint. (#31848) (diff) | |
download | ansible-743ff4897aadc9ae3695b5393badcf7e581d5fea.tar.xz ansible-743ff4897aadc9ae3695b5393badcf7e581d5fea.zip |
win_regedit: added function to load a dat file for editing (#31289)
* win_regedit: added function to load a dat file for editing
* try to make the tests more resiliant
* more stability changes
Diffstat (limited to 'test/integration')
4 files changed, 277 insertions, 15 deletions
diff --git a/test/integration/targets/win_regedit/defaults/main.yml b/test/integration/targets/win_regedit/defaults/main.yml index 87aa3e597c..cb3b84b0a1 100644 --- a/test/integration/targets/win_regedit/defaults/main.yml +++ b/test/integration/targets/win_regedit/defaults/main.yml @@ -1,2 +1,3 @@ test_win_regedit_local_key: HKLM:\Software\Cow Corp test_win_regedit_classes_key: HKCR:\.test-ansible +test_win_regedit_hive_key: HKLM:\ANSIBLE\NewKey diff --git a/test/integration/targets/win_regedit/tasks/cleanup.yml b/test/integration/targets/win_regedit/tasks/cleanup.yml new file mode 100644 index 0000000000..f10452506e --- /dev/null +++ b/test/integration/targets/win_regedit/tasks/cleanup.yml @@ -0,0 +1,18 @@ +--- +- name: load HKLM:\ANSIBLE with test hive + win_command: reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat + failed_when: false + +- name: make sure testing keys are removed before test + win_regedit: + path: '{{item}}' + delete_key: yes + state: absent + with_items: + - '{{test_win_regedit_local_key}}' + - '{{test_win_regedit_classes_key}}' + - '{{test_win_regedit_hive_key}}' + +- name: ensure HKLM:\ANSIBLE is unloaded + win_command: reg.exe unload HKLM\ANSIBLE + failed_when: false diff --git a/test/integration/targets/win_regedit/tasks/main.yml b/test/integration/targets/win_regedit/tasks/main.yml index e8468a096e..86ca1cbd60 100644 --- a/test/integration/targets/win_regedit/tasks/main.yml +++ b/test/integration/targets/win_regedit/tasks/main.yml @@ -1,12 +1,6 @@ --- -- name: make sure testing keys are removed before test - win_regedit: - path: '{{item}}' - delete_key: yes - state: absent - with_items: - - '{{test_win_regedit_local_key}}' - - '{{test_win_regedit_classes_key}}' +- name: make sure we start on a blank state + include_tasks: cleanup.yml - block: - name: run tests for each property type @@ -81,10 +75,4 @@ always: - name: make sure testing keys are removed after test - win_regedit: - path: '{{item}}' - delete_key: yes - state: absent - with_items: - - '{{test_win_regedit_local_key}}' - - '{{test_win_regedit_classes_key}}' + include_tasks: cleanup.yml diff --git a/test/integration/targets/win_regedit/tasks/tests.yml b/test/integration/targets/win_regedit/tasks/tests.yml index 1e39de566f..9144d491b5 100644 --- a/test/integration/targets/win_regedit/tasks/tests.yml +++ b/test/integration/targets/win_regedit/tasks/tests.yml @@ -458,3 +458,258 @@ assert: that: - not create_prop_with_json_again|changed + +- name: create new key in loaded hive (check mode) + win_regedit: + path: '{{test_win_regedit_hive_key}}' + state: present + hive: C:\Users\Default\NTUSER.dat + register: new_key_in_hive_check + check_mode: yes + +- name: get result of create new key in loaded hive (check mode) + win_shell: | + ®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null + Test-Path -Path HKLM:\ANSIBLE\NewKey + exit 0 + register: new_key_in_hive_result_check + +- win_command: reg.exe unload HKLM\ANSIBLE + +- name: assert result of create new key in loaded hive (check mode) + assert: + that: + - new_key_in_hive_check|changed + - new_key_in_hive_result_check.stdout == "False\r\n" + +- name: create new key in loaded hive + win_regedit: + path: '{{test_win_regedit_hive_key}}' + state: present + hive: C:\Users\Default\NTUSER.dat + register: new_key_in_hive + +- name: get result of create new key in loaded hive + win_shell: | + ®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null + Test-Path -Path HKLM:\ANSIBLE\NewKey + exit 0 + register: new_key_in_hive_result + +- win_command: reg.exe unload HKLM\ANSIBLE + +- name: assert result of create new key in loaded hive + assert: + that: + - new_key_in_hive|changed + - new_key_in_hive_result.stdout == "True\r\n" + +- name: create new key in loaded hive (idempotent) + win_regedit: + path: '{{test_win_regedit_hive_key}}' + state: present + hive: C:\Users\Default\NTUSER.dat + register: new_key_in_hive_again + +- name: assert result of create new key in loaded hive (idempotent) + assert: + that: + - not new_key_in_hive_again|changed + +- name: set hive key property (check mode) + win_regedit: + path: '{{test_win_regedit_hive_key}}' + name: TestProp + data: string + type: string + state: present + hive: C:\Users\Default\NTUSER.dat + register: new_prop_in_hive_check + check_mode: yes + +- name: get result of set hive key property (check mode) + win_shell: | + ®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null + $prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue + if ($prop) { + $prop.TestProp + } + exit 0 + register: new_prop_in_hive_result_check + +- win_command: reg.exe unload HKLM\ANSIBLE + +- name: assert result of set hive key property (check mode) + assert: + that: + - new_prop_in_hive_check|changed + - new_prop_in_hive_result_check.stdout == "" + +- name: set hive key property + win_regedit: + path: '{{test_win_regedit_hive_key}}' + name: TestProp + data: string + type: string + state: present + hive: C:\Users\Default\NTUSER.dat + register: new_prop_in_hive + +- name: get result of set hive key property + win_shell: | + ®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null + $prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue + if ($prop) { + $prop.TestProp + } + exit 0 + register: new_prop_in_hive_result + +- win_command: reg.exe unload HKLM\ANSIBLE + +- name: assert result of set hive key property + assert: + that: + - new_prop_in_hive|changed + - new_prop_in_hive_result.stdout == "string\r\n" + +- name: set hive key property (idempotent) + win_regedit: + path: '{{test_win_regedit_hive_key}}' + name: TestProp + data: string + type: string + state: present + hive: C:\Users\Default\NTUSER.dat + register: new_prop_in_hive_again + +- name: assert result of set hive key property (idempotent) + assert: + that: + - not new_prop_in_hive_again|changed + +- name: remove hive key property (check mode) + win_regedit: + path: '{{test_win_regedit_hive_key}}' + name: TestProp + state: absent + hive: C:\Users\Default\NTUSER.dat + register: remove_prop_in_hive_check + check_mode: yes + +- name: get result of remove hive key property (check mode) + win_shell: | + ®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null + $prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue + if ($prop) { + $prop.TestProp + } + exit 0 + register: remove_prop_in_hive_result_check + +- win_command: reg.exe unload HKLM\ANSIBLE + +- name: assert result of remove hive key property (check mode) + assert: + that: + - remove_prop_in_hive_check|changed + - remove_prop_in_hive_result_check.stdout == "string\r\n" + +- name: remove hive key property + win_regedit: + path: '{{test_win_regedit_hive_key}}' + name: TestProp + state: absent + hive: C:\Users\Default\NTUSER.dat + register: remove_prop_in_hive + +- name: get result of remove hive key property + win_shell: | + ®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null + $prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue + if ($prop) { + $prop.TestProp + } + exit 0 + register: remove_prop_in_hive_result + +- win_command: reg.exe unload HKLM\ANSIBLE + +- name: assert result of remove hive key property + assert: + that: + - remove_prop_in_hive|changed + - remove_prop_in_hive_result.stdout == "" + +- name: remove hive key property (idempotent) + win_regedit: + path: '{{test_win_regedit_hive_key}}' + name: TestProp + state: absent + hive: C:\Users\Default\NTUSER.dat + register: remove_prop_in_hive_again + +- name: assert result of set hive key property (idempotent) + assert: + that: + - not remove_prop_in_hive_again|changed + +- name: remove key in loaded hive (check mode) + win_regedit: + path: '{{test_win_regedit_hive_key}}' + state: absent + delete_yes: yes + hive: C:\Users\Default\NTUSER.dat + register: remove_key_in_hive_check + check_mode: yes + +- name: get result of remove key in loaded hive (check mode) + win_shell: | + ®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null + Test-Path -Path HKLM:\ANSIBLE\NewKey + exit 0 + register: remove_key_in_hive_result_check + +- win_command: reg.exe unload HKLM\ANSIBLE + +- name: assert result of removekey in loaded hive (check mode) + assert: + that: + - remove_key_in_hive_check|changed + - remove_key_in_hive_result_check.stdout == "True\r\n" + +- name: remove key in loaded hive + win_regedit: + path: '{{test_win_regedit_hive_key}}' + state: absent + delete_yes: yes + hive: C:\Users\Default\NTUSER.dat + register: remove_key_in_hive + +- name: get result of remove key in loaded hive + win_shell: | + ®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null + Test-Path -Path HKLM:\ANSIBLE\NewKey + exit 0 + register: remove_key_in_hive_result + +- win_command: reg.exe unload HKLM\ANSIBLE + +- name: assert result of remove key in loaded hive + assert: + that: + - remove_key_in_hive|changed + - remove_key_in_hive_result.stdout == "False\r\n" + +- name: remove key in loaded hive (idempotent) + win_regedit: + path: '{{test_win_regedit_hive_key}}' + state: absent + delete_yes: yes + hive: C:\Users\Default\NTUSER.dat + register: remove_key_in_hive_again + +- name: assert result of remove key in loaded hive (idempotent) + assert: + that: + - not remove_key_in_hive_again|changed |