From 08b654f48b562b6d75cabdcdbfa7c90651a8d9e7 Mon Sep 17 00:00:00 2001 From: Klention Mali Date: Sat, 19 Jul 2025 15:05:05 +0200 Subject: [PATCH] Clean FS, LV, VG and PSs before run --- .../lvm_pv_move_data/tasks/cleanup.yml | 8 ++++ .../lvm_pv_move_data/tasks/creation.yml | 37 +++++++++++++------ .../targets/lvm_pv_move_data/tasks/main.yml | 6 ++- .../targets/lvm_pv_move_data/tasks/moving.yml | 21 +++++++---- .../lvm_pv_move_data/tasks/prepare.yml | 23 ++++++++++++ 5 files changed, 74 insertions(+), 21 deletions(-) create mode 100644 tests/integration/targets/lvm_pv_move_data/tasks/prepare.yml diff --git a/tests/integration/targets/lvm_pv_move_data/tasks/cleanup.yml b/tests/integration/targets/lvm_pv_move_data/tasks/cleanup.yml index 515adadac5..1c121008b8 100644 --- a/tests/integration/targets/lvm_pv_move_data/tasks/cleanup.yml +++ b/tests/integration/targets/lvm_pv_move_data/tasks/cleanup.yml @@ -13,6 +13,14 @@ 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 }} diff --git a/tests/integration/targets/lvm_pv_move_data/tasks/creation.yml b/tests/integration/targets/lvm_pv_move_data/tasks/creation.yml index d0c4c74592..d22f882674 100644 --- a/tests/integration/targets/lvm_pv_move_data/tasks/creation.yml +++ b/tests/integration/targets/lvm_pv_move_data/tasks/creation.yml @@ -13,28 +13,39 @@ 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: Associating loop device with file - ansible.builtin.command: 'losetup {{ loop_device_02.stdout }} {{ remote_tmp_dir }}/test_lvm_pv_02.img' - - name: Wiping existing LVM metadata community.general.lvm_pv: - device: "{{ item }}" + device: "{{ loop_device_02.stdout }}" force: true state: absent - loop: - - "{{ loop_device_01.stdout }}" - - "{{ loop_device_02.stdout }}" + +- 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: @@ -54,10 +65,12 @@ ansible.builtin.command: pvs --noheadings -o pv_size --units M {{ loop_device_02.stdout }} register: pv_size_output_02 -- name: Creating volume group on top of first device {{ loop_device_01.stdout }} +- name: Creating volume group community.general.lvg: vg: testvg - pvs: "{{ loop_device_01.stdout }}" + pvs: + - "{{ loop_device_01.stdout }}" + - "{{ loop_device_02.stdout }}" force: true register: vg_creation_result @@ -88,9 +101,9 @@ - name: Asserting physical volume was created ansible.builtin.assert: that: - - pv_creation_result_01.changed == true - - pv_creation_result_02.changed == true - - vg_creation_result.changed == true + - pv_creation_result_01 is changed + - pv_creation_result_02 is changed + - vg_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 diff --git a/tests/integration/targets/lvm_pv_move_data/tasks/main.yml b/tests/integration/targets/lvm_pv_move_data/tasks/main.yml index e5e420832a..908e1b9a99 100644 --- a/tests/integration/targets/lvm_pv_move_data/tasks/main.yml +++ b/tests/integration/targets/lvm_pv_move_data/tasks/main.yml @@ -12,11 +12,15 @@ - name: Install required packages (Linux) when: ansible_system == 'Linux' ansible.builtin.package: - name: lvm2 + 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 diff --git a/tests/integration/targets/lvm_pv_move_data/tasks/moving.yml b/tests/integration/targets/lvm_pv_move_data/tasks/moving.yml index 0d125e4c5b..9b52f35f7e 100644 --- a/tests/integration/targets/lvm_pv_move_data/tasks/moving.yml +++ b/tests/integration/targets/lvm_pv_move_data/tasks/moving.yml @@ -8,13 +8,18 @@ args: creates: "{{ remote_tmp_dir }}/tmp_mount/test_file" -- name: Extending VG testvg with second device {{ loop_device_02.stdout }} - community.general.lvg: - vg: testvg - pvs: "{{ loop_device_02.stdout }}" - force: true +- name: Growing the second loop device file to 1500MB + ansible.builtin.shell: truncate -s 1500M {{ remote_tmp_dir }}/test_lvm_pv_02.img -- name: Moving data from {{ loop_device_01.stdout }} to {{ loop_device_02.stdout }} (both in same VG) +- 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 }}" @@ -27,5 +32,5 @@ - name: Asserting data was moved successfully ansible.builtin.assert: that: - - move_result.changed == true - - "'moved data from' in creation_result.msg" + - move_result is changed + - "'moved data from' in move_result.msg" diff --git a/tests/integration/targets/lvm_pv_move_data/tasks/prepare.yml b/tests/integration/targets/lvm_pv_move_data/tasks/prepare.yml new file mode 100644 index 0000000000..ced3f74dc6 --- /dev/null +++ b/tests/integration/targets/lvm_pv_move_data/tasks/prepare.yml @@ -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