Skip to content

Commit

Permalink
fix: remove prefix parameter and change suffix to snapset name
Browse files Browse the repository at this point in the history
Use snapshot_lvm_snapset_name to identify a set of snapshots.  The snapset
name is appended to the LV name to indicate membership in the set.

Using a set name will map more easily to how snapm is being implemented.
If/when we decide to back the role with snapm, it will be easier to
keep the current interface if we use only a snapset name and drop the
prefix.

See : https://github.com/snapshotmanager/snapm/

Signed-off-by: Todd Gill <[email protected]>
  • Loading branch information
trgill committed Feb 3, 2024
1 parent e577b89 commit b39b2ab
Show file tree
Hide file tree
Showing 19 changed files with 228 additions and 118 deletions.
52 changes: 24 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,11 @@ Sets are defined in the following format:

If before running the role, with :

### snapshot_lvm_prefix
### snapshot_lvm_snapset_name

This variable is required if not using sets. snapshot_lvm_prefix is a string that will be
prepended to the name of the LV when the snapshot is created.

### snapshot_lvm_suffix

This variable is required if not using sets. snapshot_lvm_prefix is a string that will be
appended to the name of the LV when the snapshot is created.
This variable is required. snapshot_lvm_snapset_name is a string that will be
appended to the name of the LV when the snapshot set is created. It will be used
to identify members of the set.

If before running the role, the following LVs exist:

