mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
lvm_pv: new module for LVM Physical Volumes (#10070)
* Added LVM Physical Volume module * Fixed CI checks * python 2.7 compatibility * Fixed another fprint line not compatible with python 2.x * Applied cosmetic changes * Removed msg from RETURN section * Updated the 'absent state' block logic * Added integration tests * Updated logic for creating loop devices on Alpine Linux * Updated loop device path * Minor, cosmetic changes * Adjust indentation. --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
6bbd1dd7f5
commit
367b28d765
9 changed files with 331 additions and 0 deletions
13
tests/integration/targets/lvm_pv/aliases
Normal file
13
tests/integration/targets/lvm_pv/aliases
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Copyright (c) Contributors to the Ansible project
|
||||
# Based on the integraton test for the lvg module
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
azp/posix/1
|
||||
azp/posix/vm
|
||||
destructive
|
||||
needs/privileged
|
||||
skip/aix
|
||||
skip/freebsd
|
||||
skip/osx
|
||||
skip/macos
|
9
tests/integration/targets/lvm_pv/meta/main.yml
Normal file
9
tests/integration/targets/lvm_pv/meta/main.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# Based on the integraton test for the lvg module
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
dependencies:
|
||||
- setup_pkg_mgr
|
||||
- setup_remote_tmp_dir
|
12
tests/integration/targets/lvm_pv/tasks/cleanup.yml
Normal file
12
tests/integration/targets/lvm_pv/tasks/cleanup.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Detaching loop device
|
||||
ansible.builtin.command: losetup -d {{ loop_device.stdout }}
|
||||
|
||||
- name: Removing loop device file
|
||||
ansible.builtin.file:
|
||||
path: "{{ remote_tmp_dir }}/test_lvm_pv.img"
|
||||
state: absent
|
33
tests/integration/targets/lvm_pv/tasks/creation.yml
Normal file
33
tests/integration/targets/lvm_pv/tasks/creation.yml
Normal file
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Creating a 50MB file for loop device
|
||||
ansible.builtin.command: dd if=/dev/zero of={{ remote_tmp_dir }}/test_lvm_pv.img bs=1M count=50
|
||||
args:
|
||||
creates: "{{ remote_tmp_dir }}/test_lvm_pv.img"
|
||||
|
||||
- name: Creating loop device
|
||||
ansible.builtin.command: losetup -f
|
||||
register: loop_device
|
||||
|
||||
- name: Associating loop device with file
|
||||
ansible.builtin.command: 'losetup {{ loop_device.stdout }} {{ remote_tmp_dir }}/test_lvm_pv.img'
|
||||
|
||||
- name: Creating physical volume
|
||||
community.general.lvm_pv:
|
||||
device: "{{ loop_device.stdout }}"
|
||||
register: result
|
||||
|
||||
- name: Checking physical volume size
|
||||
ansible.builtin.command: pvs --noheadings -o pv_size --units M {{ loop_device.stdout }}
|
||||
register: pv_size_output
|
||||
|
||||
- name: Asserting physical volume was created
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- (pv_size_output.stdout | trim | regex_replace('M', '') | float) > 45
|
||||
- (pv_size_output.stdout | trim | regex_replace('M', '') | float) < 55
|
||||
- "'created' in result.msg"
|
27
tests/integration/targets/lvm_pv/tasks/main.yml
Normal file
27
tests/integration/targets/lvm_pv/tasks/main.yml
Normal file
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
####################################################################
|
||||
# WARNING: These are designed specifically for Ansible tests #
|
||||
# and should not be used as examples of how to write Ansible roles #
|
||||
####################################################################
|
||||
|
||||
# Copyright (c) Contributors to the Ansible project
|
||||
# Based on the integraton test for the lvg module
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Install required packages (Linux)
|
||||
when: ansible_system == 'Linux'
|
||||
ansible.builtin.package:
|
||||
name: lvm2
|
||||
state: present
|
||||
|
||||
- name: Testing lvg_pv module
|
||||
block:
|
||||
- import_tasks: creation.yml
|
||||
|
||||
- import_tasks: resizing.yml
|
||||
|
||||
- import_tasks: removal.yml
|
||||
|
||||
always:
|
||||
- import_tasks: cleanup.yml
|
16
tests/integration/targets/lvm_pv/tasks/removal.yml
Normal file
16
tests/integration/targets/lvm_pv/tasks/removal.yml
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Removing physical volume
|
||||
community.general.lvm_pv:
|
||||
device: "{{ loop_device.stdout }}"
|
||||
state: absent
|
||||
register: remove_result
|
||||
|
||||
- name: Asserting physical volume was removed
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- remove_result.changed == true
|
||||
- "'removed' in remove_result.msg"
|
27
tests/integration/targets/lvm_pv/tasks/resizing.yml
Normal file
27
tests/integration/targets/lvm_pv/tasks/resizing.yml
Normal file
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Growing the loop device file to 100MB
|
||||
ansible.builtin.shell: truncate -s 100M {{ remote_tmp_dir }}/test_lvm_pv.img
|
||||
|
||||
- name: Refreshing the loop device
|
||||
ansible.builtin.shell: losetup -c {{ loop_device.stdout }}
|
||||
|
||||
- name: Resizing the physical volume
|
||||
community.general.lvm_pv:
|
||||
device: "{{ loop_device.stdout }}"
|
||||
resize: true
|
||||
register: resize_result
|
||||
|
||||
- name: Checking physical volume size
|
||||
ansible.builtin.command: pvs --noheadings -o pv_size --units M {{ loop_device.stdout }}
|
||||
register: pv_size_output
|
||||
|
||||
- name: Asserting physical volume was resized
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- resize_result.changed == true
|
||||
- (pv_size_output.stdout | trim | regex_replace('M', '') | float) > 95
|
||||
- "'resized' in resize_result.msg"
|
Loading…
Add table
Add a link
Reference in a new issue