mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-03 12:44:22 -07:00
Clean FS, LV, VG and PSs before run
This commit is contained in:
parent
2da7133717
commit
08b654f48b
5 changed files with 74 additions and 21 deletions
|
@ -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 }}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
23
tests/integration/targets/lvm_pv_move_data/tasks/prepare.yml
Normal file
23
tests/integration/targets/lvm_pv_move_data/tasks/prepare.yml
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue