summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/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/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 '')
-rw-r--r--test/integration/targets/reboot/aliases2
-rw-r--r--test/integration/targets/reboot/tasks/check_reboot.yml10
-rw-r--r--test/integration/targets/reboot/tasks/get_boot_time.yml3
-rw-r--r--test/integration/targets/reboot/tasks/main.yml111
-rw-r--r--test/integration/targets/reboot/vars/main.yml9
5 files changed, 135 insertions, 0 deletions
diff --git a/test/integration/targets/reboot/aliases b/test/integration/targets/reboot/aliases
new file mode 100644
index 00000000..e9bebbf3
--- /dev/null
+++ b/test/integration/targets/reboot/aliases
@@ -0,0 +1,2 @@
+# No current way to split controller and test node
+unsupported
diff --git a/test/integration/targets/reboot/tasks/check_reboot.yml b/test/integration/targets/reboot/tasks/check_reboot.yml
new file mode 100644
index 00000000..1aff1be2
--- /dev/null
+++ b/test/integration/targets/reboot/tasks/check_reboot.yml
@@ -0,0 +1,10 @@
+- name: Get current boot time
+ command: "{{ boot_time_command[ansible_facts['distribution'] | lower] | default('cat /proc/sys/kernel/random/boot_id') }}"
+ register: after_boot_time
+
+- name: Ensure system was actually rebooted
+ assert:
+ that:
+ - reboot_result is changed
+ - reboot_result.elapsed > 10
+ - before_boot_time.stdout != after_boot_time.stdout
diff --git a/test/integration/targets/reboot/tasks/get_boot_time.yml b/test/integration/targets/reboot/tasks/get_boot_time.yml
new file mode 100644
index 00000000..cec22f06
--- /dev/null
+++ b/test/integration/targets/reboot/tasks/get_boot_time.yml
@@ -0,0 +1,3 @@
+- name: Get current boot time
+ command: "{{ boot_time_command[ansible_facts['distribution'] | lower] | default('cat /proc/sys/kernel/random/boot_id') }}"
+ register: before_boot_time
diff --git a/test/integration/targets/reboot/tasks/main.yml b/test/integration/targets/reboot/tasks/main.yml
new file mode 100644
index 00000000..2568b9b2
--- /dev/null
+++ b/test/integration/targets/reboot/tasks/main.yml
@@ -0,0 +1,111 @@
+- block:
+ # This block can be removed once we have a mechanism in ansible-test to separate
+ # the control node from the managed node.
+ - block:
+ - name: Write temp file for sanity checking this is not the controller
+ copy:
+ content: 'I am the control node'
+ dest: /tmp/Anything-Nutlike-Nuzzle-Plow-Overdue
+ delegate_to: localhost
+ connection: local
+ when: inventory_hostname == ansible_play_hosts[0]
+
+ - name: See if the temp file exists on the managed node
+ stat:
+ path: /tmp/Anything-Nutlike-Nuzzle-Plow-Overdue
+ register: controller_temp_file
+
+ - name: EXPECT FAILURE | Check if the managed node is the control node
+ assert:
+ msg: >
+ This test must be run manually by modifying the inventory file to point
+ "{{ inventory_hostname }}" at a remote host rather than "{{ ansible_host }}".
+ Skipping reboot test.
+ that:
+ - not controller_temp_file.stat.exists
+
+ - import_tasks: get_boot_time.yml
+
+ - name: Reboot with default settings
+ reboot:
+ register: reboot_result
+
+ - import_tasks: check_reboot.yml
+
+ - import_tasks: get_boot_time.yml
+
+ - name: Reboot with all options
+ reboot:
+ connect_timeout: 30
+ search_paths: /usr/local/bin
+ msg: Rebooting
+ post_reboot_delay: 1
+ pre_reboot_delay: 61
+ test_command: uptime
+ reboot_timeout: 500
+ register: reboot_result
+
+ - import_tasks: check_reboot.yml
+
+ - import_tasks: get_boot_time.yml
+
+ - name: Test with negative values for delays
+ reboot:
+ post_reboot_delay: -0.5
+ pre_reboot_delay: -61
+ register: reboot_result
+
+ - import_tasks: check_reboot.yml
+
+ - 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'"
+
+ - name: Reboot with test command that fails
+ reboot:
+ test_command: 'FAIL'
+ reboot_timeout: "{{ timeout }}"
+ register: reboot_fail_test
+ failed_when: "reboot_fail_test.msg != 'Timed out waiting for post-reboot test command (timeout=' ~ timeout ~ ')'"
+ vars:
+ timeout: "{{ timeout_value[ansible_facts['distribution'] | lower] | default(60) }}"
+
+ - name: Test molly-guard
+ block:
+ - import_tasks: get_boot_time.yml
+
+ - name: Install molly-guard
+ apt:
+ update_cache: yes
+ name: molly-guard
+ state: present
+
+ - name: Reboot when molly-guard is installed
+ reboot:
+ search_paths: /lib/molly-guard
+ register: reboot_result
+
+ - import_tasks: check_reboot.yml
+
+ when: ansible_facts.distribution in ['Debian', 'Ubuntu']
+ tags:
+ - molly-guard
+
+ always:
+ - name: Cleanup temp file
+ file:
+ path: /tmp/Anything-Nutlike-Nuzzle-Plow-Overdue
+ state: absent
+ delegate_to: localhost
+ connection: local
+ when: inventory_hostname == ansible_play_hosts[0]
+
+ when: ansible_virtualization_type | default('') != 'docker'
diff --git a/test/integration/targets/reboot/vars/main.yml b/test/integration/targets/reboot/vars/main.yml
new file mode 100644
index 00000000..24367c80
--- /dev/null
+++ b/test/integration/targets/reboot/vars/main.yml
@@ -0,0 +1,9 @@
+boot_time_command:
+ freebsd: '/sbin/sysctl kern.boottime'
+ openbsd: '/sbin/sysctl kern.boottime'
+ macosx: 'who -b'
+ solaris: 'who -b'
+ sunos: 'who -b'
+
+timeout_value:
+ solaris: 120