Skip to content

Commit 922d899

Browse files
committed
force lvm signature wipe when requested
1 parent fd89df5 commit 922d899

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/automax/plugins/lvm.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ def manual_commands(self, params: Dict[str, Any], context: ExecutionContext) ->
106106
size = quote(params["size"])
107107
lv_path = quote(self._lv_path(params))
108108
sudo = _sudo(params)
109-
commands = [f"{sudo}lvs --noheadings {lv_path} >/dev/null 2>&1 || {sudo}lvcreate -n {name} -L {size} {vg}"]
109+
create_force = " -y --wipesignatures y" if bool(params.get("force", False)) else ""
110+
commands = [
111+
f"{sudo}lvs --noheadings {lv_path} >/dev/null 2>&1 "
112+
f"|| {sudo}lvcreate{create_force} -n {name} -L {size} {vg}"
113+
]
110114
if params.get("fstype"):
111115
force = " -f" if bool(params.get("force", False)) else ""
112116
commands.append(f"{sudo}blkid {lv_path} >/dev/null 2>&1 || {sudo}mkfs.{quote(params['fstype'])}{force} {lv_path}")

tests/test_next_engine.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,6 +3438,11 @@ def test_lvm_plugins_render_manual_commands_and_previews():
34383438
assert "vgdisplay" not in " && ".join(vg_commands)
34393439
lv = LvmLvPresentPlugin().manual_commands({"vg": "vg_app", "name": "data", "size": "10G", "resizefs": True}, context)
34403440
assert any("lvcreate" in command for command in lv)
3441+
assert "--wipesignatures" not in lv[0]
3442+
forced_lv = LvmLvPresentPlugin().manual_commands(
3443+
{"vg": "vg_app", "name": "data", "size": "10G", "force": True}, context
3444+
)
3445+
assert "lvcreate -y --wipesignatures y" in forced_lv[0]
34413446
assert "lvextend -r" in LvmLvExtendPlugin().manual_commands({"vg": "vg_app", "name": "data", "size": "20G"}, context)[0]
34423447
assert "resize2fs" in LvmResizeFsPlugin().manual_commands({"device": "/dev/vg_app/data", "fstype": "ext4"}, context)[0]
34433448
assert LvmLvPresentPlugin().diff_preview({"vg": "vg_app", "name": "data", "size": "10G"}, context)[0]["kind"] == "lvm-plan"

0 commit comments

Comments
 (0)