From 0fb96f2a61923691d160d4756e5b1dff56a3d792 Mon Sep 17 00:00:00 2001 From: Todd Gill Date: Tue, 11 Jun 2024 11:33:56 -0400 Subject: [PATCH] fix: correct calls to lvm_is_snapshot it returns rc, is_snapshot and should not be called as a boolean function. Signed-off-by: Todd Gill --- library/snapshot.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/library/snapshot.py b/library/snapshot.py index 36b5a7a..3e99522 100644 --- a/library/snapshot.py +++ b/library/snapshot.py @@ -798,7 +798,13 @@ def revert_lv(vg_name, snapshot_name, check_mode): raise LvmBug("'lvs' failed '%d'" % rc) if lv_exists: - if not lvm_is_snapshot(vg_name, snapshot_name): + rc, is_snapshot = lvm_is_snapshot(vg_name, snapshot_name) + if rc != SnapshotStatus.SNAPSHOT_OK: + return ( + SnapshotStatus.ERROR_VERIFY_COMMAND_FAILED, + "revert_lv: command failed for LV lvm_is_snapshot()", + ) + if not is_snapshot: return ( SnapshotStatus.ERROR_REVERT_FAILED, "LV with name: " + vg_name + "/" + snapshot_name + " is not a snapshot", @@ -829,7 +835,14 @@ def extend_lv_snapshot(vg_name, lv_name, suffix, percent_space_required, check_m changed = False if lv_exists: - if not lvm_is_snapshot(vg_name, snapshot_name): + rc, is_snapshot = lvm_is_snapshot(vg_name, snapshot_name) + if rc != SnapshotStatus.SNAPSHOT_OK: + return ( + SnapshotStatus.ERROR_VERIFY_COMMAND_FAILED, + "extend_lv_snapshot: command failed for LV lvm_is_snapshot()", + changed, + ) + if not is_snapshot: return ( SnapshotStatus.ERROR_EXTEND_NOT_SNAPSHOT, "LV with name: " + vg_name + "/" + snapshot_name + " is not a snapshot", @@ -970,7 +983,13 @@ def snapshot_lv(vg_name, lv_name, suffix, snap_size, check_mode): rc, _vg_exists, lv_exists = lvm_lv_exists(vg_name, snapshot_name) if lv_exists: - if lvm_is_snapshot(vg_name, snapshot_name): + rc, is_snapshot = lvm_is_snapshot(vg_name, snapshot_name) + if rc != SnapshotStatus.SNAPSHOT_OK: + return ( + SnapshotStatus.ERROR_VERIFY_COMMAND_FAILED, + "snapshot_lv: command failed for LV lvm_is_snapshot()", + ) + if is_snapshot: return ( SnapshotStatus.ERROR_ALREADY_EXISTS, "Snapshot of :" + vg_name + "/" + lv_name + " already exists",