Skip to content

Commit

Permalink
Attempt to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spetrosi committed Jan 3, 2024
1 parent 291587e commit 553cd68
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
10 changes: 6 additions & 4 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
{{ __bootloader_default_grub }}
cat {{ __bootloader_default_grub }}
changed_when: true
when: >-
(ansible_distribution in ['CentOS', 'RedHat'] and
ansible_facts.distribution_major_version is version('7', '=')) or
ansible_distribution == 'Fedora'
when:
- ansible_distribution in ['CentOS', 'RedHat']
- ansible_facts.distribution_major_version is version('7', '=')

- name: Rebuild grub config
command: grub2-mkconfig -o {{ __bootloader_grub_conf }}
changed_when: true
when:
- ansible_distribution in ['CentOS', 'RedHat']
- ansible_facts.distribution_major_version is version('7', '=')

- name: Reboot system
include_tasks: tasks/reboot.yml
64 changes: 35 additions & 29 deletions tests/tests_add_rm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,38 @@
include_role:
name: linux-system-roles.bootloader

- name: Clone the oldest kernel and initrd for test purposes
- name: Set fact with the default kernel to use for clones
set_fact:
test_kernel: "{{ bootloader_facts | rejectattr('initrd', 'undefined')
| selectattr('default', 'equalto', True) | first }}"

- name: Clone test_kernel kernel and initrd for test purposes
copy:
src: "{{ item.src }}"
remote_src: true
dest: "{{ item.dest }}"
mode: preserve
loop:
- src: "{{ (bootloader_facts | last).kernel }}"
dest: "{{ (bootloader_facts | last).kernel }}_clone1"
- src: "{{ (bootloader_facts | last).initrd |
regex_replace(' .*$', '') }}"
dest: "{{ (bootloader_facts | last).initrd |
regex_replace(' .*$', '') }}_clone1"
- src: "{{ (bootloader_facts | last).kernel }}"
dest: "{{ (bootloader_facts | last).kernel }}_clone2"
- src: "{{ (bootloader_facts | last).initrd |
regex_replace(' .*$', '') }}"
dest: "{{ (bootloader_facts | last).initrd |
regex_replace(' .*$', '') }}_clone2"
- src: "{{ test_kernel.kernel }}"
dest: "{{ test_kernel.kernel }}_clone1"
- src: "{{ test_kernel.initrd | regex_replace(' .*$', '') }}"
dest: "{{ test_kernel.initrd | regex_replace(' .*$', '') }}_clone1"
- src: "{{ test_kernel.kernel }}"
dest: "{{ test_kernel.kernel }}_clone2"
- src: "{{ test_kernel.initrd | regex_replace(' .*$', '') }}"
dest: "{{ test_kernel.initrd | regex_replace(' .*$', '') }}_clone2"

- name: Create Clone1 kernel with copy_defaults=true
vars:
bootloader_settings:
- kernel:
path: "{{ (bootloader_facts | last).kernel }}_clone1"
initrd: "{{ (bootloader_facts | last).initrd |
path: "{{ test_kernel.kernel }}_clone1"
initrd: "{{ test_kernel.initrd |
regex_replace(' .*$', '') }}_clone1"
title: Clone1
options:
- name: console
value: tty0
- name: test
value: setting
state: present
- copy_default: true
include_role:
Expand All @@ -66,20 +67,22 @@
- name: Verify settings
vars:
__default_args: "{{
(bootloader_facts | selectattr('default', 'equalto', True) |
(bootloader_facts | selectattr('title', 'defined') |
selectattr('default', 'equalto', True) |
first).args }}"
assert:
that: >-
(bootloader_facts | selectattr('title', 'search', 'Clone1') |
first).args == __default_args ~ ' console=tty0'
(bootloader_facts | selectattr('title', 'defined') |
selectattr('title', 'search', 'Clone1') |
first).args == __default_args ~ ' test=setting'
- name: Remove Clone1 kernel with 3 kernel keys
vars:
bootloader_gather_facts: true
bootloader_settings:
- kernel:
path: "{{ (bootloader_facts | last).kernel }}_clone1"
initrd: "{{ (bootloader_facts | last).initrd |
path: "{{ test_kernel.kernel }}_clone1"
initrd: "{{ test_kernel.initrd |
regex_replace(' .*$', '') }}_clone1"
title: Clone1
options:
Expand All @@ -93,15 +96,16 @@

- name: Verify that Clone1 kernel is removed
assert:
that: bootloader_facts | selectattr('title', 'search', 'Clone1') |
that: bootloader_facts | selectattr('title', 'defined') |
selectattr('title', 'search', 'Clone1') |
list | length == 0

- name: Create clone2 kernel without copy_defaults=true
vars:
bootloader_settings:
- kernel:
path: "{{ (bootloader_facts | last).kernel }}_clone2"
initrd: "{{ (bootloader_facts | last).initrd |
path: "{{ test_kernel.kernel }}_clone2"
initrd: "{{ test_kernel.initrd |
regex_replace(' .*$', '') }}_clone2"
title: Clone2
options:
Expand All @@ -127,16 +131,17 @@
- name: Verify settings
assert:
that: >-
(bootloader_facts | selectattr('title', 'search', 'Clone2') |
(bootloader_facts | selectattr('title', 'defined') |
selectattr('title', 'search', 'Clone2') |
first).args == 'console=tty0'
- name: Remove Clone2 kernel with kernel path
vars:
bootloader_gather_facts: true
bootloader_settings:
- kernel:
path: "{{ (bootloader_facts | last).kernel }}_clone2"
initrd: "{{ (bootloader_facts | last).initrd |
path: "{{ test_kernel.kernel }}_clone2"
initrd: "{{ test_kernel.initrd |
regex_replace(' .*$', '') }}_clone2"
title: Clone2
state: absent
Expand All @@ -145,5 +150,6 @@

- name: Verify that Clone2 kernel is removed
assert:
that: bootloader_facts | selectattr('title', 'search', 'Clone2') |
that: bootloader_facts | selectattr('title', 'defined') |
selectattr('title', 'search', 'Clone2') |
list | length == 0

0 comments on commit 553cd68

Please sign in to comment.