Skip to content

Commit

Permalink
Introduce 'has_key' property in the attrs of DeviceFormatData object
Browse files Browse the repository at this point in the history
This is especially useful to know if a LUKS device can be unlocked.
  • Loading branch information
KKoukiou committed Jul 11, 2023
1 parent e6332a9 commit bbd37f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pyanaconda/modules/common/structures/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ def attrs(self) -> Dict[Str, Str]:
Attributes for file systems:
mount-point
Attributes for LUKS:
has_key
:return: a dictionary of attributes
"""
return self._attrs
Expand Down
1 change: 1 addition & 0 deletions pyanaconda/modules/storage/devicetree/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def _get_format_data(self, fmt):
data.description = fmt.name or ""

# Collect the additional attributes.
data.attrs["has_key"] = self._get_attribute(fmt, "has_key")
data.attrs["uuid"] = self._get_attribute(fmt, "uuid")
data.attrs["label"] = self._get_attribute(fmt, "label")
data.attrs["mount-point"] = self._get_attribute(fmt, "mountpoint")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,12 @@ def test_unlock_device(self, device_setup, device_teardown, format_setup):

dev2 = LUKSDevice("dev2", parents=[dev1], fmt=get_format("luks"), size=Size("10 GiB"))
self._add_device(dev2)
assert self.interface.GetFormatData("dev2") == {
'type': get_variant(Str, 'luks'),
'mountable': get_variant(Bool, False),
'attrs': get_variant(Dict[Str, Str], { }),
'description': get_variant(Str, 'LUKS'),
}

assert self.interface.UnlockDevice("dev2", "passphrase") is True

Expand All @@ -688,6 +694,12 @@ def test_unlock_device(self, device_setup, device_teardown, format_setup):
self.storage.devicetree.populate.assert_called_once()
self.storage.devicetree.teardown_all.assert_called_once()
assert dev2.format.has_key
assert self.interface.GetFormatData("dev2") == {
'type': get_variant(Str, 'luks'),
'mountable': get_variant(Bool, False),
'attrs': get_variant(Dict[Str, Str], { "has_key": "True" }),
'description': get_variant(Str, 'LUKS'),
}

device_setup.side_effect = StorageError("Fake error")
assert self.interface.UnlockDevice("dev2", "passphrase") is False
Expand Down

0 comments on commit bbd37f6

Please sign in to comment.