Skip to content

Make the "host" parameter mandatory in "host add" and "host del" CLI commands #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions control/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,8 @@ def host_add(self, args):
"""Add a host to a subsystem."""

out_func, err_func = self.get_output_functions(args)
if not args.host:
self.cli.parser.error("--host argument is mandatory for add command")
req = pb2.add_host_req(subsystem_nqn=args.subsystem, host_nqn=args.host)
try:
ret = self.stub.add_host(req)
Expand Down Expand Up @@ -975,6 +977,8 @@ def host_del(self, args):
"""Delete a host from a subsystem."""

out_func, err_func = self.get_output_functions(args)
if not args.host:
self.cli.parser.error("--host argument is mandatory for del command")
req = pb2.remove_host_req(subsystem_nqn=args.subsystem, host_nqn=args.host)

try:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,15 @@ def test_namespace_io_stats(self, caplog, gateway):

@pytest.mark.parametrize("host", host_list)
def test_add_host(self, caplog, host):
caplog.clear()
rc = 0
try:
cli(["host", "add", "--subsystem", subsystem])
except SystemExit as sysex:
rc = int(str(sysex))
pass
assert "error: --host argument is mandatory for add command" in caplog.text
assert rc == 2
caplog.clear()
cli(["host", "add", "--subsystem", subsystem, "--host", host])
if host == "*":
Expand Down Expand Up @@ -499,6 +508,15 @@ def test_create_listener_on_discovery(self, caplog, listener, gateway):
class TestDelete:
@pytest.mark.parametrize("host", host_list)
def test_remove_host(self, caplog, host, gateway):
caplog.clear()
rc = 0
try:
cli(["host", "del", "--subsystem", subsystem])
except SystemExit as sysex:
rc = int(str(sysex))
pass
assert "error: --host argument is mandatory for del command" in caplog.text
assert rc == 2
caplog.clear()
cli(["host", "del", "--subsystem", subsystem, "--host", host])
if host == "*":
Expand Down