Skip to content

Commit

Permalink
Run tests on both legacy and v2 pools
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran authored and jbaublitz committed Jul 15, 2024
1 parent 3dd59c4 commit 5d1003c
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 32 deletions.
17 changes: 14 additions & 3 deletions tests-fmf/python.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@ environment:
STRATISD: /usr/libexec/stratisd
STRATIS_DUMPMETADATA: /usr/bin/stratis-dumpmetadata
PYTHONPATH: ./src
LEGACY_POOL: /usr/local/bin/stratis-legacy-pool

/udev:
/legacy:
environment+:
LEGACY_POOL: /usr/local/bin/stratis-legacy-pool

/legacy/udev:
summary: Run Python udev tests
test: make -f Makefile udev-tests

/legacy/loop:
summary: Run Python tests that use loopbacked device framework
test: make -f Makefile tang-tests dump-metadata-tests

/v2/udev:
summary: Run Python udev tests
test: make -f Makefile udev-tests

/loop:
/v2/loop:
summary: Run Python tests that use loopbacked device framework
test: make -f Makefile tang-tests dump-metadata-tests
105 changes: 76 additions & 29 deletions tests/client-dbus/tests/udev/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

# isort: STDLIB
import json
import logging
import os
import random
Expand Down Expand Up @@ -50,7 +51,7 @@
from ._loopback import LoopBackDevices

_STRATISD = os.environ["STRATISD"]
_LEGACY_POOL = os.environ["LEGACY_POOL"]
_LEGACY_POOL = os.environ.get("LEGACY_POOL")

CRYPTO_LUKS_FS_TYPE = "crypto_LUKS"
STRATIS_FS_TYPE = "stratis"
Expand Down Expand Up @@ -80,40 +81,86 @@ def create_pool(
:rtype: bool * str * list of str
:raises RuntimeError: if pool is not created
"""
newly_created = False

if len(get_pools(name)) == 0:
cmdline = [_LEGACY_POOL, name] + devices
if key_description is not None:
cmdline.extend(["--key-desc", key_description])
if clevis_info is not None:
def create_legacy_pool():
newly_created = False

if len(get_pools(name)) == 0:
cmdline = [_LEGACY_POOL, name] + devices
if key_description is not None:
cmdline.extend(["--key-desc", key_description])
if clevis_info is not None:
(pin, (tang_url, thp)) = clevis_info
cmdline.extend(["--clevis", pin])
if pin == "tang":
cmdline.extend(["--tang-url", tang_url])
if thp is None:
cmdline.append("--trust-url")
else:
cmdline.extend(["--thumbprint", thp])

with subprocess.Popen(
cmdline,
text=True,
) as output:
output.wait()
if output.returncode != 0:
raise RuntimeError(
f"Unable to create a pool {name} with devices {devices}: {output.stderr}"
)

newly_created = True

i = 0
while get_pools(name) == [] and i < 5:
i += 1
time.sleep(1)
(pool_object_path, _) = next(iter(get_pools(name)))
bd_object_paths = [op for op, _ in get_blockdevs(pool_object_path)]

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
cmdline.extend(["--clevis", pin])
if pin == "tang":
cmdline.extend(["--tang-url", tang_url])
if thp is None:
cmdline.append("--trust-url")
else:
cmdline.extend(["--thumbprint", thp])

with subprocess.Popen(
cmdline,
text=True,
) as output:
output.wait()
if output.returncode != 0:
raise RuntimeError(
f"Unable to create a pool {name} with devices {devices}: {output.stderr}"
clevis_arg = (
"tang",
json.dumps(
{"url": tang_url, "stratis:tang:trust_url": True}
if thp is None
else {"url": tang_url, "thp": thp}
),
)
else:
clevis_arg = None

(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)
),
},
)

if exit_code != StratisdErrors.OK:
raise RuntimeError(
f"Unable to create a pool {name} with devices {devices}: {error_str}"
)

newly_created = True
return result

i = 0
while get_pools(name) == [] and i < 5:
i += 1
time.sleep(1)
(pool_object_path, _) = next(iter(get_pools(name)))
bd_object_paths = [op for op, _ in get_blockdevs(pool_object_path)]
(newly_created, (pool_object_path, bd_object_paths)) = (
create_v2_pool() if _LEGACY_POOL is None else create_legacy_pool()
)

if not overprovision:
Pool.Properties.Overprovisioning.Set(get_object(pool_object_path), False)
Expand Down

0 comments on commit 5d1003c

Please sign in to comment.