Skip to content

Commit

Permalink
Fix Python tests for r8
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Jan 29, 2025
1 parent 476b482 commit 1df99e9
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 92 deletions.
57 changes: 40 additions & 17 deletions tests/client-dbus/tests/udev/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ def create_pool(
Creates a stratis pool.
:param name: Name of pool
:param devices: Devices to use for pool
:param key_description: optional key description
:type key_description: str or NoneType
:param key_description: optional key descriptions and token slots
:type key_description: list of tuples
:param clevis_info: clevis information, pin and config
:type clevis_info: pair of str * (bool, str)
:type clevis_info: list of tuples
:return: result of pool create if operation succeeds
:rtype: bool * str * list of str
:raises RuntimeError: if pool is not created
Expand All @@ -98,9 +98,18 @@ def create_legacy_pool():
if len(get_pools(name)) == 0:
cmdline = [_LEGACY_POOL, name] + devices
if key_description is not None:
cmdline.extend(["--key-desc", key_description])
if len(key_description) > 1:
raise RuntimeError(
"Can only provide one key description to legacy pools"
)
(kd, _) = key_description[0]
cmdline.extend(["--key-desc", kd])
if clevis_info is not None:
(pin, (tang_url, thp)) = clevis_info
if len(clevis_info) > 1:
raise RuntimeError(
"Can only provide one Clevis info to legacy pools"
)
(pin, (tang_url, thp), _) = clevis_info[0]
cmdline.extend(["--clevis", pin])
if pin == "tang":
cmdline.extend(["--tang-url", tang_url])
Expand Down Expand Up @@ -131,12 +140,26 @@ def create_legacy_pool():
return (newly_created, (pool_object_path, bd_object_paths))

def create_v2_pool():
if clevis_info is None:
clevis_arg = None
else:
(pin, (tang_url, thp)) = clevis_info
dbus_key_descriptions = []
for kd, slot in key_description if key_description is not None else []:
if slot is None:
dbus_slot = (False, 0)
else:
dbus_slot = (True, slot)

dbus_key_descriptions.append((dbus_slot, kd))

dbus_clevis_infos = []
for pin, (tang_url, thp), slot in (
clevis_info if clevis_info is not None else []
):
if slot is None:
dbus_slot = (False, 0)
else:
dbus_slot = (True, slot)

if pin == "tang":
clevis_arg = (
(pin, config) = (
"tang",
json.dumps(
{"url": tang_url, "stratis:tang:trust_url": True}
Expand All @@ -145,19 +168,19 @@ def create_v2_pool():
),
)
else:
clevis_arg = None
raise RuntimeError(
"Currently only Tang is supported for Clevis in the test infrastructure"
)

dbus_clevis_infos.append((dbus_slot, pin, config))

(result, exit_code, error_str) = Manager.Methods.CreatePool(
get_object(TOP_OBJECT),
{
"name": name,
"devices": devices,
"key_desc": (
(False, "") if key_description is None else (True, key_description)
),
"clevis_info": (
(False, ("", "")) if clevis_arg is None else (True, clevis_arg)
),
"key_desc": dbus_key_descriptions,
"clevis_info": dbus_clevis_infos,
"journal_size": (False, 0),
"tag_spec": (False, ""),
"allocate_superblock": (False, False),
Expand Down
42 changes: 30 additions & 12 deletions tests/client-dbus/tests/udev/test_bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ def test_binding_and_adding(self):
with OptionalKeyServiceContextManager(key_spec=[(key_description, key)]):
pool_name = random_string(5)
(_, (pool_object_path, _)) = create_pool(
pool_name, initial_devnodes, key_description=key_description
pool_name, initial_devnodes, key_description=[(key_description, None)]
)
self.wait_for_pools(1)

(_, exit_code, message) = Pool.Methods.BindClevis(
get_object(pool_object_path),
{"pin": "tang", "json": self._CLEVIS_CONFIG_STR},
{
"pin": "tang",
"json": self._CLEVIS_CONFIG_STR,
"token_slot": (False, 0),
},
)

self.assertEqual(exit_code, StratisdErrors.OK, message)
Expand All @@ -88,13 +92,17 @@ def test_binding_unbinding_adding(self):
with OptionalKeyServiceContextManager(key_spec=[(key_description, key)]):
pool_name = random_string(5)
(_, (pool_object_path, _)) = create_pool(
pool_name, initial_devnodes, key_description=key_description
pool_name, initial_devnodes, key_description=[(key_description, None)]
)
self.wait_for_pools(1)

(_, exit_code, message) = Pool.Methods.BindClevis(
get_object(pool_object_path),
{"pin": "tang", "json": self._CLEVIS_CONFIG_STR},
{
"pin": "tang",
"json": self._CLEVIS_CONFIG_STR,
"token_slot": (False, 0),
},
)

self.assertEqual(exit_code, StratisdErrors.OK, message)
Expand Down Expand Up @@ -126,13 +134,17 @@ def test_swap_binding(self):
with OptionalKeyServiceContextManager(key_spec=[(key_description, key)]):
pool_name = random_string(5)
(_, (pool_object_path, _)) = create_pool(
pool_name, initial_devnodes, key_description=key_description
pool_name, initial_devnodes, key_description=[(key_description, None)]
)
self.wait_for_pools(1)

(_, exit_code, message) = Pool.Methods.BindClevis(
get_object(pool_object_path),
{"pin": "tang", "json": self._CLEVIS_CONFIG_STR},
{
"pin": "tang",
"json": self._CLEVIS_CONFIG_STR,
"token_slot": (False, 0),
},
)

self.assertEqual(exit_code, StratisdErrors.OK, message)
Expand Down Expand Up @@ -164,12 +176,15 @@ def test_swap_binding_2(self):
with OptionalKeyServiceContextManager(key_spec=[(key_description, key)]):
pool_name = random_string(5)
(_, (pool_object_path, _)) = create_pool(
pool_name, initial_devnodes, clevis_info=("tang", (_TANG_URL, None))
pool_name,
initial_devnodes,
clevis_info=[("tang", (_TANG_URL, None), None)],
)
self.wait_for_pools(1)

(_, exit_code, message) = Pool.Methods.BindKeyring(
get_object(pool_object_path), {"key_desc": key_description}
get_object(pool_object_path),
{"key_desc": key_description, "token_slot": (False, 0)},
)

self.assertEqual(exit_code, StratisdErrors.OK, message)
Expand Down Expand Up @@ -201,12 +216,14 @@ def test_rebind_with_clevis(self):
pool_name = random_string(5)

(_, (pool_object_path, _)) = create_pool(
pool_name, initial_devnodes, clevis_info=("tang", (_TANG_URL, None))
pool_name,
initial_devnodes,
clevis_info=[("tang", (_TANG_URL, None), None)],
)
self.wait_for_pools(1)

(_, exit_code, message) = Pool.Methods.RebindClevis(
get_object(pool_object_path), {}
get_object(pool_object_path), {"token_slot": (False, 0)}
)

self.assertEqual(exit_code, StratisdErrors.OK, message)
Expand Down Expand Up @@ -239,12 +256,13 @@ def test_rebind_with_new_key_description(self):
with OptionalKeyServiceContextManager(key_spec=keys):
pool_name = random_string(5)
(_, (pool_object_path, _)) = create_pool(
pool_name, initial_devnodes, key_description=keys[0][0]
pool_name, initial_devnodes, key_description=[(keys[0][0], None)]
)
self.wait_for_pools(1)

(_, exit_code, message) = Pool.Methods.RebindKeyring(
get_object(pool_object_path), {"key_desc": keys[1][0]}
get_object(pool_object_path),
{"key_desc": keys[1][0], "token_slot": (False, 0)},
)

self.assertEqual(exit_code, StratisdErrors.OK, message)
Expand Down
2 changes: 1 addition & 1 deletion tests/client-dbus/tests/udev/test_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def test_prediction_encrypted(self):
(key_description, key) = ("key_spec", "data")
with OptionalKeyServiceContextManager(key_spec=[(key_description, key)]):
pool_name = random_string(5)
create_pool(pool_name, devnodes, key_description=key_description)
create_pool(pool_name, devnodes, key_description=[(key_description, None)])
self.wait_for_pools(1)
self._test_prediction(pool_name)

Expand Down
4 changes: 2 additions & 2 deletions tests/client-dbus/tests/udev/test_revert.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_revert(self): # pylint: disable=too-many-locals
{
"id": pool_name,
"id_type": "name",
"unlock_method": (False, ""),
"unlock_method": (False, (False, 0)),
"key_fd": (False, 0),
},
)
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_revert_snapshot_chain(self): # pylint: disable=too-many-locals
{
"id": pool_name,
"id_type": "name",
"unlock_method": (False, ""),
"unlock_method": (False, (False, 0)),
"key_fd": (False, 0),
},
)
Expand Down
Loading

0 comments on commit 1df99e9

Please sign in to comment.