From 361cd02264496bc8914fb909b396a5fa8170a23f Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Thu, 21 Jun 2018 10:53:46 +0900 Subject: [PATCH] scripts/rpc: Make JSON config file loadable during run time Current load_config Python function raises exception if it find any RPC only callable at startup when SPDK application is already in the runtime RPC state. Hence current JSON config file can be loadable only at startup. Due to this limitation, test code for JSON config file is complicated. This patch tries to reduce the burden of JSON config file use case. Change-Id: Ia375a25894312c334946862a8860bd64f095475d Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/415377 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- scripts/rpc/__init__.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/scripts/rpc/__init__.py b/scripts/rpc/__init__.py index 032dbead7..da0435225 100755 --- a/scripts/rpc/__init__.py +++ b/scripts/rpc/__init__.py @@ -72,19 +72,28 @@ def save_config(client, args): def load_config(client, args): json_config = _json_load(args.filename) + # remove subsystems with no config subsystems = json_config['subsystems'] + for subsystem in list(subsystems): + if not subsystem['config']: + subsystems.remove(subsystem) + + # check if methods in the config file are known + allowed_methods = client.call('get_rpc_methods') + for subsystem in list(subsystems): + 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") + while subsystems: allowed_methods = client.call('get_rpc_methods', {'current': True}) allowed_found = False for subsystem in list(subsystems): - if not subsystem['config']: - subsystems.remove(subsystem) - continue - config = subsystem['config'] for elem in list(config): - if not elem or 'method' not in elem or elem['method'] not in allowed_methods: + if 'method' not in elem or elem['method'] not in allowed_methods: continue client.call(elem['method'], elem['params']) @@ -98,8 +107,11 @@ def load_config(client, args): client.call('start_subsystem_init') allowed_found = True - if subsystems and not allowed_found: - raise rpc_client.JSONRPCException("Some config left but did not found any allowed method to execute") + if not allowed_found: + break + + if subsystems: + print("Some configs were skipped because the RPC state that can call them passed over.") def load_subsystem_config(client, args):