Skip to content

Commit

Permalink
Return error for invalid filesystem selection
Browse files Browse the repository at this point in the history
When using --uuid/--name option to specify a filesystem, the pool name
is required, otherwise the --name option might not select a unique
filesystem.

Return the error in the action code because the argparse library
does not have faciliites to do this checking.

Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Jan 17, 2024
1 parent cb989aa commit 1085716
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/stratis_cli/_actions/_logical.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
StratisCliEngineError,
StratisCliFsSizeLimitChangeError,
StratisCliIncoherenceError,
StratisCliMissingPoolNameError,
StratisCliNoChangeError,
StratisCliPartialChangeError,
)
Expand Down Expand Up @@ -125,7 +126,8 @@ def list_volumes(namespace):
getattr(namespace, "name", None),
)

assert (fs_name is None and fs_uuid is None) or pool_name is not None
if not (fs_name is None and fs_uuid is None) and pool_name is None:
raise StratisCliMissingPoolNameError()

uuid_formatter = get_uuid_formatter(namespace.unhyphenated_uuids)

Expand Down
13 changes: 13 additions & 0 deletions src/stratis_cli/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,19 @@ def __str__(self):
)


class StratisCliMissingPoolNameError(StratisCliParserError):
"""
Raised during filesystem listing if the user specified filesystem name or
UUID but failed to specify a pool name.
"""

def __str__(self):
return (
"A value for the pool name must be supplied when "
"specifying the UUID or name of the filesystem"
)


class StratisCliIncoherenceError(StratisCliRuntimeError):
"""
Raised if there was a disagreement about state between the CLI
Expand Down
9 changes: 9 additions & 0 deletions tests/whitebox/integration/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,12 @@ def test_create_with_clevis_2(self):
"/dev/n",
]
self.check_error(StratisCliMissingClevisThumbprintError, command_line, 1)

def test_stratis_list_filesystem_with_name_no_pool(self):
"""
We want to get a parse error if filesystem UUID is specified but no
name.
"""
command_line = ["filesystem", "list", "--name=bogus"]
for prefix in [[], ["--propagate"]]:
self.check_system_exit(prefix + command_line, _PARSE_ERROR)

0 comments on commit 1085716

Please sign in to comment.