scripts/rpc: filter methods in load_config by allowed methods

Change-Id: Ie3966bd19e37e83a77e8781aac5f08e87b6f21ba
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/411133
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Pawel Kaminski <pawelx.kaminski@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Pawel Wodkowski 2018-05-14 16:58:01 +02:00 committed by Daniel Verkamp
parent 8021da8ba6
commit 1b2cf0976a

View File

@ -57,17 +57,36 @@ def save_config(client, args):
def load_config(client, args): def load_config(client, args):
if not args.filename or args.filename == '-': if not args.filename or args.filename == '-':
config = json.load(sys.stdin) json_config = json.load(sys.stdin)
else: else:
with open(args.filename, 'r') as file: with open(args.filename, 'r') as file:
config = json.load(file) json_config = json.load(file)
for subsystem in config['subsystems']: subsystems = json_config['subsystems']
name = subsystem['subsystem'] while subsystems:
config = subsystem['config'] allowed_methods = client.call('get_rpc_methods', {'current': True})
if not config: allowed_found = False
continue
for elem in subsystem['config']: for subsystem in list(subsystems):
if not elem or 'method' not in elem: if not subsystem['config']:
subsystems.remove(subsystem)
continue 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")