Skip to content

Commit

Permalink
fix #64082
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Phipps authored and s0undt3ch committed Apr 26, 2023
1 parent 47a5469 commit 196023a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/64082.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix dmsetup device names with hyphen being picked up.
2 changes: 1 addition & 1 deletion salt/modules/cryptdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def active():
ret = {}
# TODO: This command should be extended to collect more information, such as UUID.
devices = __salt__["cmd.run_stdout"]("dmsetup ls --target crypt")
out_regex = re.compile(r"(?P<devname>\w+)\W+\((?P<major>\d+), (?P<minor>\d+)\)")
out_regex = re.compile(r"(?P<devname>\S+)\s+\((?P<major>\d+), (?P<minor>\d+)\)")

log.debug(devices)
for line in devices.split("\n"):
Expand Down
38 changes: 38 additions & 0 deletions tests/pytests/unit/modules/test_cryptdev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest

import salt.modules.cryptdev as cryptdev
from tests.support.mock import MagicMock, patch


@pytest.fixture
def configure_loader_modules(minion_opts):
return {cryptdev: {"__opts__": minion_opts}}


def test_active(caplog):
with patch.dict(
cryptdev.__salt__,
{"cmd.run_stdout": MagicMock(return_value="my-device (253, 1)\n")},
):
assert cryptdev.active() == {
"my-device": {
"devname": "my-device",
"major": "253",
"minor": "1",
}
}

# debien output when no devices setup.
with patch.dict(cryptdev.__salt__, {"cmd.run_stdout": MagicMock(return_value="")}):
caplog.clear()
assert cryptdev.active() == {}
assert "dmsetup output does not match expected format" in caplog.text

# centos output of dmsetup when no devices setup.
with patch.dict(
cryptdev.__salt__,
{"cmd.run_stdout": MagicMock(return_value="No devices found")},
):
caplog.clear()
assert cryptdev.active() == {}
assert "dmsetup output does not match expected format" in caplog.text

0 comments on commit 196023a

Please sign in to comment.