From 09a9130ed249c9721fea24a266f0153503554ee1 Mon Sep 17 00:00:00 2001 From: Pawel Kaminski Date: Tue, 9 Oct 2018 14:00:56 -0400 Subject: [PATCH] test/spdkcli: Add load and save config commands. Change-Id: I499f54b025080ad1916acc0cf265a58c806da002 Signed-off-by: Pawel Kaminski Reviewed-on: https://review.gerrithub.io/428494 Reviewed-by: Pawel Wodkowski Reviewed-by: Jim Harris Reviewed-by: Paul Luse Reviewed-by: Ben Walker Chandler-Test-Pool: SPDK Automated Test System Tested-by: SPDK CI Jenkins --- scripts/rpc.py | 8 ++++++-- scripts/rpc/__init__.py | 28 +++++++++++++++------------- scripts/spdkcli/ui_root.py | 16 ++++++++++++++++ test/spdkcli/vhost.sh | 27 ++++++++++++++++++++++++++- 4 files changed, 63 insertions(+), 16 deletions(-) diff --git a/scripts/rpc.py b/scripts/rpc.py index 10772a0cc..a8114575d 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -4,6 +4,7 @@ from rpc.client import print_dict, JSONRPCException import argparse import rpc +import sys try: from shlex import quote @@ -59,6 +60,7 @@ if __name__ == "__main__": @call_cmd def save_config(args): rpc.save_config(args.client, + sys.stdout, indent=args.indent) p = subparsers.add_parser('save_config', help="""Write current (live) configuration of SPDK subsystems and targets to stdout. @@ -69,7 +71,7 @@ if __name__ == "__main__": @call_cmd def load_config(args): - rpc.load_config(args.client) + rpc.load_config(args.client, sys.stdin) p = subparsers.add_parser('load_config', help="""Configure SPDK subsystems and targets using JSON RPC read from stdin.""") p.set_defaults(func=load_config) @@ -77,6 +79,7 @@ if __name__ == "__main__": @call_cmd def save_subsystem_config(args): rpc.save_subsystem_config(args.client, + sys.stdout, indent=args.indent, name=args.name) @@ -89,7 +92,8 @@ if __name__ == "__main__": @call_cmd def load_subsystem_config(args): - rpc.load_subsystem_config(args.client) + rpc.load_subsystem_config(args.client, + sys.stdin) p = subparsers.add_parser('load_subsystem_config', help="""Configure SPDK subsystem using JSON RPC read from stdin.""") p.set_defaults(func=load_subsystem_config) diff --git a/scripts/rpc/__init__.py b/scripts/rpc/__init__.py index b663005f9..8e8dc1dd1 100644 --- a/scripts/rpc/__init__.py +++ b/scripts/rpc/__init__.py @@ -34,18 +34,19 @@ def get_rpc_methods(client, current=None): return client.call('get_rpc_methods', params) -def _json_dump(config, indent): +def _json_dump(config, fd, indent): if indent is None: indent = 2 elif indent < 0: indent = None - json.dump(config, sys.stdout, indent=indent) - sys.stdout.write('\n') + json.dump(config, fd, indent=indent) + fd.write('\n') -def save_config(client, indent=2): +def save_config(client, fd, indent=2): """Write current (live) configuration of SPDK subsystems and targets to stdout. Args: + fd: opened file descriptor where data will be saved indent: Indent level. Value less than 0 mean compact mode. Default indent level is 2. """ @@ -60,15 +61,15 @@ def save_config(client, indent=2): } config['subsystems'].append(cfg) - _json_dump(config, indent) + _json_dump(config, fd, indent) -def load_config(client): +def load_config(client, fd): """Configure SPDK subsystems and targets using JSON RPC read from stdin. Args: - none + fd: opened file descriptor where data will be taken from """ - json_config = json.load(sys.stdin) + json_config = json.load(fd) # remove subsystems with no config subsystems = json_config['subsystems'] @@ -112,9 +113,10 @@ def load_config(client): print("Some configs were skipped because the RPC state that can call them passed over.") -def save_subsystem_config(client, indent=2, name=None): +def save_subsystem_config(client, fd, indent=2, name=None): """Write current (live) configuration of SPDK subsystem to stdout. Args: + fd: opened file descriptor where data will be saved indent: Indent level. Value less than 0 mean compact mode. Default is indent level 2. """ @@ -123,15 +125,15 @@ def save_subsystem_config(client, indent=2, name=None): 'config': client.call('get_subsystem_config', {"name": name}) } - _json_dump(cfg, indent) + _json_dump(cfg, fd, indent) -def load_subsystem_config(client): +def load_subsystem_config(client, fd): """Configure SPDK subsystem using JSON RPC read from stdin. Args: - none + fd: opened file descriptor where data will be taken from """ - subsystem = json.load(sys.stdin) + subsystem = json.load(fd) if not subsystem['config']: return diff --git a/scripts/spdkcli/ui_root.py b/scripts/spdkcli/ui_root.py index 18ed82ecd..9854d3735 100644 --- a/scripts/spdkcli/ui_root.py +++ b/scripts/spdkcli/ui_root.py @@ -63,6 +63,22 @@ class UIRoot(UINode): self.is_init = True self.refresh() + def ui_command_load_config(self, filename): + with open(filename, "r") as fd: + rpc.load_config(self.client, fd) + + def ui_command_load_subsystem_config(self, filename): + with open(filename, "r") as fd: + rpc.load_subsystem_config(self.client, fd) + + def ui_command_save_config(self, filename, indent=2): + with open(filename, "w") as fd: + rpc.save_config(self.client, fd, indent) + + def ui_command_save_subsystem_config(self, filename, subsystem, indent=2): + with open(filename, "w") as fd: + rpc.save_subsystem_config(self.client, fd, indent, subsystem) + def get_rpc_methods(self, current=False): return rpc.get_rpc_methods(self.client, current=current) diff --git a/test/spdkcli/vhost.sh b/test/spdkcli/vhost.sh index 652b00913..c479857e4 100755 --- a/test/spdkcli/vhost.sh +++ b/test/spdkcli/vhost.sh @@ -4,6 +4,7 @@ set -xe MATCH_FILE="spdkcli_vhost.test" SPDKCLI_BRANCH="/" testdir=$(readlink -f $(dirname $0)) +. $testdir/../json_config/common.sh . $testdir/common.sh timing_enter spdk_cli_vhost @@ -47,6 +48,12 @@ timing_enter spdkcli_check_match check_match timing_exit spdkcli_check_match +timing_enter spdkcli_save_config +$spdkcli_job "save_config $testdir/config.json" +$spdkcli_job "save_subsystem_config $testdir/config_bdev.json bdev" +$spdkcli_job "save_subsystem_config $testdir/config_vhost.json vhost" +timing_exit spdkcli_save_config + timing_enter spdkcli_check_match_details $SPDKCLI_BUILD_DIR/scripts/spdkcli.py bdevs/split_disk/Nvme0n1p0 show_details | jq -r -S '.' > $testdir/match_files/spdkcli_details_vhost.test $SPDKCLI_BUILD_DIR/test/app/match/match -v $testdir/match_files/spdkcli_details_vhost.test.match @@ -72,9 +79,27 @@ $spdkcli_job "/bdevs/malloc delete Malloc0" "Malloc0" $spdkcli_job "/bdevs/malloc delete Malloc1" "Malloc1" $spdkcli_job "/bdevs/malloc delete Malloc2" "Malloc2" $spdkcli_job "/bdevs/malloc delete Malloc3" "Malloc3" -rm -f /tmp/sample_aio timing_exit spdkcli_clear_config +timing_enter spdkcli_load_config +$spdkcli_job "load_config $testdir/config.json" +$spdkcli_job "/lvol_stores create lvs Malloc0" "lvs" True +$spdkcli_job "/bdevs/logical_volume create lvol 16 lvs" "lvs/lvol" True +check_match +$spdk_clear_config_py clear_config +# FIXME: remove this sleep when NVMe driver will be fixed to wait for reset to complete +sleep 2 +$spdkcli_job "load_subsystem_config $testdir/config_bdev.json" +$spdkcli_job "load_subsystem_config $testdir/config_vhost.json" +$spdkcli_job "/lvol_stores create lvs Malloc0" "lvs" True +$spdkcli_job "/bdevs/logical_volume create lvol 16 lvs" "lvs/lvol" True +check_match +rm -f $testdir/config.json +rm -f $testdir/config_bdev.json +rm -f $testdir/config_vhost.json +rm -f /tmp/sample_aio +timing_exit spdkcli_load_config + killprocess $spdk_tgt_pid timing_exit spdk_cli_vhost