lvm_pv_move_data: new module (#10416)

* Added lvm_pv_move_data module

* Removed trailing whitespace

* Decreased loop devices file size

* Remove test VG if exists

* Force remove test VG if exists

* Renamed test VG and LV names

* Updated assert conditions

* Added .ansible to .gitignore

* Force extending VG

* Wiping LVM metadata from PVs before creating VG

* Clean FS, LV, VG and PSs before run

* Migrated to CmdRunner

* Added more detailed info in case of failure and cosmetic changes

* Remove redundant params from CmdRunner call

* Updates the RETURN documentation block to properly specify the return type
of the 'actions' field:
- Changes return status from 'always' to 'success'
- Adds missing 'elements: str' type specification
This commit is contained in:
Klention Mali 2025-08-04 19:59:54 +02:00 committed by GitHub
commit e91e2ef6f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 487 additions and 0 deletions

View file

@ -0,0 +1,13 @@
# Copyright (c) Contributors to the Ansible project
# Based on the integraton test for the lvm_pv 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

View 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

View file

@ -0,0 +1,39 @@
---
# 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: Unmounting temp file system
ansible.posix.mount:
fstab: '{{ remote_tmp_dir }}/fstab'
path: '{{ remote_tmp_dir }}/tmp_mount'
state: absent
- name: Removing xfs filesystem from LV lv_tmp_test
community.general.filesystem:
dev: /dev/vg_tmp_test/lv_tmp_test
state: absent
force: true
- name: Deleting testlv logical volume
community.general.lvol:
vg: testvg
lv: testlv
force: true
state: absent
- name: Detaching first loop device
ansible.builtin.command: losetup -d {{ loop_device_01.stdout }}
- name: Detaching second loop device
ansible.builtin.command: losetup -d {{ loop_device_02.stdout }}
- name: Removing first loop device file
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/test_lvm_pv_01.img"
state: absent
- name: Removing second loop device file
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/test_lvm_pv_02.img"
state: absent

View file

@ -0,0 +1,115 @@
---
# 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 500MB file for the first loop device
ansible.builtin.command: dd if=/dev/zero of={{ remote_tmp_dir }}/test_lvm_pv_01.img bs=1M count=500
args:
creates: "{{ remote_tmp_dir }}/test_lvm_pv_01.img"
- name: Creating a 1000MB file for the second loop device
ansible.builtin.command: dd if=/dev/zero of={{ remote_tmp_dir }}/test_lvm_pv_02.img bs=1M count=1000
args:
creates: "{{ remote_tmp_dir }}/test_lvm_pv_02.img"
- name: Pausing for a random time between 5-15 seconds
ansible.builtin.pause:
seconds: "{{ range(5, 16) | random }}"
- name: Creating loop device
ansible.builtin.command: losetup -f
register: loop_device_01
- name: Wiping existing LVM metadata
community.general.lvm_pv:
device: "{{ loop_device_01.stdout }}"
force: true
state: absent
- name: Associating loop device with file
ansible.builtin.command: 'losetup {{ loop_device_01.stdout }} {{ remote_tmp_dir }}/test_lvm_pv_01.img'
- name: Pausing for a random time between 5-15 seconds
ansible.builtin.pause:
seconds: "{{ range(5, 16) | random }}"
- name: Creating loop device
ansible.builtin.command: losetup -f
register: loop_device_02
- name: Wiping existing LVM metadata
community.general.lvm_pv:
device: "{{ loop_device_02.stdout }}"
force: true
state: absent
- name: Associating loop device with file
ansible.builtin.command: 'losetup {{ loop_device_02.stdout }} {{ remote_tmp_dir }}/test_lvm_pv_02.img'
- name: Creating physical volume for the first loop device
community.general.lvm_pv:
device: "{{ loop_device_01.stdout }}"
register: pv_creation_result_01
- name: Checking the first physical volume size
ansible.builtin.command: pvs --noheadings -o pv_size --units M {{ loop_device_01.stdout }}
register: pv_size_output_01
- name: Creating physical volume for the second loop device
community.general.lvm_pv:
device: "{{ loop_device_02.stdout }}"
register: pv_creation_result_02
- name: Checking the second physical volume size
ansible.builtin.command: pvs --noheadings -o pv_size --units M {{ loop_device_02.stdout }}
register: pv_size_output_02
- name: Creating volume group
community.general.lvg:
vg: testvg
pvs:
- "{{ loop_device_01.stdout }}"
- "{{ loop_device_02.stdout }}"
force: true
register: vg_creation_result
- name: Creating LV testlv on VG testvg
community.general.lvol:
vg: testvg
lv: testlv
size: 100%FREE
force: true
register: lv_creation_result
- name: Creating xfs filesystem on LV testlv
community.general.filesystem:
dev: /dev/testvg/testlv
fstype: xfs
state: present
register: fs_creation_result
- name: Mounting LV testlv
ansible.posix.mount:
fstab: '{{ remote_tmp_dir }}/fstab'
path: '{{ remote_tmp_dir }}/tmp_mount'
src: '/dev/testvg/testlv'
fstype: xfs
opts: rw,noauto
state: mounted
register: mount_result
- name: Asserting PVs, VG, LV and filesystem were created successfully
ansible.builtin.assert:
that:
- pv_creation_result_01 is changed
- pv_creation_result_02 is changed
- vg_creation_result is changed
- lv_creation_result is changed
- fs_creation_result is changed
- (pv_size_output_01.stdout | trim | regex_replace('M', '') | float) > 450
- (pv_size_output_01.stdout | trim | regex_replace('M', '') | float) < 600
- (pv_size_output_02.stdout | trim | regex_replace('M', '') | float) > 950
- (pv_size_output_02.stdout | trim | regex_replace('M', '') | float) < 1100
- "'created' in pv_creation_result_01.msg"
- "'created' in pv_creation_result_02.msg"

View file

@ -0,0 +1,29 @@
---
####################################################################
# 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 integration test for the lvm_pv 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
- xfsprogs
state: present
- name: Testing lvm_pv_move_data module
block:
- import_tasks: prepare.yml
- import_tasks: creation.yml
- import_tasks: moving.yml
always:
- import_tasks: cleanup.yml

View file

@ -0,0 +1,36 @@
---
# 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 on the mounted LV
ansible.builtin.command: dd if=/dev/zero of={{ remote_tmp_dir }}/tmp_mount/test_file bs=1M count=50
args:
creates: "{{ remote_tmp_dir }}/tmp_mount/test_file"
- name: Growing the second loop device file to 1500MB
ansible.builtin.shell: truncate -s 1500M {{ remote_tmp_dir }}/test_lvm_pv_02.img
- name: Refreshing the second loop device
ansible.builtin.shell: losetup -c {{ loop_device_02.stdout }}
- name: Resizing the second physical volume
community.general.lvm_pv:
device: "{{ loop_device_02.stdout }}"
resize: true
- name: Moving data from between PVs (both in same VG)
community.general.lvm_pv_move_data:
source: "{{ loop_device_01.stdout }}"
destination: "{{ loop_device_02.stdout }}"
register: move_result
- name: Debugging move result
ansible.builtin.debug:
var: move_result
- name: Asserting data was moved successfully
ansible.builtin.assert:
that:
- move_result is changed
- "'moved data from' in move_result.msg"

View file

@ -0,0 +1,23 @@
---
# 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 xfs filesystem from LV lv_tmp_test
community.general.filesystem:
dev: /dev/vg_tmp_test/lv_tmp_test
state: absent
force: true
- name: Deleting testlv logical volume
community.general.lvol:
vg: testvg
lv: testlv
force: true
state: absent
- name: Deleting volume group testvg
community.general.lvg:
vg: testvg
force: true
state: absent