diff --git a/scripts/rpc/__init__.py b/scripts/rpc/__init__.py index 003b3d599..f70fb01bb 100755 --- a/scripts/rpc/__init__.py +++ b/scripts/rpc/__init__.py @@ -57,17 +57,36 @@ def save_config(client, args): def load_config(client, args): if not args.filename or args.filename == '-': - config = json.load(sys.stdin) + json_config = json.load(sys.stdin) else: with open(args.filename, 'r') as file: - config = json.load(file) + json_config = json.load(file) - for subsystem in config['subsystems']: - name = subsystem['subsystem'] - config = subsystem['config'] - if not config: - continue - for elem in subsystem['config']: - if not elem or 'method' not in elem: + subsystems = json_config['subsystems'] + 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 - client.call(elem['method'], elem['params']) + + config = subsystem['config'] + for elem in list(config): + if not elem or 'method' not in elem or elem['method'] not in allowed_methods: + continue + + client.call(elem['method'], elem['params']) + config.remove(elem) + allowed_found = True + + if not config: + subsystems.remove(subsystem) + + if 'start_subsystem_init' in allowed_methods: + client.call('start_subsystem_init') + allowed_found = True + + if subsystems and not allowed_found: + raise JSONRPCException("Some config left but did not found any allowed method to execute")