Expand All @@ -94,29 +90,29 @@ lv1_vg3 vg3 -wi-a----- 1.00g
lv3_vg3 vg3 -wi-a----- 120.00m
```

If the prefix is set to "a_" and the suffix is set to "_z", running the role will result
If snapshot_lvm_snapset_name is set to "_snapset1", running the role will result
in the following:

```text
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
a_home_z rhel swi-a-s--- 104.00m home 0.00
a_root_z rhel swi-a-s--- 3.50g root 0.01
a_swap_z rhel swi-a-s--- 400.00m swap 0.00
home rhel owi-aos--- 1.00g
root rhel owi-aos--- 35.00g
swap rhel owi-aos--- <3.88g
a_lv1_vg1_z vg1 swi-a-s--- 104.00m lv1_vg1 0.00
a_lv2_vg1_z vg1 swi-a-s--- 8.00m lv2_vg1 0.00
lv1_vg1 vg1 owi-a-s--- 1.00g
lv2_vg1 vg1 owi-a-s--- 40.00m
a_lv1_vg2_z vg2 swi-a-s--- 104.00m lv1_vg2 0.00
a_lv2_vg2_z vg2 swi-a-s--- 12.00m lv2_vg2 0.00
lv1_vg2 vg2 owi-a-s--- 1.00g
lv2_vg2 vg2 owi-a-s--- 80.00m
a_lv1_vg3_z vg3 swi-a-s--- 104.00m lv1_vg3 0.00
a_lv3_vg3_z vg3 swi-a-s--- 16.00m lv3_vg3 0.00
lv1_vg3 vg3 owi-a-s--- 1.00g
lv3_vg3 vg3 owi-a-s--- 120.00m
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home_snapset1 rhel swi-a-s--- 104.00m home 0.00
root_snapset1 rhel swi-a-s--- 3.50g root 0.01
swap_snapset1 rhel swi-a-s--- 400.00m swap 0.00
home rhel owi-aos--- 1.00g
root rhel owi-aos--- 35.00g
swap rhel owi-aos--- <3.88g
lv1_vg1_snapset1 vg1 swi-a-s--- 104.00m lv1_vg1 0.00
lv2_vg1_snapset1 vg1 swi-a-s--- 8.00m lv2_vg1 0.00
lv1_vg1 vg1 owi-a-s--- 1.00g
lv2_vg1 vg1 owi-a-s--- 40.00m
lv1_vg2_snapset1 vg2 swi-a-s--- 104.00m lv1_vg2 0.00
lv2_vg2_snapset1 vg2 swi-a-s--- 12.00m lv2_vg2 0.00
lv1_vg2 vg2 owi-a-s--- 1.00g
lv2_vg2 vg2 owi-a-s--- 80.00m
lv1_vg3_snapset1 vg3 swi-a-s--- 104.00m lv1_vg3 0.00
lv3_vg3_snapset1 vg3 swi-a-s--- 16.00m lv3_vg3 0.00
lv1_vg3 vg3 owi-a-s--- 1.00g
lv3_vg3 vg3 owi-a-s--- 120.00m
```

### snapshot_lvm_percent_space_required
Expand Down
3 changes: 1 addition & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ snapshot_lvm_all_vgs: false
snapshot_lvm_verify_only: false
snapshot_lvm_vg: ''
snapshot_lvm_lv: ''
snapshot_lvm_prefix: ''
snapshot_lvm_suffix: ''
snapshot_lvm_snapset_name: ''
snapshot_lvm_percent_space_required: ''
snapshot_lvm_set: ''
3 changes: 1 addition & 2 deletions examples/check_space.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
hosts: all
vars:
snapshot_lvm_action: check
snapshot_lvm_prefix: a_
snapshot_lvm_suffix: _z
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_percent_space_required: 20
snapshot_lvm_all_vgs: true
roles:
Expand Down
3 changes: 1 addition & 2 deletions examples/remove_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
hosts: all
vars:
snapshot_lvm_action: remove
snapshot_lvm_prefix: a_
snapshot_lvm_suffix: _z
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_all_vgs: true
roles:
- linux-system-roles.snapshot
3 changes: 1 addition & 2 deletions examples/snapshot_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
hosts: all
vars:
snapshot_lvm_action: snapshot
snapshot_lvm_prefix: a_
snapshot_lvm_suffix: _z
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_percent_space_required: 20
snapshot_lvm_all_vgs: true
roles:
Expand Down
35 changes: 14 additions & 21 deletions tasks/files/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def get_snapshot_name(lv_name, prefix, suffix):
else:
suffix_str = ""

return prefix_str + lv_name + suffix_str
return prefix_str + lv_name + "_" + suffix_str


def lvm_lv_exists(vg_name, lv_name):
Expand Down Expand Up @@ -493,7 +493,7 @@ def extend_snapshot_set(snapset_json):
percent_space_required = list_item["percent_space_required"]

rc, message = extend_lv_snapshot(
vg, lv, None, get_snapset_suffix(snapset_name), percent_space_required
vg, lv, None, snapset_name, percent_space_required
)

if rc != SnapshotStatus.SNAPSHOT_OK:
Expand All @@ -513,7 +513,7 @@ def extend_verify_snapshot_set(snapset_json):
lv = list_item["lv"]
percent_space_required = list_item["percent_space_required"]

snapshot_name = get_snapshot_name(lv, None, get_snapset_suffix(snapset_name))
snapshot_name = get_snapshot_name(lv, None, snapset_name)

rc, _vg_exists, lv_exists = lvm_lv_exists(vg, snapshot_name)
if rc != SnapshotStatus.SNAPSHOT_OK:
Expand Down Expand Up @@ -815,7 +815,7 @@ def check_verify_lvs_set(snapset_json):
vg = list_item["vg"]
lv = list_item["lv"]

snapshot_name = get_snapshot_name(lv, None, get_snapset_suffix(snapset_name))
snapshot_name = get_snapshot_name(lv, None, snapset_name)

rc, _vg_exists, lv_exists = lvm_lv_exists(vg, snapshot_name)
if rc != SnapshotStatus.SNAPSHOT_OK:
Expand Down Expand Up @@ -933,7 +933,8 @@ def revert_snapshot_set(snapset_json):
vg = list_item["vg"]
lv = list_item["lv"]

rc, message = revert_lv(vg, lv, None, get_snapset_suffix(snapset_name))
rc, message = revert_lv(
vg, lv, None, get_snapshot_name(lv, None, snapset_name))

if rc != SnapshotStatus.SNAPSHOT_OK:
return rc, message
Expand All @@ -950,7 +951,7 @@ def remove_snapshot_set(snapset_json):
for list_item in volume_list:
vg = list_item["vg"]
lv = list_item["lv"]
snapshot_name = get_snapshot_name(lv, None, get_snapset_suffix(snapset_name))
snapshot_name = get_snapshot_name(lv, None, snapset_name)

rc, vg_exists, lv_exists = lvm_lv_exists(vg, snapshot_name)

Expand All @@ -973,7 +974,7 @@ def remove_snapshot_set(snapset_json):
vg = list_item["vg"]
lv = list_item["lv"]

snapshot_name = get_snapshot_name(lv, None, get_snapset_suffix(snapset_name))
snapshot_name = get_snapshot_name(lv, None, snapset_name)

rc, vg_exists, lv_exists = lvm_lv_exists(vg, snapshot_name)
if rc != SnapshotStatus.SNAPSHOT_OK:
Expand Down Expand Up @@ -1001,7 +1002,7 @@ def remove_verify_snapshot_set(snapset_json):
vg = list_item["vg"]
lv = list_item["lv"]

snapshot_name = get_snapshot_name(lv, None, get_snapset_suffix(snapset_name))
snapshot_name = get_snapshot_name(lv, None, snapset_name)

rc, _vg_exists, lv_exists = lvm_lv_exists(vg, snapshot_name)
if rc != SnapshotStatus.SNAPSHOT_OK:
Expand Down Expand Up @@ -1211,7 +1212,7 @@ def verify_snapset_target_no_existing(snapset_json):
vg = list_item["vg"]
lv = list_item["lv"]

snapshot_name = get_snapshot_name(lv, None, get_snapset_suffix(snapset_name))
snapshot_name = get_snapshot_name(lv, None, snapset_name)

rc, _vg_exists, lv_exists = lvm_lv_exists(vg, snapshot_name)
if rc != SnapshotStatus.SNAPSHOT_OK:
Expand Down Expand Up @@ -1259,20 +1260,14 @@ def verify_snapset_source_lvs_exist(snapset_json):
return SnapshotStatus.SNAPSHOT_OK, ""


def get_snapset_suffix(snapset_name):
return "_" + snapset_name


def verify_snapset_names(snapset_json):
snapset_name = snapset_json["name"]
volume_list = snapset_json["volumes"]
logger.info("verify snapsset : %s", snapset_name)
for list_item in volume_list:
lv = list_item["lv"]

rc, message = check_name_for_snapshot(
lv, None, get_snapset_suffix(snapset_name)
)
rc, message = check_name_for_snapshot(lv, None, snapset_name)
if rc != SnapshotStatus.SNAPSHOT_OK:
return rc, message

Expand Down Expand Up @@ -1379,9 +1374,7 @@ def snapshot_create_set(snapset_json):
vg, lv, percent_space_required, current_space_dict
)

rc, message = snapshot_lv(
vg, lv, None, get_snapset_suffix(snapset_name), required_size
)
rc, message = snapshot_lv(vg, lv, None, snapset_name, required_size)
if rc != SnapshotStatus.SNAPSHOT_OK:
return rc, message

Expand Down Expand Up @@ -1861,10 +1854,10 @@ def extend_cmd(args):
)
common_parser.add_argument(
"-s",
"--suffix",
"--snapset",
dest="suffix",
type=str,
help="suffix to add to volume name for snapshot",
help="name for snapshot set",
)
common_parser.add_argument(
"-p",
Expand Down
12 changes: 4 additions & 8 deletions tests/tests_basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,30 @@
vars:
snapshot_lvm_percent_space_required: 15
snapshot_lvm_all_vgs: true
snapshot_lvm_suffix: _z
snapshot_lvm_prefix: a_
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_action: snapshot

- name: Verify the snapshot LVs are created
include_role:
name: linux-system-roles.snapshot
vars:
snapshot_lvm_all_vgs: true
snapshot_lvm_suffix: _z
snapshot_lvm_prefix: a_
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_verify_only: true
snapshot_lvm_action: check

- name: Run the snapshot role remove the snapshot LVs
include_role:
name: linux-system-roles.snapshot
vars:
snapshot_lvm_suffix: _z
snapshot_lvm_prefix: a_
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_action: remove

- name: Use the snapshot_lvm_verify option to make sure remove is done
include_role:
name: linux-system-roles.snapshot
vars:
snapshot_lvm_suffix: _z
snapshot_lvm_prefix: a_
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_verify_only: true
snapshot_lvm_action: remove
always:
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_check_no_lv_fail.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
__snapshot_failed_params:
snapshot_lvm_vg: test_vg1
snapshot_lvm_lv: xxxxx
snapshot_lvm_suffix: _z
snapshot_lvm_prefix: a_
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_verify_only: true
snapshot_lvm_action: check
always:
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_check_no_vg_fail.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
__snapshot_failed_msg: Role check did not fail with wrong VG
__snapshot_failed_params:
snapshot_lvm_vg: xxxxxx
snapshot_lvm_suffix: _z
snapshot_lvm_prefix: a_
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_verify_only: true
snapshot_lvm_action: check
always:
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
vars:
snapshot_lvm_action: check
snapshot_lvm_percent_space_required: 2
snapshot_lvm_prefix: a_
snapshot_lvm_suffix: _z
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_all_vgs: true
roles:
- linux-system-roles.snapshot
12 changes: 4 additions & 8 deletions tests/tests_extend_basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,15 @@
vars:
snapshot_lvm_percent_space_required: 15
snapshot_lvm_all_vgs: true
snapshot_lvm_suffix: _z
snapshot_lvm_prefix: a_
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_action: snapshot

- name: Verify the snapshot LVs are created
include_role:
name: linux-system-roles.snapshot
vars:
snapshot_lvm_all_vgs: true
snapshot_lvm_suffix: _z
snapshot_lvm_prefix: a_
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_verify_only: true
snapshot_lvm_action: check

Expand All @@ -80,8 +78,7 @@
vars:
snapshot_lvm_percent_space_required: 40
snapshot_lvm_all_vgs: true
snapshot_lvm_suffix: _z
snapshot_lvm_prefix: a_
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_action: extend

- name: Use the snapshot_lvm_verify option to make sure extend is done
Expand All @@ -90,8 +87,7 @@
vars:
snapshot_lvm_percent_space_required: 40
snapshot_lvm_all_vgs: true
snapshot_lvm_suffix: _z
snapshot_lvm_prefix: a_
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_verify_only: true
snapshot_lvm_action: extend
always:
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_include_vars_from_parent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
vars:
snapshot_lvm_action: check
snapshot_lvm_percent_space_required: 2
snapshot_lvm_prefix: a_
snapshot_lvm_suffix: _z
snapshot_lvm_snapset_name: snapset1
snapshot_lvm_all_vgs: true
tasks:
- name: Run test in a block to clean up in always
Expand Down
Loading

0 comments on commit b39b2ab

Please sign in to comment.