Skip to content

Commit

Permalink
Add debug command to get filesystem metadata
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Jul 26, 2024
1 parent caadc10 commit b982a39
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/stratis_cli/_actions/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,46 @@ def get_object_path(namespace):
)
print(fs_object_path)

@staticmethod
def get_metadata(namespace):
"""
Get filesystem medatada. If a specific filesystem is not specified,
get metadata for all filesystems in the pool.
:raises StratisCliEngineError:
"""

# pylint: disable=import-outside-toplevel
from ._data import ObjectManager, Pool, pools

proxy = get_object(TOP_OBJECT)
managed_objects = ObjectManager.Methods.GetManagedObjects(proxy, {})

props = (
{"Uuid": namespace.uuid.hex}
if namespace.name is None
else {"Name": namespace.name}
)
(pool_object_path, _) = next(
pools(props=props).require_unique_match(True).search(managed_objects)
)

(metadata, return_code, message) = Pool.Methods.FilesystemMetadata(
get_object(pool_object_path), {}
)

if return_code != StratisdErrors.OK: # pragma: no cover
raise StratisCliEngineError(return_code, message)

json_format_data = [json.loads(chunk) for chunk in metadata.split("\n")]

if namespace.pretty:
for js in json_format_data:
print(json.dumps(js, sort_keys=True, indent=4))
else:
for js in json_format_data:
print(json.dumps(js))


class BlockdevDebugActions: # pylint: disable=too-few-public-methods
"""
Expand Down
39 changes: 39 additions & 0 deletions src/stratis_cli/_parser/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,45 @@
"func": FilesystemDebugActions.get_object_path,
},
),
(
"get-metadata",
{
"help": (
"Get the filesystem metadata for all filesystems belonging to "
"the specified pool"
),
"args": [
(
"--pretty",
{
"action": "store_true",
"help": "Format output string prettily",
},
),
],
"mut_ex_args": [
(
False,
[
(
"--name",
{
"help": "Name of pool",
},
),
(
"--uuid",
{
"help": "UUID of pool",
"type": UUID,
},
),
],
)
],
"func": FilesystemDebugActions.get_metadata,
},
),
]

BLOCKDEV_DEBUG_SUBCMDS = [
Expand Down
29 changes: 29 additions & 0 deletions tests/whitebox/integration/logical/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,32 @@ def test_lookup_name(self):
self._FSNAME,
]
TEST_RUNNER(command_line)

def test_metadata_name(self):
"""
Test getting filesystem metadata.
"""
command_line = ["filesystem", "create", self._POOLNAME, "newname"]
RUNNER(command_line)

command_line = self._MENU + [
"get-metadata",
"--name",
self._POOLNAME,
]
TEST_RUNNER(command_line)

def test_metadata_name_pretty(self):
"""
Test getting filesystem metadata and pretty printing it.
"""
command_line = ["filesystem", "create", self._POOLNAME, "newname"]
RUNNER(command_line)

command_line = self._MENU + [
"get-metadata",
"--pretty",
"--name",
self._POOLNAME,
]
TEST_RUNNER(command_line)

0 comments on commit b982a39

Please sign in to comment.