From 8c378d593c13b10d97e8bc6ff0ef8add6eaaf2cc Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Mon, 25 Jun 2018 08:06:09 +0900 Subject: [PATCH] scripts/rpc: Make load_subsystem_config usable in any RPC state Current load_subsystem_config RPC doesn't check if each RPC in the loaded config file is callable in the current RPC state. Hence RPC error occur if the loaded config file has any RPC not callable in the current RPC state. Change-Id: I392aa6858f2a826de22dde08ecafc31f68bde581 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/416305 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker --- scripts/rpc/__init__.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/rpc/__init__.py b/scripts/rpc/__init__.py index da0435225..d3627da6b 100755 --- a/scripts/rpc/__init__.py +++ b/scripts/rpc/__init__.py @@ -115,9 +115,24 @@ def load_config(client, args): def load_subsystem_config(client, args): - config = _json_load(args.filename) + subsystem = _json_load(args.filename) - for elem in config['config']: - if not elem or 'method' not in elem: + if not subsystem['config']: + return + + allowed_methods = client.call('get_rpc_methods') + config = subsystem['config'] + for elem in list(config): + if 'method' not in elem or elem['method'] not in allowed_methods: + raise rpc_client.JSONRPCException("Unknown method was included in the config file") + + allowed_methods = client.call('get_rpc_methods', {'current': True}) + for elem in list(config): + if 'method' not in elem or elem['method'] not in allowed_methods: continue + client.call(elem['method'], elem['params']) + config.remove(elem) + + if config: + print("Some configs were skipped because they cannot be called in the current RPC state.")