Fix parsing of lsblk output. (#410)
parent
2f2c8b57e8
commit
0d4b3ed991
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "luks_device - fix parsing of ``lsblk`` output when device name ends with ``crypt`` (https://github.com/ansible-collections/community.crypto/issues/409, https://github.com/ansible-collections/community.crypto/pull/410)."
|
|
@ -350,7 +350,7 @@ STDERR = 2
|
||||||
|
|
||||||
# used to get <luks-name> out of lsblk output in format 'crypt <luks-name>'
|
# used to get <luks-name> out of lsblk output in format 'crypt <luks-name>'
|
||||||
# regex takes care of any possible blank characters
|
# regex takes care of any possible blank characters
|
||||||
LUKS_NAME_REGEX = re.compile(r'\s*crypt\s+([^\s]*)\s*')
|
LUKS_NAME_REGEX = re.compile(r'^crypt\s+([^\s]*)\s*$')
|
||||||
# used to get </luks/device> out of lsblk output
|
# used to get </luks/device> out of lsblk output
|
||||||
# in format 'device: </luks/device>'
|
# in format 'device: </luks/device>'
|
||||||
LUKS_DEVICE_REGEX = re.compile(r'\s*device:\s+([^\s]*)\s*')
|
LUKS_DEVICE_REGEX = re.compile(r'\s*device:\s+([^\s]*)\s*')
|
||||||
|
@ -446,13 +446,11 @@ class CryptHandler(Handler):
|
||||||
raise ValueError('Error while obtaining LUKS name for %s: %s'
|
raise ValueError('Error while obtaining LUKS name for %s: %s'
|
||||||
% (device, result[STDERR]))
|
% (device, result[STDERR]))
|
||||||
|
|
||||||
m = LUKS_NAME_REGEX.search(result[STDOUT])
|
for line in result[STDOUT].splitlines(False):
|
||||||
|
m = LUKS_NAME_REGEX.match(line)
|
||||||
try:
|
if m:
|
||||||
name = m.group(1)
|
return m.group(1)
|
||||||
except AttributeError:
|
return None
|
||||||
name = None
|
|
||||||
return name
|
|
||||||
|
|
||||||
def get_container_device_by_name(self, name):
|
def get_container_device_by_name(self, name):
|
||||||
''' obtain device name based on the LUKS container name
|
''' obtain device name based on the LUKS container name
|
||||||
|
|
Loading…
Reference in New Issue