Skip to content

Commit

Permalink
Merge pull request #5784 from vojtechtrefny/master_luks-tests-fix
Browse files Browse the repository at this point in the history
LUKS support fixes in DeviceTreeSchedulerModule and tests
  • Loading branch information
vojtechtrefny authored Jul 30, 2024
2 parents c17ad0b + 3f6f159 commit 60d39b1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def is_device_locked(self, device_name):
:return: True or False
"""
device = self._get_device(device_name)
return device.format.type == "luks" and device.format.exists
return device.format.type == "luks" and device.format.exists and not device.children

def is_device_editable(self, device_name):
"""Is the specified device editable?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,16 +653,16 @@ def test_is_device_locked(self):
"""Test IsDeviceLocked."""
dev1 = StorageDevice(
"dev1",
fmt=get_format("ext4"),
fmt=get_format("luks"),
size=Size("10 GiB")
)
dev2 = LUKSDevice(
"dev2",
parents=[dev1],
fmt=get_format("luks"),
fmt=get_format("ext4"),
size=Size("10 GiB"),
)
dev3 = LUKSDevice(
dev3 = StorageDevice(
"dev3",
parents=[dev1],
fmt=get_format("luks", exists=True),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,8 @@ def test_get_format_data(self):
fmt2 = get_format(
"luks"
)
dev2 = LUKSDevice(
dev2 = StorageDevice(
"dev2",
parents=[dev1],
fmt=fmt2,
size=Size("10 GiB")
)
Expand Down Expand Up @@ -786,35 +785,25 @@ def test_find_mountable_partitions(self, update_size_info):
assert self.interface.FindMountablePartitions() == ["dev2"]

@patch.object(LUKS, "setup")
@patch.object(LUKSDevice, "teardown")
@patch.object(LUKSDevice, "setup")
@patch.object(StorageDevice, "teardown")
@patch.object(StorageDevice, "setup")
def test_unlock_device(self, device_setup, device_teardown, format_setup):
"""Test UnlockDevice."""
self.storage.devicetree.populate = Mock()
self.storage.devicetree.teardown_all = Mock()

dev1 = StorageDevice("dev1", fmt=get_format("ext4"), size=Size("10 GiB"))
dev1 = StorageDevice("dev1", fmt=get_format("luks"), size=Size("10 GiB"), exists=True)
self._add_device(dev1)

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),
'formattable': get_variant(Bool, True),
'attrs': get_variant(Dict[Str, Str], {'has_key': 'False'}),
'description': get_variant(Str, 'LUKS'),
}

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

device_setup.assert_called_once()
format_setup.assert_called_once()
device_teardown.assert_not_called()
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") == {
assert dev1.format.has_key
assert self.interface.GetFormatData("dev1") == {
'type': get_variant(Str, 'luks'),
'mountable': get_variant(Bool, False),
'formattable': get_variant(Bool, True),
Expand All @@ -823,35 +812,36 @@ def test_unlock_device(self, device_setup, device_teardown, format_setup):
}

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

device_teardown.assert_called_once()
assert not dev2.format.has_key
assert not dev1.format.has_key

def test_find_unconfigured_luks(self):
"""Test FindUnconfiguredLUKS."""
assert self.interface.FindUnconfiguredLUKS() == []

dev1 = StorageDevice("dev1", fmt=get_format("ext4"), size=Size("10 GiB"))
dev1 = StorageDevice("dev1", fmt=get_format("luks"), size=Size("10 GiB"))
self._add_device(dev1)

assert self.interface.FindUnconfiguredLUKS() == []
assert self.interface.FindUnconfiguredLUKS() == ["dev1"]

dev2 = LUKSDevice("dev2", parents=[dev1], fmt=get_format("luks"), size=Size("10 GiB"))
dev2 = LUKSDevice("dev2", parents=[dev1], fmt=get_format("ext4"), size=Size("10 GiB"))
self._add_device(dev2)
dev1.format.passphrase = "123456"

assert self.interface.FindUnconfiguredLUKS() == ["dev2"]
assert self.interface.FindUnconfiguredLUKS() == []

def test_set_device_passphrase(self):
"""Test SetDevicePassphrase."""
dev1 = StorageDevice("dev1", fmt=get_format("ext4"), size=Size("10 GiB"))
dev1 = StorageDevice("dev1", fmt=get_format("luks"), size=Size("10 GiB"))
self._add_device(dev1)

dev2 = LUKSDevice("dev2", parents=[dev1], fmt=get_format("luks"), size=Size("10 GiB"))
dev2 = LUKSDevice("dev2", parents=[dev1], fmt=get_format("ext4"), size=Size("10 GiB"))
self._add_device(dev2)

assert self.interface.FindUnconfiguredLUKS() == ["dev2"]
self.interface.SetDevicePassphrase("dev2", "123456")
assert self.interface.FindUnconfiguredLUKS() == ["dev1"]
self.interface.SetDevicePassphrase("dev1", "123456")
assert self.interface.FindUnconfiguredLUKS() == []

def test_get_fstab_spec(self):
Expand Down

0 comments on commit 60d39b1

Please sign in to comment.