Skip to content

Commit

Permalink
Show acual NQN in CLI when adding a subsystem.
Browse files Browse the repository at this point in the history
Fixes #854

Signed-off-by: Gil Bregman <gbregman@il.ibm.com>
  • Loading branch information
gbregman committed Sep 8, 2024
1 parent 545a89a commit 1f1594e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion control/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,19 @@ def subsystem_add(self, args):
except Exception as ex:
ret = pb2.req_status(status = errno.EINVAL, error_message = f"Failure adding subsystem {args.subsystem}:\n{ex}")

new_nqn = args.subsystem
if not args.no_group_append:
try:
gw_info = self.gw_get_info()
if gw_info.status == 0:
group_name = gw_info.group.replace("_", "-")
new_nqn += f".{group_name}"
except Exception as ex:
pass

if args.format == "text" or args.format == "plain":
if ret.status == 0:
out_func(f"Adding subsystem {args.subsystem}: Successful")
out_func(f"Adding subsystem {new_nqn}: Successful")
else:
err_func(f"{ret.error_message}")
elif args.format == "json" or args.format == "yaml":
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,7 @@ class TestSubsysWithGroupName:
def test_create_subsys_group_name(self, caplog, gateway):
caplog.clear()
cli(["subsystem", "add", "--subsystem", subsystem3])
assert f"Adding subsystem {subsystem3}.{group_name}: Successful" in caplog.text
assert f"Subsystem NQN was changed to {subsystem3}.{group_name}, adding the group name" in caplog.text
assert f"create_subsystem {subsystem3}.{group_name}: True" in caplog.text
assert f"create_subsystem {subsystem3}: True" not in caplog.text
Expand All @@ -980,6 +981,7 @@ def test_create_subsys_group_name(self, caplog, gateway):
assert f'"nqn": "{subsystem3}"' not in caplog.text
caplog.clear()
cli(["subsystem", "add", "--subsystem", subsystem4, "--no-group-append"])
assert f"Adding subsystem {subsystem4}: Successful" in caplog.text
assert f"Subsystem NQN will not be changed" in caplog.text
assert f"create_subsystem {subsystem4}.{group_name}: True" not in caplog.text
assert f"create_subsystem {subsystem4}: True" in caplog.text
Expand Down

0 comments on commit 1f1594e

Please sign in to comment.