Skip to content

Commit a527ac0

Browse files
committed
fix: restore key-file reopening with older Blivet
The initial change to volume lookup assumed that LUKS.key_file was writable. Stock Stream 9 Blivet exposes only a getter, so assigning a key file raised AttributeError before the supplied key was tried. Set the backing field when the format has one, as the PR base did. Context-based formats keep using their public setter. Configure both the current and original format, and keep explicit activation unchanged. Exercise both credential representations in the reopening tests. Assisted-by: OpenCode using model GPT-6.2 Astra Signed-off-by: Bata Roland Krisztián <batarolandkrisztian@gmail.com>
1 parent 61cf4a5 commit a527ac0

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

‎library/blivet.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,11 +697,15 @@ def _look_up_device(self):
697697
return
698698

699699
if device.format.type == 'luks':
700-
# Assisted by OpenCode using model GPT-6.1 Sol
700+
# Assisted by OpenCode using models GPT-6.1 Sol, GPT-6.2 Astra
701701
# Keep both formats configured for subsequent action processing.
702702
for fmt in (device.format, device.original_format):
703703
if self._volume.get('encryption_key'):
704-
fmt.key_file = self._volume['encryption_key']
704+
if hasattr(fmt, '_key_file'):
705+
# Older Blivet exposes this field through a read-only property.
706+
fmt._key_file = self._volume['encryption_key']
707+
else:
708+
fmt.key_file = self._volume['encryption_key']
705709
if self._volume.get('encryption_password'):
706710
fmt.passphrase = self._volume['encryption_password']
707711
if device.isleaf:

‎tests/unit/test_luks_reopening.py‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: MIT
2-
# Assisted by OpenCode using model GPT-6.1 Sol
2+
# Assisted by OpenCode using models GPT-6.1 Sol, GPT-6.2 Astra
33
"""Existing mapping names and unrelated swap behavior survive LUKS inspection."""
44
from __future__ import absolute_import, division, print_function
55

@@ -35,10 +35,18 @@ def __init__(self, fmt_type='luks'):
3535
self.type = fmt_type
3636
self.map_name = 'luks-test-uuid'
3737
self.passphrase = None
38-
self.key_file = None
38+
self.context_key_file = None
3939
self.status = False
4040
self.setup_calls = 0
4141

42+
@property
43+
def key_file(self):
44+
return self.context_key_file
45+
46+
@key_file.setter
47+
def key_file(self, path):
48+
self.context_key_file = path
49+
4250
@property
4351
def has_key(self):
4452
return bool(self.passphrase or self.key_file)
@@ -50,6 +58,14 @@ def setup(self):
5058
self.status = True
5159

5260

61+
class LegacyLUKSFormat(FakeFormat):
62+
_key_file = None
63+
64+
@property
65+
def key_file(self):
66+
return self._key_file
67+
68+
5369
class FakeDevice(object):
5470
def __init__(self, path, fmt_type='luks', raw_device=None):
5571
self.path = path
@@ -119,6 +135,14 @@ def test_key_file_reopening_preserves_the_name(self):
119135
self.assertEqual(self.device.format.key_file, '/root/existing.key')
120136
self.assertEqual(self.device.original_format.key_file, '/root/existing.key')
121137

138+
def test_reopen_with_a_read_only_key_file_property(self):
139+
self.device.format = LegacyLUKSFormat()
140+
self.device.original_format = LegacyLUKSFormat()
141+
volume = self.lookup(encryption_password=None, encryption_key='/root/existing.key')
142+
self.assertEqual(volume._device.path, '/dev/mapper/custom')
143+
self.assertEqual(self.device.format.key_file, '/root/existing.key')
144+
self.assertEqual(self.device.original_format.key_file, '/root/existing.key')
145+
122146
def test_comments_blank_and_unrelated_entries(self):
123147
self.text = u'\n # ignored UUID=test-uuid\nmalformed\nother /dev/missing - luks\n'
124148
self.assertEqual(self.lookup()._device.path, '/dev/mapper/luks-test-uuid')

0 commit comments

Comments
 (0)