Skip to content

Commit 8a2a786

Browse files
authored
Merge pull request ceph#57925 from guits/cv-fix-version-checking
ceph-volume: fix set_dmcrypt_no_workqueue()
2 parents 335aa61 + dc28b77 commit 8a2a786

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

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

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import base64
22
import os
33
import logging
4+
import re
45
from ceph_volume import process, conf, terminal
56
from ceph_volume.util import constants, system
67
from ceph_volume.util.device import Device
@@ -12,14 +13,49 @@
1213
mlogger = terminal.MultiLogger(__name__)
1314

1415
def set_dmcrypt_no_workqueue(target_version: str = '2.3.4') -> None:
15-
"""
16-
set `conf.dmcrypt_no_workqueue` to `True` if the available
17-
version of `cryptsetup` is greater or equal to `version`
16+
"""Set `conf.dmcrypt_no_workqueue` to `True` if the installed version
17+
of `cryptsetup` is greater than or equal to the specified `target_version`.
18+
19+
Depending on the crypsetup version, `cryptsetup --version` output can be different.
20+
Eg:
21+
22+
CentOS Stream9:
23+
$ cryptsetup --version
24+
cryptsetup 2.6.0 flags: UDEV BLKID KEYRING FIPS KERNEL_CAPI PWQUALITY
25+
26+
CentOS Stream8:
27+
$ cryptsetup --version
28+
cryptsetup 2.3.7
29+
30+
Args:
31+
target_version (str, optional): The minimum version required for setting
32+
`conf.dmcrypt_no_workqueue` to `True`. Defaults to '2.3.4'.
33+
34+
Raises:
35+
RuntimeError: If failed to retrieve the cryptsetup version.
36+
RuntimeError: If failed to parse the cryptsetup version.
37+
RuntimeError: If failed to compare the cryptsetup version with the target version.
1838
"""
1939
command = ["cryptsetup", "--version"]
2040
out, err, rc = process.call(command)
41+
42+
# This regex extracts the version number from
43+
# the `cryptsetup --version` output
44+
pattern: str = r'\b\d+(\.\d+)*\b'
45+
46+
if rc:
47+
raise RuntimeError(f"Can't retrieve cryptsetup version: {err}")
48+
2149
try:
22-
if version.parse(out[0]) >= version.parse(f'cryptsetup {target_version}'):
50+
cryptsetup_version = re.match(pattern, out[0])
51+
52+
if cryptsetup_version is None:
53+
_output: str = "\n".join(out)
54+
raise RuntimeError('Error while checking cryptsetup version.\n',
55+
'`cryptsetup --version` output:\n',
56+
f'{_output}')
57+
58+
if version.parse(cryptsetup_version.group(0)) >= version.parse(target_version):
2359
conf.dmcrypt_no_workqueue = True
2460
except IndexError:
2561
mlogger.debug(f'cryptsetup version check: rc={rc} out={out} err={err}')

0 commit comments

Comments
 (0)