summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/incidental_win_reboot
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:03:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:03:01 +0000
commita453ac31f3428614cceb99027f8efbdb9258a40b (patch)
treef61f87408f32a8511cbd91799f9cececb53e0374 /test/integration/targets/incidental_win_reboot
parentInitial commit. (diff)
downloadansible-upstream.tar.xz
ansible-upstream.zip
Adding upstream version 2.10.7+merged+base+2.10.8+dfsg.upstream/2.10.7+merged+base+2.10.8+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/incidental_win_reboot')
-rw-r--r--test/integration/targets/incidental_win_reboot/aliases2
-rw-r--r--test/integration/targets/incidental_win_reboot/tasks/main.yml70
-rw-r--r--test/integration/targets/incidental_win_reboot/templates/post_reboot.ps18
3 files changed, 80 insertions, 0 deletions
diff --git a/test/integration/targets/incidental_win_reboot/aliases b/test/integration/targets/incidental_win_reboot/aliases
new file mode 100644
index 00000000..a5fc90dc
--- /dev/null
+++ b/test/integration/targets/incidental_win_reboot/aliases
@@ -0,0 +1,2 @@
+shippable/windows/incidental
+windows
diff --git a/test/integration/targets/incidental_win_reboot/tasks/main.yml b/test/integration/targets/incidental_win_reboot/tasks/main.yml
new file mode 100644
index 00000000..7757e08f
--- /dev/null
+++ b/test/integration/targets/incidental_win_reboot/tasks/main.yml
@@ -0,0 +1,70 @@
+---
+- name: make sure win output dir exists
+ win_file:
+ path: "{{win_output_dir}}"
+ state: directory
+
+- name: reboot with defaults
+ win_reboot:
+
+- name: test with negative values for delays
+ win_reboot:
+ post_reboot_delay: -0.5
+ pre_reboot_delay: -61
+
+- name: schedule a reboot for sometime in the future
+ win_command: shutdown.exe /r /t 599
+
+- name: reboot with a shutdown already scheduled
+ win_reboot:
+
+# test a reboot that reboots again during the test_command phase
+- name: create test file
+ win_file:
+ path: '{{win_output_dir}}\win_reboot_test'
+ state: touch
+
+- name: reboot with secondary reboot stage
+ win_reboot:
+ test_command: '{{ lookup("template", "post_reboot.ps1") }}'
+
+- name: reboot with test command that fails
+ win_reboot:
+ test_command: 'FAIL'
+ reboot_timeout: 120
+ register: reboot_fail_test
+ failed_when: "reboot_fail_test.msg != 'Timed out waiting for post-reboot test command (timeout=120)'"
+
+- name: remove SeRemoteShutdownPrivilege
+ win_user_right:
+ name: SeRemoteShutdownPrivilege
+ users: []
+ action: set
+ register: removed_shutdown_privilege
+
+- block:
+ - name: try and reboot without required privilege
+ win_reboot:
+ register: fail_privilege
+ failed_when:
+ - "'Reboot command failed, error was:' not in fail_privilege.msg"
+ - "'Access is denied.(5)' not in fail_privilege.msg"
+
+ always:
+ - name: reset the SeRemoteShutdownPrivilege
+ win_user_right:
+ name: SeRemoteShutdownPrivilege
+ users: '{{ removed_shutdown_privilege.removed }}'
+ action: add
+
+- name: Use invalid parameter
+ reboot:
+ foo: bar
+ ignore_errors: true
+ register: invalid_parameter
+
+- name: Ensure task fails with error
+ assert:
+ that:
+ - invalid_parameter is failed
+ - "invalid_parameter.msg == 'Invalid options for reboot: foo'"
diff --git a/test/integration/targets/incidental_win_reboot/templates/post_reboot.ps1 b/test/integration/targets/incidental_win_reboot/templates/post_reboot.ps1
new file mode 100644
index 00000000..e4a99a72
--- /dev/null
+++ b/test/integration/targets/incidental_win_reboot/templates/post_reboot.ps1
@@ -0,0 +1,8 @@
+if (Test-Path -Path '{{win_output_dir}}\win_reboot_test') {
+ New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' `
+ -Name PendingFileRenameOperations `
+ -Value @("\??\{{win_output_dir}}\win_reboot_test`0") `
+ -PropertyType MultiString
+ Restart-Computer -Force
+ exit 1
+}