diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
commit | 8a754e0858d922e955e71b253c139e071ecec432 (patch) | |
tree | 527d16e74bfd1840c85efd675fdecad056c54107 /test/integration/targets/reboot | |
parent | Initial commit. (diff) | |
download | ansible-core-upstream/2.14.3.tar.xz ansible-core-upstream/2.14.3.zip |
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/reboot')
11 files changed, 167 insertions, 0 deletions
diff --git a/test/integration/targets/reboot/aliases b/test/integration/targets/reboot/aliases new file mode 100644 index 0000000..7f995fd --- /dev/null +++ b/test/integration/targets/reboot/aliases @@ -0,0 +1,5 @@ +context/target +destructive +needs/root +shippable/posix/group2 +skip/docker diff --git a/test/integration/targets/reboot/handlers/main.yml b/test/integration/targets/reboot/handlers/main.yml new file mode 100644 index 0000000..a40bac0 --- /dev/null +++ b/test/integration/targets/reboot/handlers/main.yml @@ -0,0 +1,4 @@ +- name: remove molly-guard + apt: + name: molly-guard + state: absent 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 0000000..059c422 --- /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 0000000..7f79770 --- /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 0000000..4884f10 --- /dev/null +++ b/test/integration/targets/reboot/tasks/main.yml @@ -0,0 +1,43 @@ +- name: Check split state + stat: + path: "{{ output_dir }}" + register: split + ignore_errors: yes + +- name: >- + Memorize whether we're in a containerized environment + and/or a split controller mode + set_fact: + in_container_env: >- + {{ + ansible_facts.virtualization_type | default('') + in ['docker', 'container', 'containerd'] + }} + in_split_controller_mode: >- + {{ split is not success or not split.stat.exists }} + +- name: Explain why testing against a container is not an option + debug: + msg: >- + This test is attempting to reboot the whole host operating system. + The current target is a containerized environment. Containers + cannot be reboot like VMs. This is why the test is being skipped. + when: in_container_env + +- name: Explain why testing against the same host is not an option + debug: + msg: >- + This test is attempting to reboot the whole host operating system. + This means it would interrupt itself trying to reboot own + environment. It needs to target a separate VM or machine to be + able to function so it's being skipped in the current invocation. + when: not in_split_controller_mode + +- name: Test reboot + when: not in_container_env and in_split_controller_mode + block: + - import_tasks: test_standard_scenarios.yml + - import_tasks: test_reboot_command.yml + - import_tasks: test_invalid_parameter.yml + - import_tasks: test_invalid_test_command.yml + - import_tasks: test_molly_guard.yml diff --git a/test/integration/targets/reboot/tasks/test_invalid_parameter.yml b/test/integration/targets/reboot/tasks/test_invalid_parameter.yml new file mode 100644 index 0000000..f8e1a8f --- /dev/null +++ b/test/integration/targets/reboot/tasks/test_invalid_parameter.yml @@ -0,0 +1,11 @@ +- name: Use invalid parameter + reboot: + foo: bar + ignore_errors: yes + 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/reboot/tasks/test_invalid_test_command.yml b/test/integration/targets/reboot/tasks/test_invalid_test_command.yml new file mode 100644 index 0000000..ea1db81 --- /dev/null +++ b/test/integration/targets/reboot/tasks/test_invalid_test_command.yml @@ -0,0 +1,8 @@ +- 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) }}" diff --git a/test/integration/targets/reboot/tasks/test_molly_guard.yml b/test/integration/targets/reboot/tasks/test_molly_guard.yml new file mode 100644 index 0000000..f91fd4f --- /dev/null +++ b/test/integration/targets/reboot/tasks/test_molly_guard.yml @@ -0,0 +1,20 @@ +- name: Test molly-guard + when: ansible_facts.distribution in ['Debian', 'Ubuntu'] + tags: + - molly-guard + block: + - import_tasks: get_boot_time.yml + + - name: Install molly-guard + apt: + update_cache: yes + name: molly-guard + state: present + notify: remove molly-guard + + - name: Reboot when molly-guard is installed + reboot: + search_paths: /lib/molly-guard + register: reboot_result + + - import_tasks: check_reboot.yml diff --git a/test/integration/targets/reboot/tasks/test_reboot_command.yml b/test/integration/targets/reboot/tasks/test_reboot_command.yml new file mode 100644 index 0000000..779d380 --- /dev/null +++ b/test/integration/targets/reboot/tasks/test_reboot_command.yml @@ -0,0 +1,22 @@ +- import_tasks: get_boot_time.yml +- name: Reboot with custom reboot_command using unqualified path + reboot: + reboot_command: reboot + register: reboot_result +- import_tasks: check_reboot.yml + + +- import_tasks: get_boot_time.yml +- name: Reboot with custom reboot_command using absolute path + reboot: + reboot_command: /sbin/reboot + register: reboot_result +- import_tasks: check_reboot.yml + + +- import_tasks: get_boot_time.yml +- name: Reboot with custom reboot_command with parameters + reboot: + reboot_command: shutdown -r now + register: reboot_result +- import_tasks: check_reboot.yml diff --git a/test/integration/targets/reboot/tasks/test_standard_scenarios.yml b/test/integration/targets/reboot/tasks/test_standard_scenarios.yml new file mode 100644 index 0000000..fac85be --- /dev/null +++ b/test/integration/targets/reboot/tasks/test_standard_scenarios.yml @@ -0,0 +1,32 @@ +- 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 except reboot_command + reboot: + connect_timeout: 30 + search_paths: + - /sbin + - /bin + - /usr/sbin + - /usr/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 diff --git a/test/integration/targets/reboot/vars/main.yml b/test/integration/targets/reboot/vars/main.yml new file mode 100644 index 0000000..0e1997c --- /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 |