forked from redhat-cop/infra.lvm_snapshots
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert - wait for all snapshots to drain before returning
Add a check that the all snapshots were drained Add test Add changelog fragement Signed-off-by: Ygal Blum <[email protected]>
- Loading branch information
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- Revert - wait for snapshot to drain before returning |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
- name: Fill the volume | ||
block: | ||
- name: Set the retry count | ||
ansible.builtin.set_fact: | ||
_retry_count: "{{ (_retry_count | default('-1') | int) + 1 }}" | ||
|
||
- name: Generate the Sub-Directory name | ||
ansible.builtin.set_fact: | ||
_sub_dir_name: "{{ lookup('community.general.random_string', upper=false, numbers=false, special=false) }}" | ||
|
||
- name: Make a copy of the boot partition | ||
ansible.builtin.copy: | ||
src: /boot | ||
dest: "{{ test_directory }}/{{ _sub_dir_name }}" | ||
remote_src: true | ||
mode: '0777' | ||
|
||
- name: Get the status of the snapshot | ||
ansible.builtin.command: "lvs --select 'lv_name = {{ volume_name }}_{{ snapshot_set_name }}' --reportformat json" | ||
register: _lv_status_check | ||
changed_when: false | ||
|
||
- name: Store the snapshot data_percent | ||
ansible.builtin.set_fact: | ||
_snapshot_data_percent: "{{ ((_lv_status_check.stdout | from_json).report[0].lv[0].data_percent) }}" | ||
|
||
- name: Check if snapshot is full enough | ||
ansible.builtin.assert: | ||
that: _snapshot_data_percent|float > snapshot_fill_percent|float | ||
quiet: true | ||
|
||
rescue: | ||
- name: Check the retry count to avoid endless loop | ||
ansible.builtin.assert: | ||
that: (_retry_count|int) < (snapshot_max_retry|int) | ||
fail_msg: "Ended after {{ snapshot_max_retry }} retries" | ||
success_msg: "Volume is not full enought ({{ _snapshot_data_percent }}) - Run again..." | ||
|
||
- name: Include the same tasks file again | ||
ansible.builtin.include_tasks: fill-snapshot.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
- name: Test revering to the snapshots | ||
hosts: all | ||
become: true | ||
vars: | ||
volume_group: test_vg | ||
test_directory: "/mnt/test" | ||
volume_name: test_lv | ||
volumes: | ||
- name: "{{ volume_name }}" | ||
size: 4g | ||
directory: "{{ test_directory }}" | ||
snapshot_set_name: demo_snap | ||
snapshot_fill_percent: 60 | ||
snapshot_max_retry: 100 | ||
tasks: | ||
- name: Run pre-test steps | ||
ansible.builtin.include_tasks: pre-test-tasks.yml | ||
|
||
- name: Create the snapshot | ||
ansible.builtin.include_tasks: create-snapshot.yml | ||
|
||
- name: Fill the snapshot | ||
ansible.builtin.include_tasks: fill-snapshot.yml | ||
|
||
- name: Revert to Snapshot | ||
vars: | ||
lvm_snapshots_action: revert | ||
lvm_snapshots_set_name: "{{ snapshot_set_name }}" | ||
ansible.builtin.include_role: | ||
name: lvm_snapshots | ||
|
||
- name: Verify that the snapshot was completly drained | ||
block: | ||
- name: Verify that the snapshot no longer exists | ||
vars: | ||
volume_name: test_lv | ||
ansible.builtin.include_tasks: verify-snapshot-not-exist.yml | ||
- name: Verify that the snapshot was drained before returning | ||
block: | ||
- name: Get the status of the volume | ||
ansible.builtin.command: "lvs --select 'lv_name = {{ volume_name }}' --reportformat json" | ||
register: _lv_status_check | ||
changed_when: false | ||
- name: Store the snapshot data_percent | ||
ansible.builtin.set_fact: | ||
volume_data_percent: "{{ ((_lv_status_check.stdout | from_json).report[0].lv[0].data_percent) }}" | ||
- name: Assert volume_data_percent is 0 | ||
ansible.builtin.assert: | ||
that: volume_data_percent|float == 0.0 | ||
fail_msg: "Volume data percent is {{ volume_data_percent }} while it should be 0" | ||
always: | ||
- name: Cleanup | ||
ansible.builtin.include_tasks: post-test-tasks.yml |