mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-01-12 07:35:31 +01:00
* Declare functions swapon() & swapoff(), is_swap() & reswap().
* Apply swapon/swapoff for states mounted, unmounted, remounted and
absent.
* Override default opts and boot when fstype=swap.
* Do not honor 'fstab' when fstype=swap (fail instead).
* Also fail when fstype=swap and 'path' is not 'none' ('-' for Solaris).
* Update module documentation accordingly.
+ Replace all platform.system() calls by a variable.
refactor integration tests
* Improve readability/understanding of what is tested, and what OS is
targeted.
* Move 'swap' related test cases into dedicated file (swap.yml).
* Add new test cases about swap enabling/disabling.
* Extend tests to FreeBSD when possible.
139 lines
3.3 KiB
YAML
139 lines
3.3 KiB
YAML
---
|
|
# Tasks to validate swapfile management (enabling/disabling its use) on FreeBSD.
|
|
# The swapfile MUST be associated to a memory disk, that becomes the 'src'.
|
|
|
|
- name: Swap off all (try to cleanup previous erraneous tests)
|
|
command:
|
|
cmd: swapoff -a
|
|
|
|
|
|
- name: Try to activate swapfile
|
|
vars:
|
|
swapfile: /var/swapfile0
|
|
md_unit: 99
|
|
md_name: "md{{ md_unit }}"
|
|
md_path: "/dev/{{ md_name }}"
|
|
|
|
block:
|
|
- name: Create a file to be used for memory swapping
|
|
command:
|
|
cmd: "dd if=/dev/zero of={{ swapfile }} bs=1M count=64"
|
|
creates: "{{ swapfile }}"
|
|
|
|
- name: Setup permissions suitable for swap usage
|
|
file:
|
|
path: "{{ swapfile }}"
|
|
mode: u=rw,go=
|
|
state: file
|
|
|
|
- name: Attach a memory disk to the swap file
|
|
command:
|
|
cmd: "mdconfig -a -t vnode -u {{ md_unit }} -f {{ swapfile }}"
|
|
creates: "{{ md_path }}"
|
|
|
|
|
|
- name: Get swap info (0)
|
|
command: swapctl -l
|
|
register: swap_info_0
|
|
changed_when: false
|
|
|
|
- name: Assert that memory disk {{ md_path }} is not used by swap
|
|
assert:
|
|
that:
|
|
- swap_info_0.stdout is not search(md_path)
|
|
|
|
- name: Enable swap file
|
|
mount:
|
|
path: none
|
|
src: "{{ md_name }}"
|
|
fstype: swap
|
|
opts: "sw,file={{ swapfile }}"
|
|
state: mounted
|
|
register: swap_enabled_1
|
|
|
|
- name: Get swap info (1)
|
|
command: swapctl -l
|
|
register: swap_info_1
|
|
changed_when: false
|
|
|
|
- name: Assert that swap file is enabled
|
|
assert:
|
|
that:
|
|
- swap_enabled_1 is changed
|
|
- swap_info_1.stdout is search(md_path)
|
|
|
|
|
|
- name: Enable swap file, again
|
|
mount:
|
|
path: none
|
|
src: "{{ md_name }}"
|
|
fstype: swap
|
|
opts: "sw,file={{ swapfile }}"
|
|
state: mounted
|
|
register: swap_enabled_2
|
|
|
|
- name: Get swap info (2)
|
|
command: swapctl -l
|
|
register: swap_info_2
|
|
changed_when: false
|
|
|
|
- name: Assert that nothing changed
|
|
assert:
|
|
that:
|
|
- swap_enabled_2 is not changed
|
|
- swap_info_2.stdout == swap_info_1.stdout
|
|
|
|
always:
|
|
- name: Disable swap file
|
|
mount:
|
|
path: none
|
|
src: "{{ md_name }}"
|
|
fstype: swap
|
|
state: absent
|
|
register: swap_disabled_1
|
|
|
|
- name: Get swap info (3)
|
|
command: swapctl -l
|
|
register: swap_info_3
|
|
changed_when: false
|
|
|
|
- name: Assert that swap file is disabled
|
|
assert:
|
|
that:
|
|
- swap_disabled_1 is changed
|
|
- swap_info_3.stdout == swap_info_0.stdout
|
|
|
|
- name: Disable swap file, again
|
|
mount:
|
|
path: none
|
|
src: "{{ md_name }}"
|
|
fstype: swap
|
|
state: absent
|
|
register: swap_disabled_2
|
|
|
|
- name: Get swap info (4)
|
|
command: swapctl -l
|
|
register: swap_info_4
|
|
changed_when: false
|
|
|
|
- name: Assert that swap file is disabled and nothing changed
|
|
assert:
|
|
that:
|
|
- swap_disabled_2 is not changed
|
|
- swap_info_4.stdout == swap_info_3.stdout
|
|
|
|
|
|
- name: Detach memory disk
|
|
command:
|
|
cmd: "mdconfig -d -u {{ md_unit }}"
|
|
removes: "{{ md_path }}"
|
|
|
|
- name: Remove swap file
|
|
file:
|
|
path: "{{ swapfile }}"
|
|
state: absent
|
|
|
|
|
|
- name: Swap on all (try to restore pre-test state)
|
|
command:
|
|
cmd: swapon -a
|