Skip to content

Commit 607eb34

Browse files
committed
ceph-volume: fix regex usage in set_dmcrypt_no_workqueue
- Updated the regex pattern to `r'(\d+\.?)+'` to more accurately capture version numbers. - Replaced `re.match` with `re.search` to properly match the cryptsetup version in the output. - `re.match` only checks for a match at the beginning of the string, while `re.search` looks for a match anywhere in the string. This fix ensures that the function correctly retrieves the cryptsetup version from the output. Fixes: https://tracker.ceph.com/issues/66393 Signed-off-by: Guillaume Abrioux <[email protected]>
1 parent 73b599d commit 607eb34

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/ceph-volume/ceph_volume/tests/util/test_encryption.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
11
from ceph_volume.util import encryption
2-
from mock.mock import patch
2+
from mock.mock import patch, Mock
33
import base64
4+
import pytest
5+
6+
7+
class TestNoWorkqueue:
8+
def setup_method(self):
9+
encryption.conf.dmcrypt_no_workqueue = None
10+
11+
@patch('ceph_volume.util.encryption.process.call',
12+
Mock(return_value=(['cryptsetup 2.7.2 flags: UDEV BLKID KEYRING' \
13+
'FIPS KERNEL_CAPI PWQUALITY '], [''], 0)))
14+
def test_set_dmcrypt_no_workqueue_true(self):
15+
encryption.set_dmcrypt_no_workqueue()
16+
assert encryption.conf.dmcrypt_no_workqueue
17+
18+
@patch('ceph_volume.util.encryption.process.call',
19+
Mock(return_value=(['cryptsetup 2.0.0'], [''], 0)))
20+
def test_set_dmcrypt_no_workqueue_false(self):
21+
encryption.set_dmcrypt_no_workqueue()
22+
assert encryption.conf.dmcrypt_no_workqueue is None
23+
24+
@patch('ceph_volume.util.encryption.process.call',
25+
Mock(return_value=([''], ['fake error'], 1)))
26+
def test_set_dmcrypt_no_workqueue_cryptsetup_version_fails(self):
27+
with pytest.raises(RuntimeError):
28+
encryption.set_dmcrypt_no_workqueue()
29+
30+
@patch('ceph_volume.util.encryption.process.call',
31+
Mock(return_value=(['unexpected output'], [''], 0)))
32+
def test_set_dmcrypt_no_workqueue_pattern_not_found(self):
33+
with pytest.raises(RuntimeError):
34+
encryption.set_dmcrypt_no_workqueue()
35+
36+
@patch('ceph_volume.util.encryption.process.call',
37+
Mock(return_value=([], [''], 0)))
38+
def test_set_dmcrypt_no_workqueue_index_error(self):
39+
with pytest.raises(RuntimeError):
40+
encryption.set_dmcrypt_no_workqueue()
41+
442

543
class TestGetKeySize(object):
644
def test_get_size_from_conf_default(self, conf_ceph_stub):

src/ceph-volume/ceph_volume/util/encryption.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ def set_dmcrypt_no_workqueue(target_version: str = '2.3.4') -> None:
4141

4242
# This regex extracts the version number from
4343
# the `cryptsetup --version` output
44-
pattern: str = r'\b\d+(\.\d+)*\b'
44+
pattern: str = r'(\d+\.?)+'
4545

4646
if rc:
4747
raise RuntimeError(f"Can't retrieve cryptsetup version: {err}")
4848

4949
try:
50-
cryptsetup_version = re.match(pattern, out[0])
50+
cryptsetup_version = re.search(pattern, out[0])
5151

5252
if cryptsetup_version is None:
5353
_output: str = "\n".join(out)

0 commit comments

Comments
 (0)